mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-19 16:30:19 +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.show()
|
||||||
(dialog.findViewById<View>(android.R.id.message) as? TextView)?.movementMethod = LinkMovementMethod.getInstance()
|
(dialog.findViewById<View>(android.R.id.message) as? TextView)?.movementMethod = LinkMovementMethod.getInstance()
|
||||||
}
|
}
|
||||||
val (userDicts, hasInternalDict) = getUserAndInternalDictionaries(context, mainLocaleString)
|
val (userDicts, hasInternalDictForLanguage) = getUserAndInternalDictionaries(context, mainLocaleString)
|
||||||
if (hasInternalDict) {
|
if (hasInternalDictForLanguage) {
|
||||||
dictionariesView.addView(TextView(context, null, R.style.PreferenceCategoryTitleText).apply {
|
dictionariesView.addView(TextView(context, null, R.style.PreferenceCategoryTitleText).apply {
|
||||||
setText(R.string.internal_dictionary_summary)
|
setText(R.string.internal_dictionary_summary)
|
||||||
textSize *= 0.8f
|
textSize *= 0.8f
|
||||||
|
@ -276,15 +276,23 @@ fun getUserAndInternalDictionaries(context: Context, locale: String): Pair<List<
|
||||||
}
|
}
|
||||||
if (hasInternalDict)
|
if (hasInternalDict)
|
||||||
return userDicts to true
|
return userDicts to true
|
||||||
|
val language = localeString.languageConsideringZZ()
|
||||||
BinaryDictionaryGetter.getAssetsDictionaryList(context)?.forEach { dictFile ->
|
BinaryDictionaryGetter.getAssetsDictionaryList(context)?.forEach { dictFile ->
|
||||||
BinaryDictionaryGetter.extractLocaleFromAssetsDictionaryFile(dictFile)?.let {
|
BinaryDictionaryGetter.extractLocaleFromAssetsDictionaryFile(dictFile)?.let {
|
||||||
if (it == localeString)
|
if (it == localeString || it.languageConsideringZZ() == language)
|
||||||
return userDicts to true
|
return userDicts to true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userDicts to false
|
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
|
// get locales with same script as main locale, but different language
|
||||||
private fun getAvailableSecondaryLocales(context: Context, mainLocaleString: String, asciiCapable: Boolean): Set<Locale> {
|
private fun getAvailableSecondaryLocales(context: Context, mainLocaleString: String, asciiCapable: Boolean): Set<Locale> {
|
||||||
val mainLocale = mainLocaleString.toLocale()
|
val mainLocale = mainLocaleString.toLocale()
|
||||||
|
|
|
@ -23,7 +23,7 @@ class LanguageSettingsFragment : SubScreenFragment() {
|
||||||
private val enabledSubtypes = mutableListOf<InputMethodSubtype>()
|
private val enabledSubtypes = mutableListOf<InputMethodSubtype>()
|
||||||
private val systemLocales = mutableListOf<Locale>()
|
private val systemLocales = mutableListOf<Locale>()
|
||||||
private val languageFilterListPreference by lazy { findPreference("pref_language_filter") as LanguageFilterListPreference }
|
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?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -139,7 +139,7 @@ class LanguageSettingsFragment : SubScreenFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun InputMethodSubtype.toSubtypeInfo(locale: Locale, isEnabled: Boolean = false) =
|
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() {
|
private fun List<SubtypeInfo>.addToSortedSubtypes() {
|
||||||
forEach {
|
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 =
|
fun InputMethodSubtype.toSubtypeInfo(locale: Locale, context: Context, isEnabled: Boolean, hasDictionary: Boolean): SubtypeInfo =
|
||||||
SubtypeInfo(LocaleUtils.getLocaleDisplayNameInSystemLocale(locale, context), this, isEnabled, hasDictionary)
|
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
|
private const val DICTIONARY_REQUEST_CODE = 96834
|
||||||
const val USER_DICTIONARY_SUFFIX = "user.dict"
|
const val USER_DICTIONARY_SUFFIX = "user.dict"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue