diff --git a/app/src/main/java/helium314/keyboard/latin/App.kt b/app/src/main/java/helium314/keyboard/latin/App.kt index 819863aa9..ffe8ff7da 100644 --- a/app/src/main/java/helium314/keyboard/latin/App.kt +++ b/app/src/main/java/helium314/keyboard/latin/App.kt @@ -49,12 +49,28 @@ fun checkVersionUpgrade(context: Context) { } if (oldVersion == 0) // new install or restoring settings from old app name upgradesWhenComingFromOldAppName(context) - if (oldVersion == 1000) { // upgrade old custom layouts name + if (oldVersion <= 1000) { // upgrade old custom layouts name val layoutsDir = Settings.getLayoutsDir(context) val oldShiftSymbolsFile = File(layoutsDir, "${CUSTOM_LAYOUT_PREFIX}shift_symbols") if (oldShiftSymbolsFile.exists()) { oldShiftSymbolsFile.renameTo(File(layoutsDir, "${CUSTOM_LAYOUT_PREFIX}symbols_shifted")) } + + // rename subtype setting, and clean old subtypes that might remain in some cases + val subtypesPref = prefs.getString("enabled_input_styles", "")!! + .split(";").filter { it.isNotEmpty() } + .map { + val localeAndLayout = it.split(":").toMutableList() + localeAndLayout[0] = localeAndLayout[0].constructLocale().toLanguageTag() + localeAndLayout.joinToString(":") + }.toSet().joinToString(";") + val selectedSubtype = prefs.getString("selected_input_style", "") + prefs.edit { + remove("enabled_input_styles") + putString(Settings.PREF_ENABLED_SUBTYPES, subtypesPref) + remove("selected_input_style") + putString(Settings.PREF_SELECTED_SUBTYPE, selectedSubtype) + } } prefs.edit { putInt(Settings.PREF_VERSION_CODE, BuildConfig.VERSION_CODE) } } diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java index 340aa66d4..583d83cc0 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java @@ -41,7 +41,6 @@ import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.ResourceUtils; import helium314.keyboard.latin.utils.RunInLocaleKt; -import helium314.keyboard.latin.utils.ScriptUtils; import helium314.keyboard.latin.utils.StatsUtils; import helium314.keyboard.latin.utils.SubtypeSettingsKt; import helium314.keyboard.latin.utils.ToolbarKey; @@ -139,8 +138,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_ADD_TO_PERSONAL_DICTIONARY = "add_to_personal_dictionary"; public static final String PREF_NAVBAR_COLOR = "navbar_color"; public static final String PREF_NARROW_KEY_GAPS = "narrow_key_gaps"; - public static final String PREF_ENABLED_INPUT_STYLES = "enabled_input_styles"; - public static final String PREF_SELECTED_INPUT_STYLE = "selected_input_style"; + public static final String PREF_ENABLED_SUBTYPES = "enabled_subtypes"; + public static final String PREF_SELECTED_SUBTYPE = "selected_subtype"; public static final String PREF_USE_SYSTEM_LOCALES = "use_system_locales"; public static final String PREF_URL_DETECTION = "url_detection"; public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "dont_show_missing_dict_dialog"; @@ -179,7 +178,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang add(PREF_EMOJI_RECENT_KEYS); add(PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG); add(PREF_SHOW_ALL_COLORS); - add(PREF_SELECTED_INPUT_STYLE); + add(PREF_SELECTED_SUBTYPE); }}; public static Settings getInstance() { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt b/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt index 67c392865..2b6c7b786 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/SubtypeSettings.kt @@ -57,9 +57,9 @@ fun getMatchingLayoutSetNameForLocale(locale: Locale): String { fun addEnabledSubtype(prefs: SharedPreferences, newSubtype: InputMethodSubtype) { require(initialized) val subtypeString = newSubtype.prefString() - val oldSubtypeStrings = prefs.getString(Settings.PREF_ENABLED_INPUT_STYLES, "")!!.split(SUBTYPE_SEPARATOR) + val oldSubtypeStrings = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, "")!!.split(SUBTYPE_SEPARATOR) val newString = (oldSubtypeStrings + subtypeString).filter { it.isNotBlank() }.toSortedSet().joinToString(SUBTYPE_SEPARATOR) - prefs.edit { putString(Settings.PREF_ENABLED_INPUT_STYLES, newString) } + prefs.edit { putString(Settings.PREF_ENABLED_SUBTYPES, newString) } if (newSubtype !in enabledSubtypes) { enabledSubtypes.add(newSubtype) @@ -94,7 +94,7 @@ fun removeAdditionalSubtype(prefs: SharedPreferences, resources: Resources, subt fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype { require(initialized) - val localeAndLayout = prefs.getString(Settings.PREF_SELECTED_INPUT_STYLE, "")!!.toLocaleAndLayout() + val localeAndLayout = prefs.getString(Settings.PREF_SELECTED_SUBTYPE, "")!!.toLocaleAndLayout() val subtypes = if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true)) getDefaultEnabledSubtypes() else enabledSubtypes val subtype = subtypes.firstOrNull { localeAndLayout.first == it.locale() && localeAndLayout.second == SubtypeLocaleUtils.getKeyboardLayoutSetName(it) } @@ -113,9 +113,9 @@ fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype { fun setSelectedSubtype(prefs: SharedPreferences, subtype: InputMethodSubtype) { val subtypeString = subtype.prefString() - if (subtype.locale().toLanguageTag().isEmpty() || prefs.getString(Settings.PREF_SELECTED_INPUT_STYLE, "") == subtypeString) + if (subtype.locale().toLanguageTag().isEmpty() || prefs.getString(Settings.PREF_SELECTED_SUBTYPE, "") == subtypeString) return - prefs.edit { putString(Settings.PREF_SELECTED_INPUT_STYLE, subtypeString) } + prefs.edit { putString(Settings.PREF_SELECTED_SUBTYPE, subtypeString) } } fun isAdditionalSubtype(subtype: InputMethodSubtype): Boolean { @@ -267,7 +267,7 @@ private fun loadAdditionalSubtypes(context: Context) { // requires loadResourceSubtypes to be called before private fun loadEnabledSubtypes(context: Context) { val prefs = DeviceProtectedUtils.getSharedPreferences(context) - val subtypeStrings = prefs.getString(Settings.PREF_ENABLED_INPUT_STYLES, "")!! + val subtypeStrings = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, "")!! .split(SUBTYPE_SEPARATOR).filter { it.isNotEmpty() }.map { it.toLocaleAndLayout() } for (localeAndLayout in subtypeStrings) { @@ -299,12 +299,12 @@ private fun loadEnabledSubtypes(context: Context) { } private fun removeEnabledSubtype(prefs: SharedPreferences, subtypeString: String) { - val oldSubtypeString = prefs.getString(Settings.PREF_ENABLED_INPUT_STYLES, "")!! + val oldSubtypeString = prefs.getString(Settings.PREF_ENABLED_SUBTYPES, "")!! val newString = (oldSubtypeString.split(SUBTYPE_SEPARATOR) - subtypeString).joinToString(SUBTYPE_SEPARATOR) if (newString == oldSubtypeString) return // already removed - prefs.edit { putString(Settings.PREF_ENABLED_INPUT_STYLES, newString) } - if (subtypeString == prefs.getString(Settings.PREF_SELECTED_INPUT_STYLE, "")) { + prefs.edit { putString(Settings.PREF_ENABLED_SUBTYPES, newString) } + if (subtypeString == prefs.getString(Settings.PREF_SELECTED_SUBTYPE, "")) { // switch subtype if the currently used one has been disabled try { val nextSubtype = RichInputMethodManager.getInstance().getNextSubtypeInThisIme(true)