fix issues with settings upgrades when starting from 0

This commit is contained in:
Helium314 2025-02-16 13:01:31 +01:00
parent 2c1d6a5f4c
commit 6f1e79caa1

View file

@ -82,21 +82,20 @@ fun checkVersionUpgrade(context: Context) {
if (oldShiftSymbolsFile.exists()) { if (oldShiftSymbolsFile.exists()) {
oldShiftSymbolsFile.renameTo(getCustomLayoutFile("custom.symbols_shifted", context)) oldShiftSymbolsFile.renameTo(getCustomLayoutFile("custom.symbols_shifted", context))
} }
if (prefs.contains("enabled_input_styles")) {
// rename subtype setting, and clean old subtypes that might remain in some cases // rename subtype setting, and clean old subtypes that might remain in some cases
val subtypesPref = prefs.getString("enabled_input_styles", "")!! val subtypesPref = prefs.getString("enabled_input_styles", "")!!
.split(";").filter { it.isNotEmpty() } .split(";").filter { it.isNotEmpty() }
.map { .map {
val localeAndLayout = it.split(":").toMutableList() val localeAndLayout = it.split(":").toMutableList()
localeAndLayout[0] = localeAndLayout[0].constructLocale().toLanguageTag() localeAndLayout[0] = localeAndLayout[0].constructLocale().toLanguageTag()
localeAndLayout.joinToString(":") localeAndLayout.joinToString(":")
}.toSet().joinToString(";") }.toSet().joinToString(";")
val selectedSubtype = prefs.getString("selected_input_style", "") prefs.edit().remove("enabled_input_styles").putString(Settings.PREF_ENABLED_SUBTYPES, subtypesPref).apply()
prefs.edit { }
remove("enabled_input_styles") if (prefs.contains("selected_input_style")) {
putString(Settings.PREF_ENABLED_SUBTYPES, subtypesPref) val selectedSubtype = prefs.getString("selected_input_style", "")
remove("selected_input_style") prefs.edit().remove("selected_input_style").putString(Settings.PREF_SELECTED_SUBTYPE, selectedSubtype).apply()
putString(Settings.PREF_SELECTED_SUBTYPE, selectedSubtype)
} }
} }
if (oldVersion <= 2000) { if (oldVersion <= 2000) {
@ -529,12 +528,14 @@ private fun upgradesWhenComingFromOldAppName(context: Context) {
prefs.edit().remove("spellcheck_use_contacts").apply() prefs.edit().remove("spellcheck_use_contacts").apply()
} }
// upgrade additional subtype locale strings // upgrade additional subtype locale strings
val additionalSubtypes = mutableListOf<String>() if (prefs.contains(Settings.PREF_ADDITIONAL_SUBTYPES)) {
prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, Defaults.PREF_ADDITIONAL_SUBTYPES)!!.split(";").forEach { val additionalSubtypes = mutableListOf<String>()
val localeString = it.substringBefore(":") prefs.getString(Settings.PREF_ADDITIONAL_SUBTYPES, "")!!.split(";").forEach {
additionalSubtypes.add(it.replace(localeString, localeString.constructLocale().toLanguageTag())) val localeString = it.substringBefore(":")
additionalSubtypes.add(it.replace(localeString, localeString.constructLocale().toLanguageTag()))
}
Settings.writePrefAdditionalSubtypes(prefs, additionalSubtypes.joinToString(";"))
} }
Settings.writePrefAdditionalSubtypes(prefs, additionalSubtypes.joinToString(";"))
// move pinned clips to credential protected storage if device is not locked (should never happen) // move pinned clips to credential protected storage if device is not locked (should never happen)
if (!prefs.contains(Settings.PREF_PINNED_CLIPS)) return if (!prefs.contains(Settings.PREF_PINNED_CLIPS)) return
try { try {