more thoroughly test added dictionaries

This commit is contained in:
Helium314 2023-11-22 20:32:04 +01:00
parent 800fb29f21
commit 9ef79821f4
2 changed files with 9 additions and 8 deletions

View file

@ -96,7 +96,7 @@ public final class DictionaryFactory {
public static void killDictionary(final Context context, final AssetFileAddress f) {
if (f.pointsToPhysicalFile()) {
f.deleteUnderlyingFile();
// notify the user if possible (toast not showing up on Android 13+)
// notify the user if possible (toast not showing up on Android 13+ when not in settings)
// but not that important, as the not working dictionary should be obvious
final String wordlistId = DictionaryInfoUtils.getWordListIdFromFileName(new File(f.mFilename).getName());
new Handler(Looper.getMainLooper()).post(() ->

View file

@ -8,6 +8,7 @@ import android.net.Uri
import androidx.appcompat.app.AlertDialog
import org.dslul.openboard.inputmethod.dictionarypack.DictionaryPackConstants
import org.dslul.openboard.inputmethod.latin.R
import org.dslul.openboard.inputmethod.latin.ReadOnlyBinaryDictionary
import org.dslul.openboard.inputmethod.latin.common.FileUtils
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils
import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader
@ -26,10 +27,7 @@ class NewDictionaryAdder(private val context: Context, private val onAdded: ((Bo
cachedDictionaryFile.delete()
try {
val i = context.contentResolver.openInputStream(uri)
FileUtils.copyStreamToNewFile(
i,
cachedDictionaryFile
)
FileUtils.copyStreamToNewFile(i, cachedDictionaryFile)
} catch (e: IOException) {
return onDictionaryLoadingError(R.string.dictionary_load_error)
}
@ -38,6 +36,12 @@ class NewDictionaryAdder(private val context: Context, private val onAdded: ((Bo
?: return onDictionaryLoadingError(R.string.dictionary_file_error)
val locale = newHeader.mLocaleString.toLocale()
val dict = ReadOnlyBinaryDictionary(cachedDictionaryFile.absolutePath, 0, cachedDictionaryFile.length(), false, locale, "test")
if (!dict.isValidDictionary) {
dict.close()
return onDictionaryLoadingError(R.string.dictionary_load_error)
}
if (mainLocale == null) {
val localeName = LocaleUtils.getLocaleDisplayNameInSystemLocale(locale, context)
val message = context.getString(R.string.add_new_dictionary_ask_locale,
@ -141,9 +145,6 @@ class NewDictionaryAdder(private val context: Context, private val onAdded: ((Bo
private fun onDictionaryLoadingError(messageId: Int) {
cachedDictionaryFile.delete()
// Toast.makeText(context, messageId, Toast.LENGTH_LONG).show()
// show a dialog because toasts are not showing up on some Android versions
// possibly Android 13 because of notification permission
infoDialog(context, messageId)
}
}