mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-20 06:09:09 +00:00
fix subtypes not showing up if all available subtypes have a mismatching country
This commit is contained in:
parent
5b0acd82fa
commit
f137a32a28
2 changed files with 18 additions and 14 deletions
|
@ -28,7 +28,7 @@ class LanguageSettingsFragment : SubScreenFragment() {
|
||||||
addPreferencesFromResource(R.xml.prefs_screen_languages);
|
addPreferencesFromResource(R.xml.prefs_screen_languages);
|
||||||
SubtypeLocaleUtils.init(activity)
|
SubtypeLocaleUtils.init(activity)
|
||||||
|
|
||||||
enabledSubtypes.addAll(getExplicitlyEnabledSubtypes())
|
enabledSubtypes.addAll(getEnabledSubtypes(sharedPreferences))
|
||||||
systemLocales.addAll(getSystemLocales())
|
systemLocales.addAll(getSystemLocales())
|
||||||
loadSubtypes()
|
loadSubtypes()
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,14 @@ class LanguageSettingsFragment : SubScreenFragment() {
|
||||||
private fun loadSubtypes() {
|
private fun loadSubtypes() {
|
||||||
val systemOnly = (findPreference(Settings.PREF_USE_SYSTEM_LOCALES) as TwoStatePreference).isChecked
|
val systemOnly = (findPreference(Settings.PREF_USE_SYSTEM_LOCALES) as TwoStatePreference).isChecked
|
||||||
sortedSubtypes.clear()
|
sortedSubtypes.clear()
|
||||||
|
// list of all subtypes, any subtype added to sortedSubtypes will be removed to avoid duplicates
|
||||||
val allSubtypes = getAllAvailableSubtypes().toMutableList()
|
val allSubtypes = getAllAvailableSubtypes().toMutableList()
|
||||||
// maybe make use of the map used by SubtypeSettings for performance reasons?
|
// maybe make use of the map used by SubtypeSettings for performance reasons?
|
||||||
fun List<Locale>.sortedAddToSubtypesAndRemoveFromAllSubtypes() {
|
fun List<Locale>.sortedAddToSubtypesAndRemoveFromAllSubtypes() {
|
||||||
val subtypesToAdd = mutableListOf<SubtypeInfo>()
|
val subtypesToAdd = mutableListOf<SubtypeInfo>()
|
||||||
forEach { locale ->
|
forEach { locale ->
|
||||||
|
// this could be rather slow with looping multiple times over all ~100 subtypes,
|
||||||
|
// but usually there aren't many locales to be checked, and usually the first loop already finds a match
|
||||||
val localeString = locale.toString()
|
val localeString = locale.toString()
|
||||||
val iter = allSubtypes.iterator()
|
val iter = allSubtypes.iterator()
|
||||||
var added = false
|
var added = false
|
||||||
|
@ -68,8 +71,8 @@ class LanguageSettingsFragment : SubScreenFragment() {
|
||||||
added = true
|
added = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// try again, but with language only
|
||||||
if (!added && locale.country.isNotEmpty()) {
|
if (!added && locale.country.isNotEmpty()) {
|
||||||
// try again, but with language only
|
|
||||||
val languageString = locale.language
|
val languageString = locale.language
|
||||||
val iter = allSubtypes.iterator()
|
val iter = allSubtypes.iterator()
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
|
@ -99,17 +102,16 @@ class LanguageSettingsFragment : SubScreenFragment() {
|
||||||
subtypesToAdd.sortedBy { it.displayName }.addToSortedSubtypes()
|
subtypesToAdd.sortedBy { it.displayName }.addToSortedSubtypes()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (systemOnly) {
|
|
||||||
systemLocales.sortedAddToSubtypesAndRemoveFromAllSubtypes()
|
|
||||||
languageFilterListPreference.setLanguages(sortedSubtypes.values, systemOnly)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// add enabled subtypes
|
// add enabled subtypes
|
||||||
enabledSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale), true) }
|
enabledSubtypes.map { it.toSubtypeInfo(LocaleUtils.constructLocaleFromString(it.locale), true) }
|
||||||
.sortedBy { it.displayName }.addToSortedSubtypes()
|
.sortedBy { it.displayName }.addToSortedSubtypes()
|
||||||
allSubtypes.removeAll(enabledSubtypes)
|
allSubtypes.removeAll(enabledSubtypes)
|
||||||
|
|
||||||
|
if (systemOnly) { // don't add anything else
|
||||||
|
languageFilterListPreference.setLanguages(sortedSubtypes.values, systemOnly)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// add subtypes that have a dictionary
|
// add subtypes that have a dictionary
|
||||||
val localesWithDictionary = DictionaryInfoUtils.getCachedDirectoryList(activity)?.mapNotNull { dir ->
|
val localesWithDictionary = DictionaryInfoUtils.getCachedDirectoryList(activity)?.mapNotNull { dir ->
|
||||||
if (!dir.isDirectory)
|
if (!dir.isDirectory)
|
||||||
|
|
|
@ -25,11 +25,6 @@ fun getEnabledSubtypes(prefs: SharedPreferences, fallback: Boolean = false): Lis
|
||||||
require(initialized)
|
require(initialized)
|
||||||
if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true))
|
if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true))
|
||||||
return getDefaultEnabledSubtypes()
|
return getDefaultEnabledSubtypes()
|
||||||
return getExplicitlyEnabledSubtypes(fallback)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getExplicitlyEnabledSubtypes(fallback: Boolean = false): List<InputMethodSubtype> {
|
|
||||||
require(initialized)
|
|
||||||
if (fallback && enabledSubtypes.isEmpty())
|
if (fallback && enabledSubtypes.isEmpty())
|
||||||
return getDefaultEnabledSubtypes()
|
return getDefaultEnabledSubtypes()
|
||||||
return enabledSubtypes
|
return enabledSubtypes
|
||||||
|
@ -157,7 +152,14 @@ private fun getDefaultEnabledSubtypes(): List<InputMethodSubtype> {
|
||||||
val subtypes = systemLocales.mapNotNull { locale ->
|
val subtypes = systemLocales.mapNotNull { locale ->
|
||||||
val localeString = locale.toString()
|
val localeString = locale.toString()
|
||||||
val subtypesOfLocale = resourceSubtypesByLocale[localeString]
|
val subtypesOfLocale = resourceSubtypesByLocale[localeString]
|
||||||
?: resourceSubtypesByLocale[localeString.substringBefore("_")] // fall back to language match
|
?: resourceSubtypesByLocale[localeString.substringBefore("_")] // fall back to language matching the subtype
|
||||||
|
?: localeString.substringBefore("_").let { language -> // fall back to languages matching subtype language
|
||||||
|
resourceSubtypesByLocale.firstNotNullOfOrNull {
|
||||||
|
if (it.key.substringBefore("_") == language)
|
||||||
|
it.value
|
||||||
|
else null
|
||||||
|
}
|
||||||
|
}
|
||||||
subtypesOfLocale?.firstOrNull()
|
subtypesOfLocale?.firstOrNull()
|
||||||
}
|
}
|
||||||
if (subtypes.isEmpty()) {
|
if (subtypes.isEmpty()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue