mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Add system languages as subtypes when blank
This commit is contained in:
parent
7570e4d258
commit
97859147d9
@ -221,6 +221,8 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
Subtypes.addDefaultSubtypesIfNecessary(this)
|
||||
|
||||
languageModelFacilitator = LanguageModelFacilitator(
|
||||
this,
|
||||
latinIMELegacy.mInputLogic,
|
||||
|
@ -39,6 +39,7 @@ import org.futo.inputmethod.latin.uix.setSettingBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.NavigationItem
|
||||
import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
|
||||
import org.futo.inputmethod.latin.uix.settings.SettingsActivity
|
||||
import org.futo.inputmethod.latin.uix.settings.pages.LocaleLayoutMap
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.theme.Typography
|
||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils
|
||||
@ -55,6 +56,36 @@ val ActiveSubtype = SettingsKey(
|
||||
)
|
||||
|
||||
object Subtypes {
|
||||
fun addDefaultSubtypesIfNecessary(context: Context) {
|
||||
val currentSubtypes = context.getSettingBlocking(SubtypesSetting)
|
||||
if(currentSubtypes.isNotEmpty()) return
|
||||
|
||||
val locales = context.resources.configuration.locales
|
||||
if(locales.size() == 0) return
|
||||
|
||||
for(i in 0 until locales.size()) {
|
||||
val locale = locales.get(i)
|
||||
val layout = findClosestLocaleLayouts(locale).firstOrNull() ?: continue
|
||||
|
||||
addLanguage(context, locale, layout)
|
||||
}
|
||||
|
||||
context.setSettingBlocking(ActiveSubtype.key, context.getSettingBlocking(SubtypesSetting).first())
|
||||
}
|
||||
|
||||
fun findClosestLocaleLayouts(locale: Locale): List<String> {
|
||||
val supportedLocales = LocaleLayoutMap.toList().associate {
|
||||
getLocale(it.first) to it.second
|
||||
}
|
||||
|
||||
val perfectMatch = supportedLocales.keys.find { it.language == locale.language && it.country == locale.country }
|
||||
val languageMatch = supportedLocales.keys.find { it.language == locale.language }
|
||||
|
||||
val match = perfectMatch ?: languageMatch
|
||||
|
||||
return match?.let { supportedLocales[it] } ?: listOf()
|
||||
}
|
||||
|
||||
fun convertToSubtype(string: String): InputMethodSubtype {
|
||||
val splits = string.split(":")
|
||||
val locale = splits[0]
|
||||
|
@ -23,7 +23,7 @@ import org.futo.inputmethod.latin.uix.settings.SettingItem
|
||||
|
||||
val QwertyVariants = listOf("qwerty", "qwertz", "dvorak", "azerty", "colemak", "bepo", "pcqwerty")
|
||||
|
||||
val locales = mapOf(
|
||||
val LocaleLayoutMap = mapOf(
|
||||
"af" to listOf("qwerty"),
|
||||
"ar" to listOf("arabic"),
|
||||
"az_AZ" to listOf("qwerty"),
|
||||
@ -114,7 +114,7 @@ fun AddLanguageScreen(navController: NavHostController = rememberNavController()
|
||||
val selectedLocale: MutableState<String> = remember { mutableStateOf(context.resources.configuration.locale.toString()) }
|
||||
val selectedLayout: MutableState<String> = remember { mutableStateOf("qwerty") }
|
||||
|
||||
val keys = remember { locales.keys.toList() }
|
||||
val keys = remember { LocaleLayoutMap.keys.toList() }
|
||||
ScrollableList {
|
||||
ScreenTitle("Add Language", showBack = true, navController)
|
||||
|
||||
@ -125,7 +125,7 @@ fun AddLanguageScreen(navController: NavHostController = rememberNavController()
|
||||
selectedLocale.value,
|
||||
{
|
||||
selectedLocale.value = it
|
||||
selectedLayout.value = locales[it]!!.first()
|
||||
selectedLayout.value = LocaleLayoutMap[it]!!.first()
|
||||
},
|
||||
{
|
||||
Subtypes.getNameForLocale(it)
|
||||
@ -137,7 +137,7 @@ fun AddLanguageScreen(navController: NavHostController = rememberNavController()
|
||||
SettingItem(title = "Layout") {
|
||||
DropDownPicker(
|
||||
"",
|
||||
locales[selectedLocale.value] ?: listOf(),
|
||||
LocaleLayoutMap[selectedLocale.value] ?: listOf(),
|
||||
selectedLayout.value,
|
||||
{ selectedLayout.value = it },
|
||||
{ Subtypes.getLayoutName(context, it) },
|
||||
|
Loading…
Reference in New Issue
Block a user