mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-18 16:03:12 +00:00
remove no-dictionary warning when a fallback dictionary for the same language can be used
This commit is contained in:
parent
59ce1a1cb3
commit
50258ef435
2 changed files with 20 additions and 5 deletions
|
@ -191,8 +191,8 @@ class LanguageSettingsDialog(
|
|||
dialog.show()
|
||||
(dialog.findViewById<View>(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<List<
|
|||
}
|
||||
if (hasInternalDict)
|
||||
return userDicts to true
|
||||
val language = localeString.languageConsideringZZ()
|
||||
BinaryDictionaryGetter.getAssetsDictionaryList(context)?.forEach { dictFile ->
|
||||
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<Locale> {
|
||||
val mainLocale = mainLocaleString.toLocale()
|
||||
|
|
|
@ -23,7 +23,7 @@ class LanguageSettingsFragment : SubScreenFragment() {
|
|||
private val enabledSubtypes = mutableListOf<InputMethodSubtype>()
|
||||
private val systemLocales = mutableListOf<Locale>()
|
||||
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<SubtypeInfo>.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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue