Add persistence for user history dictionary

User history dictionary was not flushing to disk on close, added that logic so (unless there's a crash) the user history should be persisted.
This commit is contained in:
Trevor Terris 2021-05-05 13:30:30 -04:00 committed by Daniele Laudani
parent dd7b56fbb3
commit 206fc18ec3
3 changed files with 13 additions and 0 deletions

View file

@ -225,6 +225,7 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
@Override @Override
public void onFinishInput(Context context) { public void onFinishInput(Context context) {
flushDictionaries();
} }
@Override @Override
@ -459,6 +460,18 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
} }
} }
public void flushDictionaries() {
final DictionaryGroup dictionaryGroupToClose;
synchronized (mLock) {
dictionaryGroupToClose = mDictionaryGroup;
mDictionaryGroup = new DictionaryGroup();
}
for (final String dictType : ALL_DICTIONARY_TYPES) {
ExpandableBinaryDictionary dict = dictionaryGroupToClose.getSubDict(dictType);
if (dict != null) dict.asyncFlushBinaryDictionary();
}
}
@UsedForTesting @UsedForTesting
public ExpandableBinaryDictionary getSubDictForTesting(final String dictName) { public ExpandableBinaryDictionary getSubDictForTesting(final String dictName) {
return mDictionaryGroup.getSubDict(dictName); return mDictionaryGroup.getSubDict(dictName);

Binary file not shown.

BIN
dictionaries/en_wordlist.combined.gz Executable file → Normal file

Binary file not shown.