From 4a2b09fe2e6d8017f6df096926b9a549c8c26547 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Mon, 28 Aug 2023 17:07:23 +0200 Subject: [PATCH] fix internal main dictionary being used instead of user-added one --- .../inputmethod/latin/BinaryDictionaryGetter.java | 11 +++++++++-- .../latin/settings/LanguageSettingsDialog.kt | 7 ++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java b/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java index 790bfdb0e..8e1c0df09 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/BinaryDictionaryGetter.java @@ -16,6 +16,8 @@ package org.dslul.openboard.inputmethod.latin; +import static org.dslul.openboard.inputmethod.latin.settings.LanguageSettingsFragmentKt.USER_DICTIONARY_SUFFIX; + import android.content.Context; import android.content.SharedPreferences; import android.content.res.AssetFileDescriptor; @@ -184,8 +186,11 @@ final public class BinaryDictionaryGetter { final String category = DictionaryInfoUtils.getCategoryFromFileName(wordList.getName()); final FileAndMatchLevel currentBestMatch = cacheFiles.get(category); - if (null == currentBestMatch || currentBestMatch.mMatchLevel < matchLevel) { - cacheFiles.put(category, new FileAndMatchLevel(wordList, matchLevel)); + if (null == currentBestMatch || currentBestMatch.mMatchLevel <= matchLevel) { + // todo: not nice, related to getDictionaryFiles todo + // this is so user-added main dict has priority over internal main dict + if ("main".equals(category) && (wordList.getName().endsWith(USER_DICTIONARY_SUFFIX) || currentBestMatch == null)) + cacheFiles.put(category, new FileAndMatchLevel(wordList, matchLevel)); } } } @@ -244,6 +249,8 @@ final public class BinaryDictionaryGetter { * - Returns null. * @return The list of addresses of valid dictionary files, or null. */ + // todo: the way of using assets and cached lists should be improved, so that the assets file + // doesn't need to be in cached dir just for checking whether it's a good match public static ArrayList getDictionaryFiles(final Locale locale, final Context context, boolean notifyDictionaryPackForUpdates, final boolean weakMatchAcceptable) { loadDictionaryFromAssets(locale.toString(), context, weakMatchAcceptable); // will copy dict to cached word lists if not existing diff --git a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt index 2aed9aafb..aefc223f2 100644 --- a/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt +++ b/app/src/main/java/org/dslul/openboard/inputmethod/latin/settings/LanguageSettingsDialog.kt @@ -258,9 +258,10 @@ class LanguageSettingsDialog( } if (dictionaryType == DictionaryInfoUtils.DEFAULT_MAIN_DICT) { // replaced main dict, remove the one created from internal data - val internalMainDictFilename = DictionaryInfoUtils.getCacheDirectoryForLocale(mainLocaleString, context) + - File.separator + DictionaryInfoUtils.getMainDictFilename(mainLocaleString) - File(internalMainDictFilename).delete() + // todo: currently not, see also BinaryDictionaryGetter.getDictionaryFiles +// val internalMainDictFilename = DictionaryInfoUtils.getCacheDirectoryForLocale(mainLocaleString, context) + +// File.separator + DictionaryInfoUtils.getMainDictFilename(mainLocaleString) +// File(internalMainDictFilename).delete() } val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION) fragment?.activity?.sendBroadcast(newDictBroadcast)