remove "use system locales"

now behavior is as it was disabled
if no subtypes are explicitly enabled, it behaves the same as if the setting was enabled (same as before, actually)
This commit is contained in:
Helium314 2025-02-25 22:41:54 +01:00
parent cab9cc7de0
commit f0689b00f6
18 changed files with 40 additions and 61 deletions

View file

@ -467,7 +467,7 @@ fun checkVersionUpgrade(context: Context) {
prefs.all.keys.toList().forEach { key -> prefs.all.keys.toList().forEach { key ->
if (key.startsWith(Settings.PREF_POPUP_KEYS_ORDER+"_")) { if (key.startsWith(Settings.PREF_POPUP_KEYS_ORDER+"_")) {
val locale = key.substringAfter(Settings.PREF_POPUP_KEYS_ORDER+"_").constructLocale() val locale = key.substringAfter(Settings.PREF_POPUP_KEYS_ORDER+"_").constructLocale()
SubtypeSettings.getEnabledSubtypes(prefs).forEach { SubtypeSettings.getEnabledSubtypes().forEach {
if (it.locale() == locale && !SubtypeSettings.isAdditionalSubtype(it)) { if (it.locale() == locale && !SubtypeSettings.isAdditionalSubtype(it)) {
SubtypeUtilsAdditional.changeAdditionalSubtype(it.toSettingsSubtype(), it.toSettingsSubtype(), context) SubtypeUtilsAdditional.changeAdditionalSubtype(it.toSettingsSubtype(), it.toSettingsSubtype(), context)
} }
@ -483,7 +483,7 @@ fun checkVersionUpgrade(context: Context) {
} }
if (key.startsWith(Settings.PREF_POPUP_KEYS_LABELS_ORDER+"_")) { if (key.startsWith(Settings.PREF_POPUP_KEYS_LABELS_ORDER+"_")) {
val locale = key.substringAfter(Settings.PREF_POPUP_KEYS_LABELS_ORDER+"_").constructLocale() val locale = key.substringAfter(Settings.PREF_POPUP_KEYS_LABELS_ORDER+"_").constructLocale()
SubtypeSettings.getEnabledSubtypes(prefs).forEach { SubtypeSettings.getEnabledSubtypes().forEach {
if (it.locale() == locale && !SubtypeSettings.isAdditionalSubtype(it)) { if (it.locale() == locale && !SubtypeSettings.isAdditionalSubtype(it)) {
SubtypeUtilsAdditional.changeAdditionalSubtype(it.toSettingsSubtype(), it.toSettingsSubtype(), context) SubtypeUtilsAdditional.changeAdditionalSubtype(it.toSettingsSubtype(), it.toSettingsSubtype(), context)
} }
@ -499,7 +499,7 @@ fun checkVersionUpgrade(context: Context) {
} }
if (key.startsWith("secondary_locales_")) { if (key.startsWith("secondary_locales_")) {
val locale = key.substringAfter("secondary_locales_").constructLocale() val locale = key.substringAfter("secondary_locales_").constructLocale()
SubtypeSettings.getEnabledSubtypes(prefs).forEach { SubtypeSettings.getEnabledSubtypes().forEach {
if (it.locale() == locale && !SubtypeSettings.isAdditionalSubtype(it)) { if (it.locale() == locale && !SubtypeSettings.isAdditionalSubtype(it)) {
SubtypeUtilsAdditional.changeAdditionalSubtype(it.toSettingsSubtype(), it.toSettingsSubtype(), context) SubtypeUtilsAdditional.changeAdditionalSubtype(it.toSettingsSubtype(), it.toSettingsSubtype(), context)
} }

View file

@ -10,11 +10,6 @@ import android.Manifest;
import android.content.Context; import android.content.Context;
import android.provider.UserDictionary; import android.provider.UserDictionary;
import android.text.TextUtils; import android.text.TextUtils;
import helium314.keyboard.latin.common.StringUtilsKt;
import helium314.keyboard.latin.settings.SettingsValues;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import android.util.LruCache; import android.util.LruCache;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
@ -27,11 +22,15 @@ import helium314.keyboard.latin.SuggestedWords.SuggestedWordInfo;
import helium314.keyboard.latin.common.ComposedData; import helium314.keyboard.latin.common.ComposedData;
import helium314.keyboard.latin.common.Constants; import helium314.keyboard.latin.common.Constants;
import helium314.keyboard.latin.common.StringUtils; import helium314.keyboard.latin.common.StringUtils;
import helium314.keyboard.latin.common.StringUtilsKt;
import helium314.keyboard.latin.permissions.PermissionsUtil; import helium314.keyboard.latin.permissions.PermissionsUtil;
import helium314.keyboard.latin.personalization.UserHistoryDictionary; import helium314.keyboard.latin.personalization.UserHistoryDictionary;
import helium314.keyboard.latin.settings.Settings; import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.settings.SettingsValues;
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion; import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
import helium314.keyboard.latin.utils.ExecutorUtils; import helium314.keyboard.latin.utils.ExecutorUtils;
import helium314.keyboard.latin.utils.KtxKt;
import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.SubtypeSettings; import helium314.keyboard.latin.utils.SubtypeSettings;
import helium314.keyboard.latin.utils.SubtypeUtilsKt; import helium314.keyboard.latin.utils.SubtypeUtilsKt;
import helium314.keyboard.latin.utils.SuggestionResults; import helium314.keyboard.latin.utils.SuggestionResults;
@ -352,7 +351,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
addAll(SubtypeUtilsKt.getSecondaryLocales(selected.getExtraValue())); addAll(SubtypeUtilsKt.getSecondaryLocales(selected.getExtraValue()));
} else { } else {
// probably we're called from the spell checker when using a different app as keyboard // probably we're called from the spell checker when using a different app as keyboard
final List<InputMethodSubtype> enabled = SubtypeSettings.INSTANCE.getEnabledSubtypes(KtxKt.prefs(context), false); final List<InputMethodSubtype> enabled = SubtypeSettings.INSTANCE.getEnabledSubtypes(false);
for (InputMethodSubtype subtype : enabled) { for (InputMethodSubtype subtype : enabled) {
if (SubtypeUtilsKt.locale(subtype).equals(newLocale)) if (SubtypeUtilsKt.locale(subtype).equals(newLocale))
addAll(SubtypeUtilsKt.getSecondaryLocales(subtype.getExtraValue())); addAll(SubtypeUtilsKt.getSecondaryLocales(subtype.getExtraValue()));

View file

@ -171,7 +171,7 @@ public class RichInputMethodManager {
if (imi == getInputMethodOfThisIme()) { if (imi == getInputMethodOfThisIme()) {
// allowsImplicitlySelectedSubtypes means system should choose if nothing is enabled, // allowsImplicitlySelectedSubtypes means system should choose if nothing is enabled,
// use it to fall back to system locales or en_US to avoid returning an empty list // use it to fall back to system locales or en_US to avoid returning an empty list
result = SubtypeSettings.INSTANCE.getEnabledSubtypes(KtxKt.prefs(sInstance.mContext), allowsImplicitlySelectedSubtypes); result = SubtypeSettings.INSTANCE.getEnabledSubtypes(allowsImplicitlySelectedSubtypes);
} else { } else {
result = mImm.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes); result = mImm.getEnabledInputMethodSubtypeList(imi, allowsImplicitlySelectedSubtypes);
} }

View file

@ -135,7 +135,6 @@ object Defaults {
const val PREF_NARROW_KEY_GAPS = false const val PREF_NARROW_KEY_GAPS = false
const val PREF_ENABLED_SUBTYPES = "" const val PREF_ENABLED_SUBTYPES = ""
const val PREF_SELECTED_SUBTYPE = "" const val PREF_SELECTED_SUBTYPE = ""
const val PREF_USE_SYSTEM_LOCALES = true
const val PREF_URL_DETECTION = false const val PREF_URL_DETECTION = false
const val PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = false const val PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = false
const val PREF_QUICK_PIN_TOOLBAR_KEYS = false const val PREF_QUICK_PIN_TOOLBAR_KEYS = false

View file

@ -58,18 +58,17 @@ class LanguageSettingsFragment : Fragment(R.layout.language_settings) {
SubtypeLocaleUtils.init(requireContext()) SubtypeLocaleUtils.init(requireContext())
enabledSubtypes.addAll(SubtypeSettings.getEnabledSubtypes(prefs)) enabledSubtypes.addAll(SubtypeSettings.getEnabledSubtypes())
systemLocales.addAll(SubtypeSettings.getSystemLocales()) systemLocales.addAll(SubtypeSettings.getSystemLocales())
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = super.onCreateView(inflater, container, savedInstanceState) ?: return null val view = super.onCreateView(inflater, container, savedInstanceState) ?: return null
systemOnlySwitch = view.findViewById(R.id.language_switch) systemOnlySwitch = view.findViewById(R.id.language_switch)
systemOnlySwitch.isChecked = prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, true) systemOnlySwitch.isChecked = false
systemOnlySwitch.setOnCheckedChangeListener { _, b -> systemOnlySwitch.setOnCheckedChangeListener { _, b ->
prefs.edit { putBoolean(Settings.PREF_USE_SYSTEM_LOCALES, b) }
enabledSubtypes.clear() enabledSubtypes.clear()
enabledSubtypes.addAll(SubtypeSettings.getEnabledSubtypes(prefs)) enabledSubtypes.addAll(SubtypeSettings.getEnabledSubtypes())
loadSubtypes(b) loadSubtypes(b)
} }
languageFilterList = LanguageFilterList(view.findViewById(R.id.search_field), view.findViewById(R.id.language_list)) languageFilterList = LanguageFilterList(view.findViewById(R.id.search_field), view.findViewById(R.id.language_list))

View file

@ -106,7 +106,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
if (pref == null) return; if (pref == null) return;
// locales that have a number row defined (not good to have it hardcoded, but reading a bunch of files may be noticeably slow) // locales that have a number row defined (not good to have it hardcoded, but reading a bunch of files may be noticeably slow)
final String[] numberRowLocales = new String[] { "ar", "bn", "fa", "gu", "hi", "kn", "mr", "ne", "ur" }; final String[] numberRowLocales = new String[] { "ar", "bn", "fa", "gu", "hi", "kn", "mr", "ne", "ur" };
for (final InputMethodSubtype subtype : SubtypeSettings.INSTANCE.getEnabledSubtypes(getSharedPreferences(), true)) { for (final InputMethodSubtype subtype : SubtypeSettings.INSTANCE.getEnabledSubtypes(true)) {
if (ArraysKt.any(numberRowLocales, (l) -> l.equals(SubtypeUtilsKt.locale(subtype).getLanguage()))) { if (ArraysKt.any(numberRowLocales, (l) -> l.equals(SubtypeUtilsKt.locale(subtype).getLanguage()))) {
pref.setVisible(true); pref.setVisible(true);
return; return;

View file

@ -144,7 +144,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_NARROW_KEY_GAPS = "narrow_key_gaps"; public static final String PREF_NARROW_KEY_GAPS = "narrow_key_gaps";
public static final String PREF_ENABLED_SUBTYPES = "enabled_subtypes"; public static final String PREF_ENABLED_SUBTYPES = "enabled_subtypes";
public static final String PREF_SELECTED_SUBTYPE = "selected_subtype"; public static final String PREF_SELECTED_SUBTYPE = "selected_subtype";
public static final String PREF_USE_SYSTEM_LOCALES = "use_system_locales";
public static final String PREF_URL_DETECTION = "url_detection"; public static final String PREF_URL_DETECTION = "url_detection";
public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "dont_show_missing_dict_dialog"; public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "dont_show_missing_dict_dialog";
public static final String PREF_QUICK_PIN_TOOLBAR_KEYS = "quick_pin_toolbar_keys"; public static final String PREF_QUICK_PIN_TOOLBAR_KEYS = "quick_pin_toolbar_keys";

View file

@ -80,7 +80,7 @@ public final class SettingsFragment extends PreferenceFragmentCompat {
} }
private String getEnabledSubtypesLabel() { private String getEnabledSubtypesLabel() {
final List<InputMethodSubtype> subtypes = SubtypeSettings.INSTANCE.getEnabledSubtypes(KtxKt.prefs(getActivity()), true); final List<InputMethodSubtype> subtypes = SubtypeSettings.INSTANCE.getEnabledSubtypes(true);
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (final InputMethodSubtype subtype : subtypes) { for (final InputMethodSubtype subtype : subtypes) {
if (sb.length() > 0) if (sb.length() > 0)

View file

@ -107,22 +107,19 @@ public class UserDictionaryListFragment extends SubScreenFragment {
static TreeSet<Locale> getSortedDictionaryLocales(final Context context) { static TreeSet<Locale> getSortedDictionaryLocales(final Context context) {
final SharedPreferences prefs = KtxKt.prefs(context); final SharedPreferences prefs = KtxKt.prefs(context);
final boolean localeSystemOnly = prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, Defaults.PREF_USE_SYSTEM_LOCALES);
final TreeSet<Locale> sortedLocales = new TreeSet<>(new LocaleComparator()); final TreeSet<Locale> sortedLocales = new TreeSet<>(new LocaleComparator());
// Add the main language selected in the "Language and Layouts" setting except "No language" // Add the main language selected in the "Language and Layouts" setting except "No language"
for (InputMethodSubtype mainSubtype : SubtypeSettings.INSTANCE.getEnabledSubtypes(prefs, true)) { for (InputMethodSubtype mainSubtype : SubtypeSettings.INSTANCE.getEnabledSubtypes(true)) {
final Locale mainLocale = SubtypeUtilsKt.locale(mainSubtype); final Locale mainLocale = SubtypeUtilsKt.locale(mainSubtype);
if (!mainLocale.toLanguageTag().equals(SubtypeLocaleUtils.NO_LANGUAGE)) { if (!mainLocale.toLanguageTag().equals(SubtypeLocaleUtils.NO_LANGUAGE)) {
sortedLocales.add(mainLocale); sortedLocales.add(mainLocale);
} }
// Secondary language is added only if main language is selected and if system language is not enabled // Secondary language is added only if main language is selected and if system language is not enabled
if (!localeSystemOnly) { final List<InputMethodSubtype> enabled = SubtypeSettings.INSTANCE.getEnabledSubtypes(false);
final List<InputMethodSubtype> enabled = SubtypeSettings.INSTANCE.getEnabledSubtypes(prefs, false); for (InputMethodSubtype subtype : enabled) {
for (InputMethodSubtype subtype : enabled) { if (SubtypeUtilsKt.locale(subtype).equals(mainLocale))
if (SubtypeUtilsKt.locale(subtype).equals(mainLocale)) sortedLocales.addAll(SubtypeUtilsKt.getSecondaryLocales(subtype.getExtraValue()));
sortedLocales.addAll(SubtypeUtilsKt.getSecondaryLocales(subtype.getExtraValue()));
}
} }
} }

View file

@ -180,9 +180,8 @@ fun createDictionaryTextAnnotated(locale: Locale): AnnotatedString {
fun cleanUnusedMainDicts(context: Context) { fun cleanUnusedMainDicts(context: Context) {
val dictionaryDir = File(DictionaryInfoUtils.getWordListCacheDirectory(context)) val dictionaryDir = File(DictionaryInfoUtils.getWordListCacheDirectory(context))
val dirs = dictionaryDir.listFiles() ?: return val dirs = dictionaryDir.listFiles() ?: return
val prefs = context.prefs()
val usedLocaleLanguageTags = hashSetOf<String>() val usedLocaleLanguageTags = hashSetOf<String>()
SubtypeSettings.getEnabledSubtypes(prefs).forEach { subtype -> SubtypeSettings.getEnabledSubtypes().forEach { subtype ->
val locale = subtype.locale() val locale = subtype.locale()
usedLocaleLanguageTags.add(locale.toLanguageTag()) usedLocaleLanguageTags.add(locale.toLanguageTag())
} }

View file

@ -23,9 +23,7 @@ import java.util.Locale
object SubtypeSettings { object SubtypeSettings {
/** @return enabled subtypes. If no subtypes are enabled, but a contextForFallback is provided, /** @return enabled subtypes. If no subtypes are enabled, but a contextForFallback is provided,
* subtypes for system locales will be returned, or en-US if none found. */ * subtypes for system locales will be returned, or en-US if none found. */
fun getEnabledSubtypes(prefs: SharedPreferences, fallback: Boolean = false): List<InputMethodSubtype> { fun getEnabledSubtypes(fallback: Boolean = false): List<InputMethodSubtype> {
if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, Defaults.PREF_USE_SYSTEM_LOCALES))
return getDefaultEnabledSubtypes()
if (fallback && enabledSubtypes.isEmpty()) if (fallback && enabledSubtypes.isEmpty())
return getDefaultEnabledSubtypes() return getDefaultEnabledSubtypes()
return enabledSubtypes.toList() return enabledSubtypes.toList()
@ -78,17 +76,15 @@ object SubtypeSettings {
if (selectedAdditionalSubtype != null) return selectedAdditionalSubtype if (selectedAdditionalSubtype != null) return selectedAdditionalSubtype
} }
// no additional subtype, must be a resource subtype // no additional subtype, must be a resource subtype
val subtypes = if (prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, Defaults.PREF_USE_SYSTEM_LOCALES)) getDefaultEnabledSubtypes()
else enabledSubtypes
val subtype = subtypes.firstOrNull { it.toSettingsSubtype() == selectedSubtype } val subtype = enabledSubtypes.firstOrNull { it.toSettingsSubtype() == selectedSubtype }
if (subtype != null) { if (subtype != null) {
return subtype return subtype
} else { } else {
Log.w(TAG, "selected subtype $selectedSubtype / ${prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE)} not found") Log.w(TAG, "selected subtype $selectedSubtype / ${prefs.getString(Settings.PREF_SELECTED_SUBTYPE, Defaults.PREF_SELECTED_SUBTYPE)} not found")
} }
if (subtypes.isNotEmpty()) if (enabledSubtypes.isNotEmpty())
return subtypes.first() return enabledSubtypes.first()
val defaultSubtypes = getDefaultEnabledSubtypes() val defaultSubtypes = getDefaultEnabledSubtypes()
return defaultSubtypes.firstOrNull { it.locale() == selectedSubtype.locale && it.mainLayoutName() == it.mainLayoutName() } return defaultSubtypes.firstOrNull { it.locale() == selectedSubtype.locale && it.mainLayoutName() == it.mainLayoutName() }
?: defaultSubtypes.firstOrNull { it.locale().language == selectedSubtype.locale.language } ?: defaultSubtypes.firstOrNull { it.locale().language == selectedSubtype.locale.language }

View file

@ -47,7 +47,7 @@ fun NewDictionaryDialog(
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) } var locale by remember { mutableStateOf(mainLocale ?: dictLocale) }
val enabledLanguages = SubtypeSettings.getEnabledSubtypes(ctx.prefs()).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() }

View file

@ -33,7 +33,6 @@ import helium314.keyboard.latin.utils.SubtypeSettings
import helium314.keyboard.latin.utils.appendLink import helium314.keyboard.latin.utils.appendLink
import helium314.keyboard.latin.utils.getDictionaryLocales import helium314.keyboard.latin.utils.getDictionaryLocales
import helium314.keyboard.latin.utils.locale import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.SearchScreen import helium314.keyboard.settings.SearchScreen
import helium314.keyboard.settings.dialogs.ConfirmationDialog import helium314.keyboard.settings.dialogs.ConfirmationDialog
import helium314.keyboard.settings.dialogs.DictionaryDialog import helium314.keyboard.settings.dialogs.DictionaryDialog
@ -46,7 +45,7 @@ fun DictionaryScreen(
onClickBack: () -> Unit, onClickBack: () -> Unit,
) { ) {
val ctx = LocalContext.current val ctx = LocalContext.current
val enabledLanguages = SubtypeSettings.getEnabledSubtypes(ctx.prefs(), true).map { it.locale().language } val enabledLanguages = SubtypeSettings.getEnabledSubtypes(true).map { it.locale().language }
val cachedDictFolders = DictionaryInfoUtils.getCachedDirectoryList(ctx).orEmpty().map { it.name } val cachedDictFolders = DictionaryInfoUtils.getCachedDirectoryList(ctx).orEmpty().map { it.name }
val comparer = compareBy<Locale>({ it.language !in enabledLanguages }, { it.toLanguageTag() !in cachedDictFolders}, { it.displayName }) val comparer = compareBy<Locale>({ it.language !in enabledLanguages }, { it.toLanguageTag() !in cachedDictFolders}, { it.displayName })
val dictionaryLocales = getDictionaryLocales(ctx).sortedWith(comparer).toMutableList() val dictionaryLocales = getDictionaryLocales(ctx).sortedWith(comparer).toMutableList()

View file

@ -59,7 +59,7 @@ fun LanguageScreen(
if ((b?.value ?: 0) < 0) if ((b?.value ?: 0) < 0)
Log.v("irrelevant", "stupid way to trigger recomposition on preference change") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
var selectedSubtype: String? by rememberSaveable { mutableStateOf(null) } var selectedSubtype: String? by rememberSaveable { mutableStateOf(null) }
val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(prefs) val enabledSubtypes = SubtypeSettings.getEnabledSubtypes()
SearchScreen( SearchScreen(
onClickBack = onClickBack, onClickBack = onClickBack,
title = { title = {
@ -135,7 +135,7 @@ private fun dictsAvailable(locale: Locale, context: Context): Boolean {
// sorting by display name is still slow, even with the cache... but probably good enough // sorting by display name is still slow, even with the cache... but probably good enough
private fun getSortedSubtypes(context: Context): List<InputMethodSubtype> { private fun getSortedSubtypes(context: Context): List<InputMethodSubtype> {
val systemLocales = SubtypeSettings.getSystemLocales() val systemLocales = SubtypeSettings.getSystemLocales()
val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(context.prefs(), true) val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(true)
val localesWithDictionary = DictionaryInfoUtils.getCachedDirectoryList(context)?.mapNotNull { dir -> val localesWithDictionary = DictionaryInfoUtils.getCachedDirectoryList(context)?.mapNotNull { dir ->
if (!dir.isDirectory) if (!dir.isDirectory)
return@mapNotNull null return@mapNotNull null

View file

@ -51,7 +51,7 @@ fun MainSettingsScreen(
title = stringResource(R.string.ime_settings), title = stringResource(R.string.ime_settings),
settings = emptyList(), settings = emptyList(),
) { ) {
val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(ctx.prefs(), true) val enabledSubtypes = SubtypeSettings.getEnabledSubtypes(true)
Column(Modifier.verticalScroll(rememberScrollState())) { Column(Modifier.verticalScroll(rememberScrollState())) {
Preference( Preference(
name = stringResource(R.string.language_and_layouts_title), name = stringResource(R.string.language_and_layouts_title),

View file

@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.settings.screens package helium314.keyboard.settings.screens
import android.content.Context
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -18,14 +17,11 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.splitOnWhitespace import helium314.keyboard.latin.common.splitOnWhitespace
import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.SubtypeLocaleUtils import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.SubtypeSettings.getEnabledSubtypes import helium314.keyboard.latin.utils.SubtypeSettings.getEnabledSubtypes
import helium314.keyboard.latin.utils.SubtypeSettings.getSystemLocales import helium314.keyboard.latin.utils.SubtypeSettings.getSystemLocales
import helium314.keyboard.latin.utils.getSecondaryLocales import helium314.keyboard.latin.utils.getSecondaryLocales
import helium314.keyboard.latin.utils.locale import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.NextScreenIcon import helium314.keyboard.settings.NextScreenIcon
import helium314.keyboard.settings.SearchScreen import helium314.keyboard.settings.SearchScreen
import helium314.keyboard.settings.SettingsDestination import helium314.keyboard.settings.SettingsDestination
@ -38,7 +34,7 @@ fun PersonalDictionariesScreen(
) { ) {
// todo: consider adding "add word" button like old settings (requires additional navigation parameter, should not be hard) // todo: consider adding "add word" button like old settings (requires additional navigation parameter, should not be hard)
val ctx = LocalContext.current val ctx = LocalContext.current
val locales: MutableList<Locale?> = getSortedDictionaryLocales(LocalContext.current).toMutableList() val locales: MutableList<Locale?> = getSortedDictionaryLocales().toMutableList()
locales.add(0, null) locales.add(0, null)
SearchScreen( SearchScreen(
onClickBack = onClickBack, onClickBack = onClickBack,
@ -68,23 +64,19 @@ fun PersonalDictionariesScreen(
) )
} }
fun getSortedDictionaryLocales(context: Context): TreeSet<Locale> { fun getSortedDictionaryLocales(): TreeSet<Locale> {
val prefs = context.prefs()
val localeSystemOnly = prefs.getBoolean(Settings.PREF_USE_SYSTEM_LOCALES, Defaults.PREF_USE_SYSTEM_LOCALES)
val sortedLocales = sortedSetOf<Locale>(compareBy { it.toLanguageTag().lowercase() }) val sortedLocales = sortedSetOf<Locale>(compareBy { it.toLanguageTag().lowercase() })
// Add the main language selected in the "Language and Layouts" setting except "No language" // Add the main language selected in the "Language and Layouts" setting except "No language"
for (mainSubtype in getEnabledSubtypes(prefs, true)) { for (mainSubtype in getEnabledSubtypes(true)) {
val mainLocale = mainSubtype.locale() val mainLocale = mainSubtype.locale()
if (mainLocale.toLanguageTag() != SubtypeLocaleUtils.NO_LANGUAGE) { if (mainLocale.toLanguageTag() != SubtypeLocaleUtils.NO_LANGUAGE) {
sortedLocales.add(mainLocale) sortedLocales.add(mainLocale)
} }
// Secondary language is added only if main language is selected and if system language is not enabled // Secondary language is added only if main language is selected
if (!localeSystemOnly) { val enabled = getEnabledSubtypes(false)
val enabled = getEnabledSubtypes(prefs, false) for (subtype in enabled) {
for (subtype in enabled) { if (subtype.locale() == mainLocale) sortedLocales.addAll(getSecondaryLocales(subtype.extraValue))
if (subtype.locale() == mainLocale) sortedLocales.addAll(getSecondaryLocales(subtype.extraValue))
}
} }
} }

View file

@ -156,7 +156,7 @@ fun PersonalDictionaryScreen(
) { ) {
Text(stringResource(R.string.user_dict_settings_add_locale_option_name), Modifier.fillMaxWidth(0.3f)) Text(stringResource(R.string.user_dict_settings_add_locale_option_name), Modifier.fillMaxWidth(0.3f))
DropDownField( DropDownField(
items = getSpecificallySortedLocales(ctx, locale), items = getSpecificallySortedLocales(locale),
selectedItem = newLocale, selectedItem = newLocale,
onSelected = { newLocale = it }, onSelected = { newLocale = it },
) { ) {
@ -230,8 +230,8 @@ private fun doesWordExist(word: String, locale: Locale?, context: Context): Bool
} }
} }
private fun getSpecificallySortedLocales(context: Context, firstLocale: Locale?): List<Locale?> { private fun getSpecificallySortedLocales(firstLocale: Locale?): List<Locale?> {
val list: MutableList<Locale?> = getSortedDictionaryLocales(context).toMutableList() val list: MutableList<Locale?> = getSortedDictionaryLocales().toMutableList()
list.remove(firstLocale) list.remove(firstLocale)
list.remove(null) list.remove(null)
list.add(0, firstLocale) list.add(0, firstLocale)

View file

@ -57,7 +57,7 @@ fun PreferencesScreen(
Settings.PREF_KEYPRESS_SOUND_VOLUME else null, Settings.PREF_KEYPRESS_SOUND_VOLUME else null,
R.string.settings_category_additional_keys, R.string.settings_category_additional_keys,
Settings.PREF_SHOW_NUMBER_ROW, Settings.PREF_SHOW_NUMBER_ROW,
if (SubtypeSettings.getEnabledSubtypes(prefs, true).any { it.locale().language in localesWithLocalizedNumberRow }) if (SubtypeSettings.getEnabledSubtypes(true).any { it.locale().language in localesWithLocalizedNumberRow })
Settings.PREF_LOCALIZED_NUMBER_ROW else null, Settings.PREF_LOCALIZED_NUMBER_ROW else null,
if (prefs.getBoolean(Settings.PREF_SHOW_HINTS, Defaults.PREF_SHOW_HINTS) if (prefs.getBoolean(Settings.PREF_SHOW_HINTS, Defaults.PREF_SHOW_HINTS)
&& prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, Defaults.PREF_SHOW_NUMBER_ROW)) && prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, Defaults.PREF_SHOW_NUMBER_ROW))