the WordStore is now explicitly destroyed on shutdown (attempting to fix the Privileged options problem again)
This commit is contained in:
parent
da1ad98de8
commit
231f4e608e
3 changed files with 19 additions and 32 deletions
|
|
@ -26,13 +26,12 @@ import io.github.sspanak.tt9.util.Timer;
|
||||||
|
|
||||||
public class WordStore {
|
public class WordStore {
|
||||||
private final String LOG_TAG = "sqlite.WordStore";
|
private final String LOG_TAG = "sqlite.WordStore";
|
||||||
private static WordStore self;
|
|
||||||
|
|
||||||
private SQLiteOpener sqlite = null;
|
private SQLiteOpener sqlite = null;
|
||||||
private ReadOps readOps = null;
|
private ReadOps readOps = null;
|
||||||
|
|
||||||
|
|
||||||
private WordStore(@NonNull Context context) {
|
WordStore(@NonNull Context context) {
|
||||||
try {
|
try {
|
||||||
sqlite = SQLiteOpener.getInstance(context);
|
sqlite = SQLiteOpener.getInstance(context);
|
||||||
sqlite.getDb();
|
sqlite.getDb();
|
||||||
|
|
@ -40,16 +39,6 @@ public class WordStore {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.w(LOG_TAG, "Database connection failure. All operations will return empty results. " + e.getMessage());
|
Logger.w(LOG_TAG, "Database connection failure. All operations will return empty results. " + e.getMessage());
|
||||||
}
|
}
|
||||||
self = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static synchronized WordStore getInstance(@NonNull Context context) {
|
|
||||||
if (self == null) {
|
|
||||||
self = new WordStore(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,35 +15,32 @@ public class WordStoreAsync {
|
||||||
private static WordStore store;
|
private static WordStore store;
|
||||||
private static final Handler asyncHandler = new Handler();
|
private static final Handler asyncHandler = new Handler();
|
||||||
|
|
||||||
public static synchronized void init(Context context) {
|
|
||||||
store = WordStore.getInstance(context);
|
public static void init(Context context) {
|
||||||
|
store = new WordStore(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static synchronized void init() {
|
public static void destroy() {
|
||||||
init(null);
|
if (store != null) {
|
||||||
}
|
store = null;
|
||||||
|
}
|
||||||
|
|
||||||
private static WordStore getStore() {
|
|
||||||
init();
|
|
||||||
return store;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void normalizeNext() {
|
public static void normalizeNext() {
|
||||||
new Thread(() -> getStore().normalizeNext()).start();
|
new Thread(() -> store.normalizeNext()).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void getLastLanguageUpdateTime(ConsumerCompat<String> notification, Language language) {
|
public static void getLastLanguageUpdateTime(ConsumerCompat<String> notification, Language language) {
|
||||||
new Thread(() -> notification.accept(getStore().getLanguageFileHash(language))).start();
|
new Thread(() -> notification.accept(store.getLanguageFileHash(language))).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void deleteCustomWord(Runnable notification, Language language, String word) {
|
public static void deleteCustomWord(Runnable notification, Language language, String word) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
getStore().removeCustomWord(language, word);
|
store.removeCustomWord(language, word);
|
||||||
notification.run();
|
notification.run();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
@ -51,46 +48,46 @@ public class WordStoreAsync {
|
||||||
|
|
||||||
public static void deleteWords(Runnable notification, @NonNull ArrayList<Integer> languageIds) {
|
public static void deleteWords(Runnable notification, @NonNull ArrayList<Integer> languageIds) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
getStore().remove(languageIds);
|
store.remove(languageIds);
|
||||||
notification.run();
|
notification.run();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void put(ConsumerCompat<AddWordResult> statusHandler, Language language, String word) {
|
public static void put(ConsumerCompat<AddWordResult> statusHandler, Language language, String word) {
|
||||||
new Thread(() -> statusHandler.accept(getStore().put(language, word))).start();
|
new Thread(() -> statusHandler.accept(store.put(language, word))).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void makeTopWord(@NonNull Language language, @NonNull String word, @NonNull String sequence) {
|
public static void makeTopWord(@NonNull Language language, @NonNull String word, @NonNull String sequence) {
|
||||||
new Thread(() -> getStore().makeTopWord(language, word, sequence)).start();
|
new Thread(() -> store.makeTopWord(language, word, sequence)).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void getWords(ConsumerCompat<ArrayList<String>> dataHandler, Language language, String sequence, String filter, int minWords, int maxWords) {
|
public static void getWords(ConsumerCompat<ArrayList<String>> dataHandler, Language language, String sequence, String filter, int minWords, int maxWords) {
|
||||||
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
||||||
getStore().getSimilar(language, sequence, filter, minWords, maxWords)))
|
store.getSimilar(language, sequence, filter, minWords, maxWords)))
|
||||||
).start();
|
).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void getCustomWords(ConsumerCompat<ArrayList<String>> dataHandler, String wordFilter, int maxWords) {
|
public static void getCustomWords(ConsumerCompat<ArrayList<String>> dataHandler, String wordFilter, int maxWords) {
|
||||||
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
||||||
getStore().getSimilarCustom(wordFilter, maxWords)))
|
store.getSimilarCustom(wordFilter, maxWords)))
|
||||||
).start();
|
).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void countCustomWords(ConsumerCompat<Long> dataHandler) {
|
public static void countCustomWords(ConsumerCompat<Long> dataHandler) {
|
||||||
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
||||||
getStore().countCustom()))
|
store.countCustom()))
|
||||||
).start();
|
).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void exists(ConsumerCompat<ArrayList<Integer>> dataHandler, ArrayList<Language> languages) {
|
public static void exists(ConsumerCompat<ArrayList<Integer>> dataHandler, ArrayList<Language> languages) {
|
||||||
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
new Thread(() -> asyncHandler.post(() -> dataHandler.accept(
|
||||||
getStore().exists(languages))
|
store.exists(languages))
|
||||||
)).start();
|
)).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,7 @@ public class TraditionalT9 extends MainViewHandler {
|
||||||
requestHideSelf(0);
|
requestHideSelf(0);
|
||||||
onStop();
|
onStop();
|
||||||
normalizationHandler.removeCallbacksAndMessages(null);
|
normalizationHandler.removeCallbacksAndMessages(null);
|
||||||
|
WordStoreAsync.destroy();
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue