mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-11 00:49:33 +00:00
add layout screen for choosing and editing default (non-main) layouts
This commit is contained in:
parent
6b86ea236b
commit
a3e85bc664
24 changed files with 478 additions and 82 deletions
|
@ -0,0 +1,29 @@
|
|||
package helium314.keyboard.latin.utils
|
||||
|
||||
import android.content.Context
|
||||
import helium314.keyboard.latin.settings.Defaults.default
|
||||
import helium314.keyboard.latin.utils.LayoutType.Companion.folder
|
||||
import helium314.keyboard.latin.utils.ScriptUtils.script
|
||||
import java.util.Locale
|
||||
|
||||
// for layouts provided by the app
|
||||
object LayoutUtils {
|
||||
fun getAvailableLayouts(layoutType: LayoutType, context: Context, locale: Locale? = null): Collection<String> {
|
||||
if (layoutType != LayoutType.MAIN)
|
||||
return context.assets.list(layoutType.folder)?.map { it.substringBefore(".") }.orEmpty()
|
||||
if (locale == null)
|
||||
return getAllAvailableSubtypes().mapTo(HashSet()) { it.mainLayoutName()?.substringBefore("+") ?: "qwerty" }
|
||||
if (locale.script() == ScriptUtils.SCRIPT_LATIN)
|
||||
return getAllAvailableSubtypes().filter { it.isAsciiCapable && it.mainLayoutName()?.startsWith(CUSTOM_LAYOUT_PREFIX) == false }
|
||||
.mapTo(HashSet()) { it.mainLayoutName()?.substringBefore("+") ?: "qwerty" }
|
||||
return getSubtypesForLocale(locale).mapNotNullTo(HashSet()) { it.mainLayoutName() }
|
||||
}
|
||||
|
||||
fun getContent(layoutType: LayoutType, layoutName: String, context: Context): String {
|
||||
val layouts = context.assets.list(layoutType.folder)!!
|
||||
layouts.firstOrNull { it.startsWith("$layoutName.") }
|
||||
?.let { return context.assets.open(layoutType.folder + it).reader().readText() }
|
||||
val fallback = layouts.first { it.startsWith(layoutType.default) } // must exist!
|
||||
return context.assets.open(layoutType.folder + fallback).reader().readText()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue