From 27f2492edde4d34f2e53e0cdb9f9c413c3ad4d8e Mon Sep 17 00:00:00 2001 From: Helium314 Date: Thu, 1 Feb 2024 19:46:44 +0100 Subject: [PATCH] fix some missed cases of using langauge tag instead of locale string string conversion was implicit, so a bit harder to find fixes #469 --- .../settings/PreferencesSettingsFragment.java | 3 ++- .../keyboard/latin/settings/Settings.java | 4 ++-- .../keyboard/latin/settings/SettingsValues.java | 7 +++---- .../keyboard/latin/utils/DictionaryInfoUtils.java | 15 --------------- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java b/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java index 0f7c3edaa..cd78f0132 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java @@ -22,6 +22,7 @@ import helium314.keyboard.latin.R; import helium314.keyboard.latin.RichInputMethodManager; import helium314.keyboard.latin.utils.MoreKeysUtilsKt; import helium314.keyboard.latin.utils.SubtypeSettingsKt; +import helium314.keyboard.latin.utils.SubtypeUtilsKt; import helium314.keyboard.latin.utils.ToolbarUtilsKt; 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) final String[] numberRowLocales = new String[] { "ar", "bn", "fa", "gu", "hi", "mr", "ne", "ur" }; 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); return; } diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java index 315987a27..3a4fe3be5 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java @@ -579,14 +579,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static void setSecondaryLocales(final SharedPreferences prefs, final Locale mainLocale, final List locales) { if (locales.isEmpty()) { - prefs.edit().putString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale, "").apply(); + prefs.edit().putString(PREF_SECONDARY_LOCALES_PREFIX + mainLocale.toLanguageTag(), "").apply(); return; } final StringBuilder sb = new StringBuilder(); for (Locale locale : locales) { 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) { diff --git a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java index fb137261a..5e7f58b96 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java @@ -27,7 +27,6 @@ import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.MoreKeysUtilsKt; import helium314.keyboard.latin.utils.ScriptUtils; import helium314.keyboard.latin.utils.SubtypeSettingsKt; -import helium314.keyboard.latin.utils.SubtypeUtilsKt; import java.util.Arrays; import java.util.List; @@ -208,7 +207,7 @@ public class SettingsValues { } else mOneHandedModeScale = 1f; final InputMethodSubtype selectedSubtype = SubtypeSettingsKt.getSelectedSubtype(prefs); - mSecondaryLocales = Settings.getSecondaryLocales(prefs, SubtypeUtilsKt.locale(selectedSubtype)); + mSecondaryLocales = Settings.getSecondaryLocales(prefs, mLocale); mShowMoreMoreKeys = selectedSubtype.isAsciiCapable() ? Settings.readMoreMoreKeysPref(prefs) : LocaleKeyTextsKt.MORE_KEYS_NORMAL; @@ -216,9 +215,9 @@ public class SettingsValues { // 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); - 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); - 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); mUseContactsDictionary = prefs.getBoolean(Settings.PREF_USE_CONTACTS, false); diff --git a/app/src/main/java/helium314/keyboard/latin/utils/DictionaryInfoUtils.java b/app/src/main/java/helium314/keyboard/latin/utils/DictionaryInfoUtils.java index 94d36d2be..6415f3718 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/DictionaryInfoUtils.java +++ b/app/src/main/java/helium314/keyboard/latin/utils/DictionaryInfoUtils.java @@ -136,21 +136,6 @@ public class DictionaryInfoUtils { return cachedDir.listFiles(); } - /** - * Returns the id associated with the main word list for a specified locale. - *

- * 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() { return DEFAULT_MAIN_DICT + ".dict"; }