mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-23 15:49:09 +00:00
Use onFinishInput to flush dictionary state
This commit is contained in:
parent
206fc18ec3
commit
ddbed48ce9
4 changed files with 11 additions and 22 deletions
|
@ -160,6 +160,10 @@ public abstract class Dictionary {
|
|||
// empty base implementation
|
||||
}
|
||||
|
||||
public void onFinishInput() {
|
||||
//empty base implementation
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses may override to indicate that this Dictionary is not yet properly initialized.
|
||||
*/
|
||||
|
|
|
@ -225,7 +225,10 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator {
|
|||
|
||||
@Override
|
||||
public void onFinishInput(Context context) {
|
||||
flushDictionaries();
|
||||
for (final String dictType : ALL_DICTIONARY_TYPES) {
|
||||
Dictionary dict = mDictionaryGroup.getDict(dictType);
|
||||
if (dict != null) dict.onFinishInput();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -460,18 +463,6 @@ 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
|
||||
public ExpandableBinaryDictionary getSubDictForTesting(final String dictName) {
|
||||
return mDictionaryGroup.getSubDict(dictName);
|
||||
|
|
|
@ -632,7 +632,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
/**
|
||||
* Flush binary dictionary to dictionary file.
|
||||
*/
|
||||
public void asyncFlushBinaryDictionary() {
|
||||
@Override
|
||||
public void onFinishInput() {
|
||||
asyncExecuteTaskWithWriteLock(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -641,7 +642,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
|
|||
return;
|
||||
}
|
||||
if (binaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) {
|
||||
binaryDictionary.flushWithGC();
|
||||
binaryDictionary.flushWithGCIfHasUpdated();
|
||||
} else {
|
||||
binaryDictionary.flush();
|
||||
}
|
||||
|
|
|
@ -86,13 +86,6 @@ public class UserHistoryDictionary extends ExpandableBinaryDictionary {
|
|||
isValid, 1 /* count */, timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Flush pending writes.
|
||||
asyncFlushBinaryDictionary();
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getHeaderAttributeMap() {
|
||||
final Map<String, String> attributeMap = super.getHeaderAttributeMap();
|
||||
|
|
Loading…
Add table
Reference in a new issue