mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Save enabled subtypes as setting
This commit is contained in:
parent
2e7611349a
commit
e6ac130706
@ -273,6 +273,10 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
saveSubtypes()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
26
java/src/org/futo/inputmethod/latin/Subtypes.kt
Normal file
26
java/src/org/futo/inputmethod/latin/Subtypes.kt
Normal file
@ -0,0 +1,26 @@
|
||||
package org.futo.inputmethod.latin
|
||||
|
||||
import android.content.Context
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.datastore.preferences.core.stringSetPreferencesKey
|
||||
import org.futo.inputmethod.latin.uix.SettingsKey
|
||||
import org.futo.inputmethod.latin.uix.setSetting
|
||||
|
||||
val SubtypesSetting = SettingsKey(
|
||||
stringSetPreferencesKey("subtypes"),
|
||||
setOf()
|
||||
)
|
||||
|
||||
suspend fun Context.saveSubtypes() {
|
||||
val inputMethodManager = getSystemService(android.inputmethodservice.InputMethodService.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
val inputMethodList = inputMethodManager.getEnabledInputMethodSubtypeList(
|
||||
RichInputMethodManager.getInstance().inputMethodInfoOfThisIme,
|
||||
true
|
||||
)
|
||||
|
||||
val encodedSubtypes = inputMethodList.map {
|
||||
it.locale + ":" + (it.extraValue ?: "") + ":" + it.languageTag
|
||||
}.toSet()
|
||||
|
||||
setSetting(SubtypesSetting, encodedSubtypes)
|
||||
}
|
@ -26,6 +26,7 @@ import okhttp3.internal.toImmutableList
|
||||
import org.futo.inputmethod.latin.BinaryDictionaryGetter
|
||||
import org.futo.inputmethod.latin.R
|
||||
import org.futo.inputmethod.latin.RichInputMethodManager
|
||||
import org.futo.inputmethod.latin.saveSubtypes
|
||||
import org.futo.inputmethod.latin.uix.FileKind
|
||||
import org.futo.inputmethod.latin.uix.ResourceHelper
|
||||
import org.futo.inputmethod.latin.uix.getSetting
|
||||
@ -117,6 +118,8 @@ fun LanguagesScreen(navController: NavHostController = rememberNavController())
|
||||
RichInputMethodManager.getInstance().inputMethodInfoOfThisIme,
|
||||
true
|
||||
)
|
||||
|
||||
context.saveSubtypes()
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user