1
0
Fork 0

custom words that are already included in the dictionary are now purged on language reload

This commit is contained in:
sspanak 2024-03-12 12:07:34 +02:00 committed by Dimo Karaivanov
parent f1cf4554f3
commit 282a9ae8ed
4 changed files with 26 additions and 10 deletions

View file

@ -180,18 +180,23 @@ public class DictionaryLoader {
sendProgressMessage(language, ++progress, SettingsStore.DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME); sendProgressMessage(language, ++progress, SettingsStore.DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME);
logLoadingStep("Letters imported", language, start); logLoadingStep("Letters imported", language, start);
start = System.currentTimeMillis();
importWordFile(language, lettersCount, progress, 88);
progress = 88;
sendProgressMessage(language, progress, SettingsStore.DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME);
logLoadingStep("Dictionary file imported", language, start);
start = System.currentTimeMillis();
DeleteOps.purgeCustomWords(sqlite.getDb(), language.getId());
sendProgressMessage(language, ++progress, SettingsStore.DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME);
logLoadingStep("Removed custom words, which are already in the dictionary", language, start);
start = System.currentTimeMillis(); start = System.currentTimeMillis();
InsertOps.restoreCustomWords(sqlite.getDb(), language); InsertOps.restoreCustomWords(sqlite.getDb(), language);
InsertOps.restoreCustomWords(sqlite.getDb(), new EmojiLanguage()); InsertOps.restoreCustomWords(sqlite.getDb(), new EmojiLanguage());
sendProgressMessage(language, ++progress, SettingsStore.DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME); sendProgressMessage(language, ++progress, SettingsStore.DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME);
logLoadingStep("Custom words restored", language, start); logLoadingStep("Custom words restored", language, start);
start = System.currentTimeMillis();
importWordFile(language, lettersCount, progress, 90);
progress = 90;
sendProgressMessage(language, progress, SettingsStore.DICTIONARY_IMPORT_PROGRESS_UPDATE_TIME);
logLoadingStep("Dictionary file imported", language, start);
start = System.currentTimeMillis(); start = System.currentTimeMillis();
Tables.createPositionIndex(sqlite.getDb(), language); Tables.createPositionIndex(sqlite.getDb(), language);
sendProgressMessage(language, progress + (100f - progress) / 2f, 0); sendProgressMessage(language, progress + (100f - progress) / 2f, 0);
@ -290,7 +295,7 @@ public class DictionaryLoader {
} }
public void saveWordBatch(WordBatch batch) { private void saveWordBatch(WordBatch batch) {
InsertOps insertOps = new InsertOps(sqlite.getDb(), batch.getLanguage()); InsertOps insertOps = new InsertOps(sqlite.getDb(), batch.getLanguage());
for (int i = 0, end = batch.getWords().size(); i < end; i++) { for (int i = 0, end = batch.getWords().size(); i < end; i++) {

View file

@ -77,10 +77,10 @@ public class DictionaryExporter extends AbstractExporter {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
write(activity); write(activity);
sendSuccess(); sendSuccess();
Logger.d(LOG_TAG, "All words for language: " + currentLanguage.getName() + " loaded. Time: " + (System.currentTimeMillis() - start) + "ms"); Logger.d(LOG_TAG, "All words for language '" + currentLanguage.getName() + "' exported. Time: " + (System.currentTimeMillis() - start) + "ms");
} catch (Exception e) { } catch (Exception e) {
sendFailure(); sendFailure();
Logger.e(LOG_TAG, "Failed exporting dictionary for " + currentLanguage.getName() + " to: " + getOutputFile() + ". " + e); Logger.e(LOG_TAG, "Failed exporting dictionary for '" + currentLanguage.getName() + "' to '" + getOutputFile() + "'. " + e);
} }
} }
} }

View file

@ -14,4 +14,15 @@ public class DeleteOps {
db.delete(Tables.getWords(languageId), "word = ?", new String[] { word }); db.delete(Tables.getWords(languageId), "word = ?", new String[] { word });
db.delete(Tables.CUSTOM_WORDS, "word = ?", new String[] { word }); db.delete(Tables.CUSTOM_WORDS, "word = ?", new String[] { word });
} }
public static void purgeCustomWords(@NonNull SQLiteDatabase db, int languageId) {
String words = Tables.getWords(languageId);
String repeatingWords =
"SELECT " + Tables.CUSTOM_WORDS + ".ROWID FROM " + Tables.CUSTOM_WORDS +
" JOIN " + words + " ON " + words + ".word = " + Tables.CUSTOM_WORDS + ".word " +
" WHERE langId = " + languageId + " AND " + words + ".position > 0";
db.delete(Tables.CUSTOM_WORDS, "ROWID IN (" + repeatingWords + ")", null);
}
} }

View file

@ -22,7 +22,7 @@ public class SQLiteOpener extends SQLiteOpenHelper {
private SQLiteDatabase db; private SQLiteDatabase db;
public SQLiteOpener(Context context) { private SQLiteOpener(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION); super(context, DATABASE_NAME, null, DATABASE_VERSION);
allLanguages = new ArrayList<>(LanguageCollection.getAll(context)); allLanguages = new ArrayList<>(LanguageCollection.getAll(context));
allLanguages.add(new EmojiLanguage()); allLanguages.add(new EmojiLanguage());