fix internal main dictionary being used instead of user-added one

This commit is contained in:
Helium314 2023-08-28 17:07:23 +02:00
parent f0e5a38fa2
commit 4a2b09fe2e
2 changed files with 13 additions and 5 deletions

View file

@ -16,6 +16,8 @@
package org.dslul.openboard.inputmethod.latin; 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.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
@ -184,8 +186,11 @@ final public class BinaryDictionaryGetter {
final String category = final String category =
DictionaryInfoUtils.getCategoryFromFileName(wordList.getName()); DictionaryInfoUtils.getCategoryFromFileName(wordList.getName());
final FileAndMatchLevel currentBestMatch = cacheFiles.get(category); final FileAndMatchLevel currentBestMatch = cacheFiles.get(category);
if (null == currentBestMatch || currentBestMatch.mMatchLevel < matchLevel) { if (null == currentBestMatch || currentBestMatch.mMatchLevel <= matchLevel) {
cacheFiles.put(category, new FileAndMatchLevel(wordList, 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. * - Returns null.
* @return The list of addresses of valid dictionary files, or 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<AssetFileAddress> getDictionaryFiles(final Locale locale, public static ArrayList<AssetFileAddress> getDictionaryFiles(final Locale locale,
final Context context, boolean notifyDictionaryPackForUpdates, final boolean weakMatchAcceptable) { final Context context, boolean notifyDictionaryPackForUpdates, final boolean weakMatchAcceptable) {
loadDictionaryFromAssets(locale.toString(), context, weakMatchAcceptable); // will copy dict to cached word lists if not existing loadDictionaryFromAssets(locale.toString(), context, weakMatchAcceptable); // will copy dict to cached word lists if not existing

View file

@ -258,9 +258,10 @@ class LanguageSettingsDialog(
} }
if (dictionaryType == DictionaryInfoUtils.DEFAULT_MAIN_DICT) { if (dictionaryType == DictionaryInfoUtils.DEFAULT_MAIN_DICT) {
// replaced main dict, remove the one created from internal data // replaced main dict, remove the one created from internal data
val internalMainDictFilename = DictionaryInfoUtils.getCacheDirectoryForLocale(mainLocaleString, context) + // todo: currently not, see also BinaryDictionaryGetter.getDictionaryFiles
File.separator + DictionaryInfoUtils.getMainDictFilename(mainLocaleString) // val internalMainDictFilename = DictionaryInfoUtils.getCacheDirectoryForLocale(mainLocaleString, context) +
File(internalMainDictFilename).delete() // File.separator + DictionaryInfoUtils.getMainDictFilename(mainLocaleString)
// File(internalMainDictFilename).delete()
} }
val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION) val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)
fragment?.activity?.sendBroadcast(newDictBroadcast) fragment?.activity?.sendBroadcast(newDictBroadcast)