better deal with missing layouts in debug mode

This commit is contained in:
Helium314 2024-01-21 17:30:31 +01:00
parent d223864c81
commit dbb966f7af

View file

@ -240,10 +240,15 @@ private fun loadEnabledSubtypes(context: Context) {
for (localeAndLayout in subtypeStrings) { for (localeAndLayout in subtypeStrings) {
require(localeAndLayout.size == 2) require(localeAndLayout.size == 2)
val subtypesForLocale = resourceSubtypesByLocale[localeAndLayout.first()] val subtypesForLocale = resourceSubtypesByLocale[localeAndLayout.first()]
if (DebugFlags.DEBUG_ENABLED) // should not happen, but should not crash for normal user if (subtypesForLocale == null) {
require(subtypesForLocale != null) val message = "no resource subtype for $localeAndLayout"
else if (subtypesForLocale == null) Log.w(TAG, message)
if (DebugFlags.DEBUG_ENABLED)
Toast.makeText(context, message, Toast.LENGTH_LONG).show()
else // don't remove in debug mode
removeEnabledSubtype(prefs, localeAndLayout.joinToString(LOCALE_LAYOUT_SEPARATOR))
continue continue
}
val subtype = subtypesForLocale.firstOrNull { SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() } val subtype = subtypesForLocale.firstOrNull { SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() }
?: additionalSubtypes.firstOrNull { it.locale() == localeAndLayout.first() && SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() } ?: additionalSubtypes.firstOrNull { it.locale() == localeAndLayout.first() && SubtypeLocaleUtils.getKeyboardLayoutSetName(it) == localeAndLayout.last() }