Factorize code (A87)
Why was this copy-pasted :(
Change-Id: I6a537c56425ad039d7301a5fe1e0485784f07914
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
index 05f3c0d..55a2577 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
@@ -249,12 +249,7 @@
@Override
public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
- synchronized (mUpdatingLock) {
- // If we need to update, start off a background task
- if (mRequiresReload) startDictionaryLoadingTaskLocked();
- // Currently updating contacts, don't return any results.
- if (mUpdatingDictionary) return null;
- }
+ if (reloadDictionaryIfRequired()) return null;
if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) {
return null;
}
@@ -263,12 +258,13 @@
return suggestions;
}
+ // This reloads the dictionary if required, and returns whether it's currently updating its
+ // contents or not.
// @VisibleForTesting
boolean reloadDictionaryIfRequired() {
synchronized (mUpdatingLock) {
// If we need to update, start off a background task
if (mRequiresReload) startDictionaryLoadingTaskLocked();
- // Currently updating contacts, don't return any results.
return mUpdatingDictionary;
}
}
@@ -276,12 +272,10 @@
@Override
public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes,
final CharSequence previousWord) {
- if (!reloadDictionaryIfRequired()) {
- final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
- runBigramReverseLookUp(previousWord, suggestions);
- return suggestions;
- }
- return null;
+ if (reloadDictionaryIfRequired()) return null;
+ final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
+ runBigramReverseLookUp(previousWord, suggestions);
+ return suggestions;
}
protected final ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,