fix some issues with subtypes being disabled or not shown as enabled after editing

This commit is contained in:
Helium314 2025-03-08 09:05:33 +01:00
parent 15c1526895
commit a4d96a12a9
2 changed files with 16 additions and 13 deletions

View file

@ -38,7 +38,7 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
val newList = extraValues.split(",") val newList = extraValues.split(",")
.filterNot { it.isBlank() || it.startsWith("$extraValueKey=") || it == extraValueKey } .filterNot { it.isBlank() || it.startsWith("$extraValueKey=") || it == extraValueKey }
val newValue = if (extraValue == null) extraValueKey else "$extraValueKey=$extraValue" val newValue = if (extraValue == null) extraValueKey else "$extraValueKey=$extraValue"
val newValues = (newList + newValue).joinToString(",") val newValues = (newList + newValue).sorted().joinToString(",")
return copy(extraValues = newValues) return copy(extraValues = newValues)
} }

View file

@ -74,6 +74,12 @@ object SubtypeUtilsAdditional {
val fromSubtype = from.toAdditionalSubtype() val fromSubtype = from.toAdditionalSubtype()
val toSubtype = to.toAdditionalSubtype() val toSubtype = to.toAdditionalSubtype()
if (SubtypeSettings.getResourceSubtypesForLocale(to.locale).any { it.toSettingsSubtype() == to }) {
// all settings changed to default -> make additional subtype disappear as magically as it was added
// if we don't do this, enabling the base subtype will result in the additional subtype being enabled,
// as both have the same settingsSubtype
removeAdditionalSubtype(context, toSubtype)
}
if (isSelected) { if (isSelected) {
SubtypeSettings.setSelectedSubtype(prefs, toSubtype) SubtypeSettings.setSelectedSubtype(prefs, toSubtype)
} }
@ -81,21 +87,18 @@ object SubtypeUtilsAdditional {
SubtypeSettings.removeEnabledSubtype(context, fromSubtype) SubtypeSettings.removeEnabledSubtype(context, fromSubtype)
SubtypeSettings.addEnabledSubtype(prefs, toSubtype) SubtypeSettings.addEnabledSubtype(prefs, toSubtype)
} }
if (!isEnabled && !isSelected) // reloading is often unnecessary, but fast enough to not care about calling it only when necessary
SubtypeSettings.reloadEnabledSubtypes(context) SubtypeSettings.reloadEnabledSubtypes(context)
} }
fun createAdditionalSubtypes(prefSubtypes: String): List<InputMethodSubtype> { fun createAdditionalSubtypes(prefSubtypes: String): List<InputMethodSubtype> =
if (prefSubtypes.isEmpty()) prefSubtypes.split(Separators.SETS).mapNotNull {
return emptyList() if (it.isEmpty()) null
return prefSubtypes.split(Separators.SETS).map { it.toSettingsSubtype().toAdditionalSubtype() } else it.toSettingsSubtype().toAdditionalSubtype()
} }
fun createPrefSubtypes(subtypes: Collection<InputMethodSubtype>): String { fun createPrefSubtypes(subtypes: Collection<InputMethodSubtype>): String =
if (subtypes.isEmpty()) subtypes.joinToString(Separators.SETS) { it.toSettingsSubtype().toPref() }
return ""
return subtypes.joinToString(Separators.SETS) { it.toSettingsSubtype().toPref() }
}
private fun getNameResId(locale: Locale, mainLayoutName: String): Int { private fun getNameResId(locale: Locale, mainLayoutName: String): Int {
val nameId = SubtypeLocaleUtils.getSubtypeNameResId(locale, mainLayoutName) val nameId = SubtypeLocaleUtils.getSubtypeNameResId(locale, mainLayoutName)