diff --git a/docs/user-manual.md b/docs/user-manual.md
index 18ca8a9b..4d893f13 100644
--- a/docs/user-manual.md
+++ b/docs/user-manual.md
@@ -23,19 +23,19 @@ _If you don't do the above, there will be no suggestions when typing in Predicti
### Dictionary Tips
#### Loading a Dictionary
-Once a dictionary is loaded, it will stay there until you use one of the "clear" options. This means you can enable and disable languages without reloading their dictionaries every time. Just do it once, only the first time.
+Once a dictionary is loaded, it will stay there until you use one of the "delete" options. This means you can enable and disable languages without reloading their dictionaries every time. Just do it once, only the first time.
It also means that if you need to start using language X, you can safely disable all other languages, load only dictionary X (and save time!), then re-enable all languages you used before.
Have in mind reloading a dictionary will reset the suggestion popularity to the factory defaults _(your custom added words will not be affected)_. However, there should be nothing to worry about. For the most part, you will see little to no difference in the suggestion order, unless you oftenly use uncommon words.
-#### Clearing a Dictionary
+#### Deleting a Dictionary
-If you have stopped using languages X or Y, you could disable them and also use "Clear Unselected", to delete their dictionaries and free some memory.
+If you have stopped using languages X or Y, you could disable them and also use "Delete Unselected", to remove their dictionaries and free some memory.
-To delete everything, regardless of the selection, use "Clear All".
+To delete everything, regardless of the selection, use "Delete All".
-In all cases, clearing a dictionary deletes both all factory and all custom added words.
+In all cases, deleting a dictionary removes both all factory and all custom added words.
## Hotkeys
diff --git a/res/values-bg/strings.xml b/res/values-bg/strings.xml
index bc09741c..307bcced 100644
--- a/res/values-bg/strings.xml
+++ b/res/values-bg/strings.xml
@@ -64,4 +64,5 @@
Цифрова клавиатура на екрана
Намаляне на звук
Усилване на звук
+ Изтриване…
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 166683cf..8456fce0 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -14,7 +14,7 @@
Aide
Thème sombre
Langues
- Vider tous
+ Supprimer tous
Annuler le chargement
Echec du chargement de dictionnaire pour langue «%1$s» (%2$s).
@@ -25,7 +25,7 @@
Raccourcis clavier
Apparance
Echec du chargement. Mot inadmissible «%1$s» à la ligne %2$d de langue «%3$s».
- Le dictionaire est vidé avec succès.
+ Le dictionaire est supprimé avec succès.
Boutons à l\'écran
Chargement du dictionnaire
Chargement est annulé.
@@ -47,7 +47,8 @@
Tapez un mot…
Inverser l\'ordre des clés
Activez le paramètre s\'il y a 7–8–9 sur le premier rang, au lieu de 1–2–3.
- Vider les non sélectionnés
+ Supprimer les non sélectionnés
Configuration initiale
Pavé numérique à l\'écran
+ Suppression…
diff --git a/res/values-nl/strings.xml b/res/values-nl/strings.xml
index 54fc28fe..ac487c57 100644
--- a/res/values-nl/strings.xml
+++ b/res/values-nl/strings.xml
@@ -20,4 +20,5 @@
Spatie
Nieuwe regel
Initiële setup
+ Verwijderen…
diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml
index a6457030..34d42e14 100644
--- a/res/values-ru/strings.xml
+++ b/res/values-ru/strings.xml
@@ -13,7 +13,7 @@
Помощь
Темная тема
Языки
- Очистить все
+ Удалить все
Отменить загрузку
Ошибка загрузки словаря для языка «%1$s» (%2$s).
@@ -21,7 +21,7 @@
Загрузка словаря (%1$s)…
Загрузить словарь
Ошибка загрузки. Словарь «%1$s» не найден.
- Словарь успешно очищен.
+ Словарь успешно удален.
Загрузка словаря
Загрузка отменена.
Режим подсказки
@@ -59,9 +59,10 @@
Введите слово…
Перевернутая клавиатура
Используйте настройку, если в первом ряду 7–8–9 вместо 1–2–3.
- Очистить невыбранные
+ Удалить невыбранные
Начальная настройка
Экранная цифровая клавиатура
Уменьшить громкости
Увеличить громкости
+ Удаление…
diff --git a/res/values-uk/strings.xml b/res/values-uk/strings.xml
index 38f05974..163746ca 100644
--- a/res/values-uk/strings.xml
+++ b/res/values-uk/strings.xml
@@ -13,7 +13,7 @@
Допомога
Темна тема
Мови
- Очистіть усі
+ Видалити усі
Скасувати завантаження
Помилка завантаження словника для мови «%1$s» (%2$s).
@@ -53,15 +53,16 @@
Налаштування
Налаштування кнопок за замовчуванням відновлено
Повернути кнопки за замовчуванням
- Словник успішно очищено.
+ Словник успішно видалено.
Немає словника для мови «%1$s». Перейдіть до Налаштувань, щоб завантажити його.
Помилка завантаження. Недійсне слово «%1$s» в рядку %2$d мови «%3$s».
Введіть слово…
Зворотна клавіатура
Використовуйте налаштування, якщо 7–8–9 у першому рядку замість 1–2–3.
- Очистіть невибрані
+ Видалити невибрані
Початкове налаштування
Екранна цифрова клавіатура
Збільшення гучності
Зменшення гучності
+ Видалення…
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3ef2f1f6..04a0230a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -49,9 +49,10 @@
Load Dictionary
No dictionary for language \"%1$s\". Go to Settings to load it.
Loading failed. Dictionary for \"%1$s\" not found.
- Clear All
- Clear Unselected
+ Delete All
+ Delete Unselected
Dictionary successfully cleared.
+ Deleting…
Add Word key
Backspace key
diff --git a/src/io/github/sspanak/tt9/db/DictionaryDb.java b/src/io/github/sspanak/tt9/db/DictionaryDb.java
index 2cf2e551..f04dca86 100644
--- a/src/io/github/sspanak/tt9/db/DictionaryDb.java
+++ b/src/io/github/sspanak/tt9/db/DictionaryDb.java
@@ -70,23 +70,6 @@ public class DictionaryDb {
}
- public static void createShortWordIndexSync() {
- getInstance().wordsDao().rawQuery(TT9Room.createShortWordsIndexQuery());
- }
-
- public static void createLongWordIndexSync() {
- getInstance().wordsDao().rawQuery(TT9Room.createLongWordsIndexQuery());
- }
-
- public static void dropShortWordIndexSync() {
- getInstance().wordsDao().rawQuery(TT9Room.dropShortWordsIndexQuery());
- }
-
- public static void dropLongWordIndexSync() {
- getInstance().wordsDao().rawQuery(TT9Room.dropLongWordsIndexQuery());
- }
-
-
/**
* normalizeWordFrequencies
* Normalizes the word frequencies for all languages that have reached the maximum, as defined in
@@ -95,28 +78,26 @@ public class DictionaryDb {
*/
public static void normalizeWordFrequencies(SettingsStore settings) {
new Thread(() -> {
- long time = System.currentTimeMillis();
+ long time = System.currentTimeMillis();
- int affectedRows = getInstance().wordsDao().normalizeFrequencies(
- settings.getWordFrequencyNormalizationDivider(),
- settings.getWordFrequencyMax()
- );
+ int affectedRows = getInstance().wordsDao().normalizeFrequencies(
+ settings.getWordFrequencyNormalizationDivider(),
+ settings.getWordFrequencyMax()
+ );
- Logger.d(
- "db.normalizeWordFrequencies",
- "Normalized " + affectedRows + " words in: " + (System.currentTimeMillis() - time) + " ms"
- );
- }
- ).start();
+ Logger.d(
+ "db.normalizeWordFrequencies",
+ "Normalized " + affectedRows + " words in: " + (System.currentTimeMillis() - time) + " ms"
+ );
+ }).start();
}
public static void areThereWords(ConsumerCompat notification, Language language) {
new Thread(() -> {
- int langId = language != null ? language.getId() : -1;
- notification.accept(getInstance().wordsDao().count(langId) > 0);
- }
- ).start();
+ int langId = language != null ? language.getId() : -1;
+ notification.accept(getInstance().wordsDao().count(langId) > 0);
+ }).start();
}
@@ -136,14 +117,13 @@ public class DictionaryDb {
public static void deleteWords(Runnable notification, ArrayList languageIds) {
new Thread(() -> {
- if (languageIds == null) {
- getInstance().clearAllTables();
- } else if (languageIds.size() > 0) {
- getInstance().wordsDao().deleteByLanguage(languageIds);
- }
- notification.run();
+ if (languageIds == null) {
+ getInstance().clearAllTables();
+ } else if (languageIds.size() > 0) {
+ getInstance().wordsDao().deleteByLanguage(languageIds);
}
- ).start();
+ notification.run();
+ }).start();
}
@@ -164,22 +144,21 @@ public class DictionaryDb {
dbWord.frequency = 1;
new Thread(() -> {
- try {
- getInstance().wordsDao().insert(dbWord);
- getInstance().wordsDao().incrementFrequency(dbWord.langId, dbWord.word, dbWord.sequence);
- statusHandler.accept(0);
- } catch (SQLiteConstraintException e) {
- String msg = "Constraint violation when inserting a word: '" + dbWord.word + "' / sequence: '" + dbWord.sequence + "', for language: " + dbWord.langId
- + ". " + e.getMessage();
- Logger.e("tt9/insertWord", msg);
- statusHandler.accept(1);
- } catch (Exception e) {
- String msg = "Failed inserting word: '" + dbWord.word + "' / sequence: '" + dbWord.sequence + "', for language: " + dbWord.langId + ". " + e.getMessage();
- Logger.e("tt9/insertWord", msg);
- statusHandler.accept(2);
- }
+ try {
+ getInstance().wordsDao().insert(dbWord);
+ getInstance().wordsDao().incrementFrequency(dbWord.langId, dbWord.word, dbWord.sequence);
+ statusHandler.accept(0);
+ } catch (SQLiteConstraintException e) {
+ String msg = "Constraint violation when inserting a word: '" + dbWord.word + "' / sequence: '" + dbWord.sequence + "', for language: " + dbWord.langId
+ + ". " + e.getMessage();
+ Logger.e("tt9/insertWord", msg);
+ statusHandler.accept(1);
+ } catch (Exception e) {
+ String msg = "Failed inserting word: '" + dbWord.word + "' / sequence: '" + dbWord.sequence + "', for language: " + dbWord.langId + ". " + e.getMessage();
+ Logger.e("tt9/insertWord", msg);
+ statusHandler.accept(2);
}
- ).start();
+ }).start();
}
@@ -207,38 +186,37 @@ public class DictionaryDb {
}
new Thread(() -> {
- try {
- int affectedRows = getInstance().wordsDao().incrementFrequency(language.getId(), word, sequence);
+ try {
+ int affectedRows = getInstance().wordsDao().incrementFrequency(language.getId(), word, sequence);
- // In case the user has changed the text case, there would be no match.
- // Try again with the lowercase equivalent.
- String lowercaseWord = "";
- if (affectedRows == 0) {
- lowercaseWord = word.toLowerCase(language.getLocale());
- affectedRows = getInstance().wordsDao().incrementFrequency(language.getId(), lowercaseWord, sequence);
+ // In case the user has changed the text case, there would be no match.
+ // Try again with the lowercase equivalent.
+ String lowercaseWord = "";
+ if (affectedRows == 0) {
+ lowercaseWord = word.toLowerCase(language.getLocale());
+ affectedRows = getInstance().wordsDao().incrementFrequency(language.getId(), lowercaseWord, sequence);
- Logger.d("incrementWordFrequency", "Attempting to increment frequency for lowercase variant: " + lowercaseWord);
- }
-
- // Some languages permit appending the punctuation to the end of the words, like so: "try,".
- // But there are no such words in the dictionary, so try without the punctuation mark.
- if (affectedRows == 0 && language.isPunctuationPartOfWords() && sequence.endsWith("1")) {
- String truncatedWord = lowercaseWord.substring(0, word.length() - 1);
- String truncatedSequence = sequence.substring(0, sequence.length() - 1);
- affectedRows = getInstance().wordsDao().incrementFrequency(language.getId(), truncatedWord, truncatedSequence);
-
- Logger.d("incrementWordFrequency", "Attempting to increment frequency with stripped punctuation: " + truncatedWord);
- }
-
- Logger.d("incrementWordFrequency", "Affected rows: " + affectedRows);
- } catch (Exception e) {
- Logger.e(
- DictionaryDb.class.getName(),
- "Failed incrementing word frequency. Word: " + word + " | Sequence: " + sequence + ". " + e.getMessage()
- );
+ Logger.d("incrementWordFrequency", "Attempting to increment frequency for lowercase variant: " + lowercaseWord);
}
+
+ // Some languages permit appending the punctuation to the end of the words, like so: "try,".
+ // But there are no such words in the dictionary, so try without the punctuation mark.
+ if (affectedRows == 0 && language.isPunctuationPartOfWords() && sequence.endsWith("1")) {
+ String truncatedWord = lowercaseWord.substring(0, word.length() - 1);
+ String truncatedSequence = sequence.substring(0, sequence.length() - 1);
+ affectedRows = getInstance().wordsDao().incrementFrequency(language.getId(), truncatedWord, truncatedSequence);
+
+ Logger.d("incrementWordFrequency", "Attempting to increment frequency with stripped punctuation: " + truncatedWord);
+ }
+
+ Logger.d("incrementWordFrequency", "Affected rows: " + affectedRows);
+ } catch (Exception e) {
+ Logger.e(
+ DictionaryDb.class.getName(),
+ "Failed incrementing word frequency. Word: " + word + " | Sequence: " + sequence + ". " + e.getMessage()
+ );
}
- ).start();
+ }).start();
}
@@ -320,14 +298,13 @@ public class DictionaryDb {
}
new Thread(() -> {
- wordList.addAll(loadWordsExact(language, sequence, filter, maxWords));
+ wordList.addAll(loadWordsExact(language, sequence, filter, maxWords));
- if (sequence.length() > 1 && wordList.size() < minWords) {
- wordList.addAll(loadWordsFuzzy(language, sequence, filter, minWords - wordList.size()));
- }
-
- sendWords(dataHandler, wordList);
+ if (sequence.length() > 1 && wordList.size() < minWords) {
+ wordList.addAll(loadWordsFuzzy(language, sequence, filter, minWords - wordList.size()));
}
- ).start();
+
+ sendWords(dataHandler, wordList);
+ }).start();
}
}
diff --git a/src/io/github/sspanak/tt9/db/DictionaryLoader.java b/src/io/github/sspanak/tt9/db/DictionaryLoader.java
index 7fc98fee..084eaa1f 100644
--- a/src/io/github/sspanak/tt9/db/DictionaryLoader.java
+++ b/src/io/github/sspanak/tt9/db/DictionaryLoader.java
@@ -47,7 +47,6 @@ public class DictionaryLoader {
}
-
public DictionaryLoader(Context context) {
assets = context.getAssets();
settings = new SettingsStore(context);
@@ -80,7 +79,7 @@ public class DictionaryLoader {
currentFile = 0;
importStartTime = System.currentTimeMillis();
- dropIndexes();
+ sendFileCount(languages.size());
// SQLite does not support parallel queries, so let's import them one by one
for (Language lang : languages) {
@@ -90,8 +89,6 @@ public class DictionaryLoader {
importAll(lang);
currentFile++;
}
-
- createIndexes();
}
};
@@ -168,28 +165,6 @@ public class DictionaryLoader {
}
- private void dropIndexes() {
- long start = System.currentTimeMillis();
- DictionaryDb.dropLongWordIndexSync();
- Logger.d("dropIndexes", "Index 1: " + (System.currentTimeMillis() - start) + " ms");
-
- start = System.currentTimeMillis();
- DictionaryDb.dropShortWordIndexSync();
- Logger.d("dropIndexes", "Index 2: " + (System.currentTimeMillis() - start) + " ms");
- }
-
-
- private void createIndexes() {
- long start = System.currentTimeMillis();
- DictionaryDb.createLongWordIndexSync();
- Logger.d("createIndexes", "Index 1: " + (System.currentTimeMillis() - start) + " ms");
-
- start = System.currentTimeMillis();
- DictionaryDb.createShortWordIndexSync();
- Logger.d("createIndexes", "Index 2: " + (System.currentTimeMillis() - start) + " ms");
- }
-
-
private void importLetters(Language language) {
ArrayList letters = new ArrayList<>();
@@ -315,6 +290,20 @@ public class DictionaryLoader {
}
+ private void sendFileCount(int fileCount) {
+ if (onStatusChange == null) {
+ Logger.w(
+ "tt9/DictionaryLoader.sendFileCount",
+ "Cannot send file count without a status Handler. Ignoring message.");
+ return;
+ }
+
+ Bundle progressMsg = new Bundle();
+ progressMsg.putInt("fileCount", fileCount);
+ asyncHandler.post(() -> onStatusChange.accept(progressMsg));
+ }
+
+
private void sendProgressMessage(Language language, int progress, int progressUpdateInterval) {
if (onStatusChange == null) {
Logger.w(
diff --git a/src/io/github/sspanak/tt9/db/migrations/DB10.java b/src/io/github/sspanak/tt9/db/migrations/DB10.java
new file mode 100644
index 00000000..4540c474
--- /dev/null
+++ b/src/io/github/sspanak/tt9/db/migrations/DB10.java
@@ -0,0 +1,26 @@
+package io.github.sspanak.tt9.db.migrations;
+
+import androidx.annotation.NonNull;
+import androidx.room.migration.Migration;
+import androidx.sqlite.db.SupportSQLiteDatabase;
+
+import io.github.sspanak.tt9.Logger;
+import io.github.sspanak.tt9.db.room.TT9Room;
+
+public class DB10 {
+ public static final Migration MIGRATION = new Migration(9, 10) {
+ @Override
+ public void migrate(@NonNull SupportSQLiteDatabase database) {
+ try {
+ database.beginTransaction();
+ database.execSQL(TT9Room.createShortWordsIndexQuery().getSql());
+ database.execSQL(TT9Room.createLongWordsIndexQuery().getSql());
+ database.setTransactionSuccessful();
+ } catch (Exception e) {
+ Logger.e("Migrate to DB10", "Migration failed. " + e.getMessage());
+ } finally {
+ database.endTransaction();
+ }
+ }
+ };
+}
diff --git a/src/io/github/sspanak/tt9/db/room/TT9Room.java b/src/io/github/sspanak/tt9/db/room/TT9Room.java
index dfe7d01c..3b257153 100644
--- a/src/io/github/sspanak/tt9/db/room/TT9Room.java
+++ b/src/io/github/sspanak/tt9/db/room/TT9Room.java
@@ -7,12 +7,13 @@ import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SimpleSQLiteQuery;
+import io.github.sspanak.tt9.db.migrations.DB10;
import io.github.sspanak.tt9.db.migrations.DB6;
import io.github.sspanak.tt9.db.migrations.DB7;
import io.github.sspanak.tt9.db.migrations.DB8;
import io.github.sspanak.tt9.db.migrations.DB9;
-@Database(version = 9, entities = Word.class, exportSchema = false)
+@Database(version = 10, entities = Word.class, exportSchema = false)
public abstract class TT9Room extends RoomDatabase {
public abstract WordsDao wordsDao();
@@ -23,7 +24,8 @@ public abstract class TT9Room extends RoomDatabase {
DB6.MIGRATION,
new DB7().getMigration(context),
DB8.MIGRATION,
- DB9.MIGRATION
+ DB9.MIGRATION,
+ DB10.MIGRATION
)
.build();
}
@@ -50,18 +52,10 @@ public abstract class TT9Room extends RoomDatabase {
}
public static SimpleSQLiteQuery createShortWordsIndexQuery() {
- return new SimpleSQLiteQuery("CREATE INDEX " + WordsDao.indexShortWords + " ON words (lang ASC, len ASC, seq ASC)");
+ return new SimpleSQLiteQuery("CREATE INDEX IF NOT EXISTS " + WordsDao.indexShortWords + " ON words (lang ASC, len ASC, seq ASC)");
}
public static SimpleSQLiteQuery createLongWordsIndexQuery() {
- return new SimpleSQLiteQuery("CREATE INDEX " + WordsDao.indexLongWords + " ON words (lang ASC, seq ASC, freq DESC)");
- }
-
- public static SimpleSQLiteQuery dropShortWordsIndexQuery() {
- return new SimpleSQLiteQuery("DROP INDEX IF EXISTS " + WordsDao.indexShortWords);
- }
-
- public static SimpleSQLiteQuery dropLongWordsIndexQuery() {
- return new SimpleSQLiteQuery("DROP INDEX IF EXISTS " + WordsDao.indexLongWords);
+ return new SimpleSQLiteQuery("CREATE INDEX IF NOT EXISTS " + WordsDao.indexLongWords + " ON words (lang ASC, seq ASC, freq DESC)");
}
}
diff --git a/src/io/github/sspanak/tt9/db/room/WordList.java b/src/io/github/sspanak/tt9/db/room/WordList.java
index c8b972a2..397c7505 100644
--- a/src/io/github/sspanak/tt9/db/room/WordList.java
+++ b/src/io/github/sspanak/tt9/db/room/WordList.java
@@ -6,10 +6,6 @@ import java.util.ArrayList;
import java.util.List;
public class WordList extends ArrayList {
- public WordList() {
- super();
- }
-
public WordList(List words) {
addAll(words);
}
diff --git a/src/io/github/sspanak/tt9/db/room/WordsDao.java b/src/io/github/sspanak/tt9/db/room/WordsDao.java
index 35feafc5..7504b234 100644
--- a/src/io/github/sspanak/tt9/db/room/WordsDao.java
+++ b/src/io/github/sspanak/tt9/db/room/WordsDao.java
@@ -15,9 +15,6 @@ public interface WordsDao {
String indexLongWords = "index_words_lang_seq_freq";
String indexShortWords = "index_words_lang_len_seq";
- @RawQuery()
- Object rawQuery(SimpleSQLiteQuery sql);
-
@Query("SELECT COUNT(id) FROM words WHERE :langId < 0 OR lang = :langId")
int count(int langId);
diff --git a/src/io/github/sspanak/tt9/preferences/items/ItemClickable.java b/src/io/github/sspanak/tt9/preferences/items/ItemClickable.java
index 9a2fec07..38620dde 100644
--- a/src/io/github/sspanak/tt9/preferences/items/ItemClickable.java
+++ b/src/io/github/sspanak/tt9/preferences/items/ItemClickable.java
@@ -16,6 +16,16 @@ abstract class ItemClickable {
}
+ public void disable() {
+ item.setEnabled(false);
+ }
+
+
+ public void enable() {
+ item.setEnabled(true);
+ }
+
+
public void enableClickHandler() {
item.setOnPreferenceClickListener(this::debounceClick);
}
diff --git a/src/io/github/sspanak/tt9/preferences/items/ItemLoadDictionary.java b/src/io/github/sspanak/tt9/preferences/items/ItemLoadDictionary.java
index ffdcaed9..9225a986 100644
--- a/src/io/github/sspanak/tt9/preferences/items/ItemLoadDictionary.java
+++ b/src/io/github/sspanak/tt9/preferences/items/ItemLoadDictionary.java
@@ -63,7 +63,6 @@ public class ItemLoadDictionary extends ItemClickable {
@Override
protected boolean onClick(Preference p) {
ArrayList languages = LanguageCollection.getAll(settings.getEnabledLanguageIds());
- progressBar.setFileCount(languages.size());
try {
loader.load(languages);
diff --git a/src/io/github/sspanak/tt9/preferences/items/ItemTruncateAll.java b/src/io/github/sspanak/tt9/preferences/items/ItemTruncateAll.java
index b7949c5a..c8a14e20 100644
--- a/src/io/github/sspanak/tt9/preferences/items/ItemTruncateAll.java
+++ b/src/io/github/sspanak/tt9/preferences/items/ItemTruncateAll.java
@@ -1,31 +1,36 @@
package io.github.sspanak.tt9.preferences.items;
-import android.content.Context;
-
import androidx.preference.Preference;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.db.DictionaryDb;
import io.github.sspanak.tt9.db.DictionaryLoader;
+import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.ui.UI;
public class ItemTruncateAll extends ItemClickable {
public static final String NAME = "dictionary_truncate";
- private final Context context;
- private final DictionaryLoader loader;
- private final ItemLoadDictionary loadItem;
+ protected final PreferencesActivity activity;
+ protected final DictionaryLoader loader;
+ protected final ItemLoadDictionary loadItem;
+ protected ItemClickable otherTruncateItem;
-
- public ItemTruncateAll(Preference item, ItemLoadDictionary loadItem, Context context, DictionaryLoader loader) {
+ public ItemTruncateAll(Preference item, ItemLoadDictionary loadItem, PreferencesActivity activity, DictionaryLoader loader) {
super(item);
- this.context = context;
+ this.activity = activity;
this.loadItem = loadItem;
this.loader = loader;
}
+ public ItemTruncateAll setOtherTruncateItem(ItemTruncateUnselected item) {
+ this.otherTruncateItem = item;
+ return this;
+ }
+
+
@Override
protected boolean onClick(Preference p) {
if (loader != null && loader.isRunning()) {
@@ -33,8 +38,32 @@ public class ItemTruncateAll extends ItemClickable {
loadItem.changeToLoadButton();
}
- DictionaryDb.deleteWords(() -> UI.toastFromAsync(context, R.string.dictionary_truncated));
+ onStartDeleting();
+ DictionaryDb.deleteWords(this::onFinishDeleting);
return true;
}
+
+
+ protected void onStartDeleting() {
+ if (otherTruncateItem != null) {
+ otherTruncateItem.disable();
+ }
+ loadItem.disable();
+ disable();
+ item.setSummary(R.string.dictionary_truncating);
+ }
+
+
+ protected void onFinishDeleting() {
+ activity.runOnUiThread(() -> {
+ if (otherTruncateItem != null) {
+ otherTruncateItem.enable();
+ }
+ loadItem.enable();
+ item.setSummary("");
+ enable();
+ UI.toastFromAsync(activity, R.string.dictionary_truncated);
+ });
+ }
}
diff --git a/src/io/github/sspanak/tt9/preferences/items/ItemTruncateUnselected.java b/src/io/github/sspanak/tt9/preferences/items/ItemTruncateUnselected.java
index 37fd717d..cd94ef33 100644
--- a/src/io/github/sspanak/tt9/preferences/items/ItemTruncateUnselected.java
+++ b/src/io/github/sspanak/tt9/preferences/items/ItemTruncateUnselected.java
@@ -1,35 +1,32 @@
package io.github.sspanak.tt9.preferences.items;
-import android.content.Context;
-
import androidx.preference.Preference;
import java.util.ArrayList;
-import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.db.DictionaryDb;
import io.github.sspanak.tt9.db.DictionaryLoader;
import io.github.sspanak.tt9.languages.Language;
import io.github.sspanak.tt9.languages.LanguageCollection;
+import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.preferences.SettingsStore;
-import io.github.sspanak.tt9.ui.UI;
-public class ItemTruncateUnselected extends ItemClickable {
+public class ItemTruncateUnselected extends ItemTruncateAll {
public static final String NAME = "dictionary_truncate_unselected";
- private final Context context;
- private final DictionaryLoader loader;
- private final ItemLoadDictionary loadItem;
private final SettingsStore settings;
- public ItemTruncateUnselected(Preference item, ItemLoadDictionary loadItem, Context context, SettingsStore settings, DictionaryLoader loader) {
- super(item);
- this.context = context;
- this.loadItem = loadItem;
+ public ItemTruncateUnselected(Preference item, ItemLoadDictionary loadItem, PreferencesActivity context, SettingsStore settings, DictionaryLoader loader) {
+ super(item, loadItem, context, loader);
this.settings = settings;
- this.loader = loader;
+ }
+
+
+ public ItemTruncateUnselected setOtherTruncateItem(ItemTruncateAll otherTruncateItem) {
+ this.otherTruncateItem = otherTruncateItem;
+ return this;
}
@@ -48,10 +45,8 @@ public class ItemTruncateUnselected extends ItemClickable {
}
}
- DictionaryDb.deleteWords(
- () -> UI.toastFromAsync(context, R.string.dictionary_truncated),
- unselectedLanguageIds
- );
+ onStartDeleting();
+ DictionaryDb.deleteWords(this::onFinishDeleting, unselectedLanguageIds);
return true;
}
diff --git a/src/io/github/sspanak/tt9/preferences/screens/DictionariesScreen.java b/src/io/github/sspanak/tt9/preferences/screens/DictionariesScreen.java
index 157064c6..a22bee85 100644
--- a/src/io/github/sspanak/tt9/preferences/screens/DictionariesScreen.java
+++ b/src/io/github/sspanak/tt9/preferences/screens/DictionariesScreen.java
@@ -37,7 +37,6 @@ public class DictionariesScreen extends BaseScreenFragment {
activity,
activity.getDictionaryLoader()
);
- truncateItem.enableClickHandler();
ItemTruncateUnselected truncateSelectedItem = new ItemTruncateUnselected(
findPreference(ItemTruncateUnselected.NAME),
@@ -46,6 +45,8 @@ public class DictionariesScreen extends BaseScreenFragment {
activity.settings,
activity.getDictionaryLoader()
);
- truncateSelectedItem.enableClickHandler();
+
+ truncateItem.setOtherTruncateItem(truncateSelectedItem).enableClickHandler();
+ truncateSelectedItem.setOtherTruncateItem(truncateItem).enableClickHandler();
}
}
diff --git a/src/io/github/sspanak/tt9/ui/DictionaryLoadingBar.java b/src/io/github/sspanak/tt9/ui/DictionaryLoadingBar.java
index 7e9ce153..fdbd9e4f 100644
--- a/src/io/github/sspanak/tt9/ui/DictionaryLoadingBar.java
+++ b/src/io/github/sspanak/tt9/ui/DictionaryLoadingBar.java
@@ -105,6 +105,7 @@ public class DictionaryLoadingBar {
public void show(Bundle data) {
String error = data.getString("error", null);
+ int fileCount = data.getInt("fileCount", -1);
if (error != null) {
hasFailed = true;
@@ -114,7 +115,9 @@ public class DictionaryLoadingBar {
data.getLong("fileLine", -1),
data.getString("word", "")
);
- } else {
+ } else if (fileCount > -1) {
+ setFileCount(fileCount);
+ } else {
hasFailed = false;
showProgress(
data.getLong("time", 0),