From e6ac130706fe614c6c2e2f001dd8b2f163067955 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Fri, 10 May 2024 17:51:40 -0500 Subject: [PATCH] Save enabled subtypes as setting --- .../org/futo/inputmethod/latin/LatinIME.kt | 4 +++ .../org/futo/inputmethod/latin/Subtypes.kt | 26 +++++++++++++++++++ .../latin/uix/settings/pages/Languages.kt | 3 +++ 3 files changed, 33 insertions(+) create mode 100644 java/src/org/futo/inputmethod/latin/Subtypes.kt diff --git a/java/src/org/futo/inputmethod/latin/LatinIME.kt b/java/src/org/futo/inputmethod/latin/LatinIME.kt index bfd0716ed..76ca689cd 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIME.kt +++ b/java/src/org/futo/inputmethod/latin/LatinIME.kt @@ -273,6 +273,10 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save } } } + + lifecycleScope.launch { + saveSubtypes() + } } override fun onDestroy() { diff --git a/java/src/org/futo/inputmethod/latin/Subtypes.kt b/java/src/org/futo/inputmethod/latin/Subtypes.kt new file mode 100644 index 000000000..926561374 --- /dev/null +++ b/java/src/org/futo/inputmethod/latin/Subtypes.kt @@ -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) +} \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Languages.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Languages.kt index 4c637d484..ee9925e80 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Languages.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Languages.kt @@ -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() }