mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-19 21:59:11 +00:00
toAdditional subtype not nullable any more
was causing too much trouble and only was in there because "it always has been there"
This commit is contained in:
parent
fa9ac20d39
commit
15c1526895
4 changed files with 13 additions and 34 deletions
|
@ -11,11 +11,9 @@ import helium314.keyboard.latin.common.LocaleUtils.constructLocale
|
|||
import helium314.keyboard.latin.define.DebugFlags
|
||||
import helium314.keyboard.latin.utils.LayoutType
|
||||
import helium314.keyboard.latin.utils.LayoutType.Companion.toExtraValue
|
||||
import helium314.keyboard.latin.utils.LayoutUtilsCustom
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.latin.utils.ScriptUtils
|
||||
import helium314.keyboard.latin.utils.ScriptUtils.script
|
||||
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
|
||||
import helium314.keyboard.latin.utils.SubtypeUtilsAdditional
|
||||
import helium314.keyboard.latin.utils.locale
|
||||
import java.util.Locale
|
||||
|
@ -27,23 +25,9 @@ data class SettingsSubtype(val locale: Locale, val extraValues: String) {
|
|||
|
||||
/** Creates an additional subtype from the SettingsSubtype.
|
||||
* Resulting InputMethodSubtypes are equal if SettingsSubtypes are equal */
|
||||
fun toAdditionalSubtype(): InputMethodSubtype? {
|
||||
fun toAdditionalSubtype(): InputMethodSubtype {
|
||||
val asciiCapable = locale.script() == ScriptUtils.SCRIPT_LATIN
|
||||
val subtype = SubtypeUtilsAdditional.createAdditionalSubtype(locale, extraValues, asciiCapable, true)
|
||||
|
||||
// todo: this is returns null for all non-latin layouts
|
||||
// either fix it, or remove the check
|
||||
// if removed, removing a layout will result in fallback qwerty even for non-ascii, but this is better than the current alternative
|
||||
/* if (subtype.nameResId == SubtypeLocaleUtils.UNKNOWN_KEYBOARD_LAYOUT
|
||||
&& mainLayoutName()?.endsWith("+") != true // "+" layouts and custom layouts are always "unknown"
|
||||
&& !LayoutUtilsCustom.isCustomLayout(mainLayoutName() ?: SubtypeLocaleUtils.QWERTY)
|
||||
) {
|
||||
// Skip unknown keyboard layout subtype. This may happen when predefined keyboard
|
||||
// layout has been removed.
|
||||
Log.w(SettingsSubtype::class.simpleName, "unknown additional subtype $this")
|
||||
return null
|
||||
}*/
|
||||
return subtype
|
||||
return SubtypeUtilsAdditional.createAdditionalSubtype(locale, extraValues, asciiCapable, true)
|
||||
}
|
||||
|
||||
fun mainLayoutName() = LayoutType.getMainLayoutFromExtraValue(extraValues)
|
||||
|
|
|
@ -74,10 +74,8 @@ object SubtypeSettings {
|
|||
|
||||
fun getSelectedSubtype(prefs: SharedPreferences): InputMethodSubtype {
|
||||
val selectedSubtype = prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE)!!.toSettingsSubtype()
|
||||
if (selectedSubtype.isAdditionalSubtype(prefs)) {
|
||||
val selectedAdditionalSubtype = selectedSubtype.toAdditionalSubtype()
|
||||
if (selectedAdditionalSubtype != null) return selectedAdditionalSubtype
|
||||
}
|
||||
if (selectedSubtype.isAdditionalSubtype(prefs))
|
||||
return selectedSubtype.toAdditionalSubtype()
|
||||
// no additional subtype, must be a resource subtype
|
||||
|
||||
val subtype = enabledSubtypes.firstOrNull { it.toSettingsSubtype() == selectedSubtype }
|
||||
|
@ -224,11 +222,8 @@ object SubtypeSettings {
|
|||
.split(Separators.SETS).filter { it.isNotEmpty() }.map { it.toSettingsSubtype() }
|
||||
for (settingsSubtype in settingsSubtypes) {
|
||||
if (settingsSubtype.isAdditionalSubtype(prefs)) {
|
||||
val additionalSubtype = settingsSubtype.toAdditionalSubtype()
|
||||
if (additionalSubtype != null) {
|
||||
enabledSubtypes.add(additionalSubtype)
|
||||
continue
|
||||
}
|
||||
enabledSubtypes.add(settingsSubtype.toAdditionalSubtype())
|
||||
continue
|
||||
}
|
||||
val subtypesForLocale = resourceSubtypesByLocale[settingsSubtype.locale]
|
||||
if (subtypesForLocale == null) {
|
||||
|
|
|
@ -72,12 +72,12 @@ object SubtypeUtilsAdditional {
|
|||
} + to.toPref()
|
||||
prefs.edit().putString(Settings.PREF_ADDITIONAL_SUBTYPES, new.joinToString(Separators.SETS)).apply()
|
||||
|
||||
val fromSubtype = from.toAdditionalSubtype() // will be null if we edit a resource subtype
|
||||
val toSubtype = to.toAdditionalSubtype() // should never be null
|
||||
if (isSelected && toSubtype != null) {
|
||||
val fromSubtype = from.toAdditionalSubtype()
|
||||
val toSubtype = to.toAdditionalSubtype()
|
||||
if (isSelected) {
|
||||
SubtypeSettings.setSelectedSubtype(prefs, toSubtype)
|
||||
}
|
||||
if (fromSubtype != null && isEnabled && toSubtype != null) {
|
||||
if (isEnabled) {
|
||||
SubtypeSettings.removeEnabledSubtype(context, fromSubtype)
|
||||
SubtypeSettings.addEnabledSubtype(prefs, toSubtype)
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ object SubtypeUtilsAdditional {
|
|||
fun createAdditionalSubtypes(prefSubtypes: String): List<InputMethodSubtype> {
|
||||
if (prefSubtypes.isEmpty())
|
||||
return emptyList()
|
||||
return prefSubtypes.split(Separators.SETS).mapNotNull { it.toSettingsSubtype().toAdditionalSubtype() }
|
||||
return prefSubtypes.split(Separators.SETS).map { it.toSettingsSubtype().toAdditionalSubtype() }
|
||||
}
|
||||
|
||||
fun createPrefSubtypes(subtypes: Collection<InputMethodSubtype>): String {
|
||||
|
|
|
@ -125,8 +125,8 @@ fun SubtypeDialog(
|
|||
onConfirmed = { onConfirmed(currentSubtype) },
|
||||
neutralButtonText = if (initialSubtype.isAdditionalSubtype(prefs)) stringResource(R.string.delete) else null,
|
||||
onNeutral = {
|
||||
SubtypeUtilsAdditional.removeAdditionalSubtype(ctx, initialSubtype.toAdditionalSubtype()!!)
|
||||
SubtypeSettings.removeEnabledSubtype(ctx, initialSubtype.toAdditionalSubtype()!!)
|
||||
SubtypeUtilsAdditional.removeAdditionalSubtype(ctx, initialSubtype.toAdditionalSubtype())
|
||||
SubtypeSettings.removeEnabledSubtype(ctx, initialSubtype.toAdditionalSubtype())
|
||||
onDismissRequest()
|
||||
},
|
||||
title = {
|
||||
|
|
Loading…
Add table
Reference in a new issue