From 50258ef4356c8c81cd5bd5d506197b59eec54cac Mon Sep 17 00:00:00 2001 From: Helium314 Date: Thu, 31 Aug 2023 12:20:41 +0200 Subject: [PATCH] remove no-dictionary warning when a fallback dictionary for the same language can be used --- .../latin/settings/LanguageSettingsDialog.kt | 14 +++++++++++--- .../latin/settings/LanguageSettingsFragment.kt | 11 +++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt index 91cefaa52..529926212 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt @@ -191,8 +191,8 @@ class LanguageSettingsDialog( dialog.show() (dialog.findViewById(android.R.id.message) as? TextView)?.movementMethod = LinkMovementMethod.getInstance() } - val (userDicts, hasInternalDict) = getUserAndInternalDictionaries(context, mainLocaleString) - if (hasInternalDict) { + val (userDicts, hasInternalDictForLanguage) = getUserAndInternalDictionaries(context, mainLocaleString) + if (hasInternalDictForLanguage) { dictionariesView.addView(TextView(context, null, R.style.PreferenceCategoryTitleText).apply { setText(R.string.internal_dictionary_summary) textSize *= 0.8f @@ -276,15 +276,23 @@ fun getUserAndInternalDictionaries(context: Context, locale: String): Pair BinaryDictionaryGetter.extractLocaleFromAssetsDictionaryFile(dictFile)?.let { - if (it == localeString) + if (it == localeString || it.languageConsideringZZ() == language) return userDicts to true } } return userDicts to false } +private fun String.languageConsideringZZ(): String { + return if (endsWith("zz", false)) + this + else + substringBefore("_") +} + // get locales with same script as main locale, but different language private fun getAvailableSecondaryLocales(context: Context, mainLocaleString: String, asciiCapable: Boolean): Set { val mainLocale = mainLocaleString.toLocale() diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsFragment.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsFragment.kt index a32304e8b..c9bfd8602 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsFragment.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsFragment.kt @@ -23,7 +23,7 @@ class LanguageSettingsFragment : SubScreenFragment() { private val enabledSubtypes = mutableListOf() private val systemLocales = mutableListOf() private val languageFilterListPreference by lazy { findPreference("pref_language_filter") as LanguageFilterListPreference } - private val dictionaryLocales by lazy { getDictionaryLocales(activity) } + private val dictionaryLocales by lazy { getDictionaryLocales(activity).mapTo(HashSet()) { it.languageConsideringZZ() } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -139,7 +139,7 @@ class LanguageSettingsFragment : SubScreenFragment() { } private fun InputMethodSubtype.toSubtypeInfo(locale: Locale, isEnabled: Boolean = false) = - toSubtypeInfo(locale, activity, isEnabled, dictionaryLocales.contains(locale)) + toSubtypeInfo(locale, activity, isEnabled, dictionaryLocales.contains(locale.languageConsideringZZ())) private fun List.addToSortedSubtypes() { forEach { @@ -185,5 +185,12 @@ class SubtypeInfo(val displayName: String, val subtype: InputMethodSubtype, var fun InputMethodSubtype.toSubtypeInfo(locale: Locale, context: Context, isEnabled: Boolean, hasDictionary: Boolean): SubtypeInfo = SubtypeInfo(LocaleUtils.getLocaleDisplayNameInSystemLocale(locale, context), this, isEnabled, hasDictionary) +private fun Locale.languageConsideringZZ(): String { + return if (country.equals("zz", false)) + "${language}_zz" + else + language +} + private const val DICTIONARY_REQUEST_CODE = 96834 const val USER_DICTIONARY_SUFFIX = "user.dict"