don't pre-select unavailable locale when adding dictionary

This commit is contained in:
Helium314 2025-06-19 09:35:08 +02:00
parent 7b0c511857
commit 77a728e390

View file

@ -47,12 +47,12 @@ fun NewDictionaryDialog(
} else if (header != null) { } else if (header != null) {
val ctx = LocalContext.current val ctx = LocalContext.current
val dictLocale = header.mLocaleString.constructLocale() val dictLocale = header.mLocaleString.constructLocale()
var locale by remember { mutableStateOf(mainLocale ?: dictLocale) }
val enabledLanguages = SubtypeSettings.getEnabledSubtypes().map { it.locale().language } val enabledLanguages = SubtypeSettings.getEnabledSubtypes().map { it.locale().language }
val comparer = compareBy<Locale>({ it != mainLocale }, { it != dictLocale }, { it.language !in enabledLanguages }, { it.script() != dictLocale.script() }) val comparer = compareBy<Locale>({ it != mainLocale }, { it != dictLocale }, { it.language !in enabledLanguages }, { it.script() != dictLocale.script() })
val locales = SubtypeSettings.getAvailableSubtypeLocales() val locales = SubtypeSettings.getAvailableSubtypeLocales()
.filter { it.script() == dictLocale.script() || it.script() == mainLocale?.script() } .filter { it.script() == dictLocale.script() || it.script() == mainLocale?.script() }
.sortedWith(comparer) .sortedWith(comparer)
var locale by remember { mutableStateOf(mainLocale ?: dictLocale.takeIf { it in locales } ?: locales.first()) }
val cacheDir = DictionaryInfoUtils.getCacheDirectoryForLocale(locale, ctx) val cacheDir = DictionaryInfoUtils.getCacheDirectoryForLocale(locale, ctx)
val dictFile = File(cacheDir, header.mIdString.substringBefore(":") + "_" + DictionaryInfoUtils.USER_DICTIONARY_SUFFIX) val dictFile = File(cacheDir, header.mIdString.substringBefore(":") + "_" + DictionaryInfoUtils.USER_DICTIONARY_SUFFIX)
val type = header.mIdString.substringBefore(":") val type = header.mIdString.substringBefore(":")