fix some missed cases of using langauge tag instead of locale string

string conversion was implicit, so a bit harder to find
fixes #469
This commit is contained in:
Helium314 2024-02-01 19:46:44 +01:00
parent faf75963a8
commit 27f2492edd
4 changed files with 7 additions and 22 deletions

View file

@ -22,6 +22,7 @@ import helium314.keyboard.latin.R;
import helium314.keyboard.latin.RichInputMethodManager; import helium314.keyboard.latin.RichInputMethodManager;
import helium314.keyboard.latin.utils.MoreKeysUtilsKt; import helium314.keyboard.latin.utils.MoreKeysUtilsKt;
import helium314.keyboard.latin.utils.SubtypeSettingsKt; import helium314.keyboard.latin.utils.SubtypeSettingsKt;
import helium314.keyboard.latin.utils.SubtypeUtilsKt;
import helium314.keyboard.latin.utils.ToolbarUtilsKt; import helium314.keyboard.latin.utils.ToolbarUtilsKt;
import kotlin.collections.ArraysKt; import kotlin.collections.ArraysKt;
@ -104,7 +105,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
// 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", "mr", "ne", "ur" }; final String[] numberRowLocales = new String[] { "ar", "bn", "fa", "gu", "hi", "mr", "ne", "ur" };
for (final InputMethodSubtype subtype : SubtypeSettingsKt.getEnabledSubtypes(getSharedPreferences(), true)) { for (final InputMethodSubtype subtype : SubtypeSettingsKt.getEnabledSubtypes(getSharedPreferences(), true)) {
if (ArraysKt.any(numberRowLocales, (l) -> l.equals(subtype.getLocale().substring(0, 2)))) { if (ArraysKt.any(numberRowLocales, (l) -> l.equals(SubtypeUtilsKt.locale(subtype).getLanguage()))) {
pref.setVisible(true); pref.setVisible(true);
return; return;
} }

View file

@ -579,14 +579,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static void setSecondaryLocales(final SharedPreferences prefs, final Locale mainLocale, final List<Locale> locales) { public static void setSecondaryLocales(final SharedPreferences prefs, final Locale mainLocale, final List<Locale> locales) {
if (locales.isEmpty()) { if (locales.isEmpty()) {
prefs.edit().putString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale, "").apply(); prefs.edit().putString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale.toLanguageTag(), "").apply();
return; return;
} }
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (Locale locale : locales) { for (Locale locale : locales) {
sb.append(";").append(locale.toLanguageTag()); sb.append(";").append(locale.toLanguageTag());
} }
prefs.edit().putString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale, sb.toString()).apply(); prefs.edit().putString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale.toLanguageTag(), sb.toString()).apply();
} }
public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) { public static Colors getColorsForCurrentTheme(final Context context, final SharedPreferences prefs) {

View file

@ -27,7 +27,6 @@ import helium314.keyboard.latin.utils.Log;
import helium314.keyboard.latin.utils.MoreKeysUtilsKt; import helium314.keyboard.latin.utils.MoreKeysUtilsKt;
import helium314.keyboard.latin.utils.ScriptUtils; import helium314.keyboard.latin.utils.ScriptUtils;
import helium314.keyboard.latin.utils.SubtypeSettingsKt; import helium314.keyboard.latin.utils.SubtypeSettingsKt;
import helium314.keyboard.latin.utils.SubtypeUtilsKt;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -208,7 +207,7 @@ public class SettingsValues {
} else } else
mOneHandedModeScale = 1f; mOneHandedModeScale = 1f;
final InputMethodSubtype selectedSubtype = SubtypeSettingsKt.getSelectedSubtype(prefs); final InputMethodSubtype selectedSubtype = SubtypeSettingsKt.getSelectedSubtype(prefs);
mSecondaryLocales = Settings.getSecondaryLocales(prefs, SubtypeUtilsKt.locale(selectedSubtype)); mSecondaryLocales = Settings.getSecondaryLocales(prefs, mLocale);
mShowMoreMoreKeys = selectedSubtype.isAsciiCapable() mShowMoreMoreKeys = selectedSubtype.isAsciiCapable()
? Settings.readMoreMoreKeysPref(prefs) ? Settings.readMoreMoreKeysPref(prefs)
: LocaleKeyTextsKt.MORE_KEYS_NORMAL; : LocaleKeyTextsKt.MORE_KEYS_NORMAL;
@ -216,9 +215,9 @@ public class SettingsValues {
// read locale-specific popup key settings, fall back to global settings // read locale-specific popup key settings, fall back to global settings
final String moreKeyTypesDefault = prefs.getString(Settings.PREF_POPUP_KEYS_ORDER, MoreKeysUtilsKt.MORE_KEYS_ORDER_DEFAULT); final String moreKeyTypesDefault = prefs.getString(Settings.PREF_POPUP_KEYS_ORDER, MoreKeysUtilsKt.MORE_KEYS_ORDER_DEFAULT);
mMoreKeyTypes = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_ORDER + "_" + selectedSubtype.getLocale(), moreKeyTypesDefault); mMoreKeyTypes = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_ORDER + "_" + mLocale.toLanguageTag(), moreKeyTypesDefault);
final String moreKeyLabelDefault = prefs.getString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, MoreKeysUtilsKt.MORE_KEYS_LABEL_DEFAULT); final String moreKeyLabelDefault = prefs.getString(Settings.PREF_POPUP_KEYS_LABELS_ORDER, MoreKeysUtilsKt.MORE_KEYS_LABEL_DEFAULT);
mMoreKeyLabelSources = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_LABELS_ORDER + "_" + selectedSubtype.getLocale(), moreKeyLabelDefault); mMoreKeyLabelSources = MoreKeysUtilsKt.getEnabledMoreKeys(prefs, Settings.PREF_POPUP_KEYS_LABELS_ORDER + "_" + mLocale.toLanguageTag(), moreKeyLabelDefault);
mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false); mAddToPersonalDictionary = prefs.getBoolean(Settings.PREF_ADD_TO_PERSONAL_DICTIONARY, false);
mUseContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, false); mUseContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, false);

View file

@ -136,21 +136,6 @@ public class DictionaryInfoUtils {
return cachedDir.listFiles(); return cachedDir.listFiles();
} }
/**
* Returns the id associated with the main word list for a specified locale.
* <p>
* Word lists stored in Android Keyboard's resources are referred to as the "main"
* word lists. Since they can be updated like any other list, we need to assign a
* unique ID to them. This ID is just the name of the language (locale-wise) they
* are for, and this method returns this ID.
*/
public static String getMainDictId(@NonNull final Locale locale) {
// This works because we don't include by default different dictionaries for
// different countries. This actually needs to return the id that we would
// like to use for word lists included in resources, and the following is okay.
return Dictionary.TYPE_MAIN + ID_CATEGORY_SEPARATOR + locale.toString().toLowerCase();
}
public static String getExtractedMainDictFilename() { public static String getExtractedMainDictFilename() {
return DEFAULT_MAIN_DICT + ".dict"; return DEFAULT_MAIN_DICT + ".dict";
} }