mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-02 21:04:28 +00:00
more thoroughly test added dictionaries
This commit is contained in:
parent
800fb29f21
commit
9ef79821f4
2 changed files with 9 additions and 8 deletions
|
@ -96,7 +96,7 @@ public final class DictionaryFactory {
|
||||||
public static void killDictionary(final Context context, final AssetFileAddress f) {
|
public static void killDictionary(final Context context, final AssetFileAddress f) {
|
||||||
if (f.pointsToPhysicalFile()) {
|
if (f.pointsToPhysicalFile()) {
|
||||||
f.deleteUnderlyingFile();
|
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
|
// but not that important, as the not working dictionary should be obvious
|
||||||
final String wordlistId = DictionaryInfoUtils.getWordListIdFromFileName(new File(f.mFilename).getName());
|
final String wordlistId = DictionaryInfoUtils.getWordListIdFromFileName(new File(f.mFilename).getName());
|
||||||
new Handler(Looper.getMainLooper()).post(() ->
|
new Handler(Looper.getMainLooper()).post(() ->
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.net.Uri
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import org.dslul.openboard.inputmethod.dictionarypack.DictionaryPackConstants
|
import org.dslul.openboard.inputmethod.dictionarypack.DictionaryPackConstants
|
||||||
import org.dslul.openboard.inputmethod.latin.R
|
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.FileUtils
|
||||||
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils
|
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils
|
||||||
import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader
|
import org.dslul.openboard.inputmethod.latin.makedict.DictionaryHeader
|
||||||
|
@ -26,10 +27,7 @@ class NewDictionaryAdder(private val context: Context, private val onAdded: ((Bo
|
||||||
cachedDictionaryFile.delete()
|
cachedDictionaryFile.delete()
|
||||||
try {
|
try {
|
||||||
val i = context.contentResolver.openInputStream(uri)
|
val i = context.contentResolver.openInputStream(uri)
|
||||||
FileUtils.copyStreamToNewFile(
|
FileUtils.copyStreamToNewFile(i, cachedDictionaryFile)
|
||||||
i,
|
|
||||||
cachedDictionaryFile
|
|
||||||
)
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
return onDictionaryLoadingError(R.string.dictionary_load_error)
|
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)
|
?: return onDictionaryLoadingError(R.string.dictionary_file_error)
|
||||||
val locale = newHeader.mLocaleString.toLocale()
|
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) {
|
if (mainLocale == null) {
|
||||||
val localeName = LocaleUtils.getLocaleDisplayNameInSystemLocale(locale, context)
|
val localeName = LocaleUtils.getLocaleDisplayNameInSystemLocale(locale, context)
|
||||||
val message = context.getString(R.string.add_new_dictionary_ask_locale,
|
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) {
|
private fun onDictionaryLoadingError(messageId: Int) {
|
||||||
cachedDictionaryFile.delete()
|
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)
|
infoDialog(context, messageId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue