Save enabled subtypes as setting

This commit is contained in:
Aleksandras Kostarevas 2024-05-10 17:51:40 -05:00
parent 2e7611349a
commit e6ac130706
3 changed files with 33 additions and 0 deletions

View File

@ -273,6 +273,10 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
}
}
}
lifecycleScope.launch {
saveSubtypes()
}
}
override fun onDestroy() {

View 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)
}

View File

@ -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()
}