Refactor logic to retrieve relevant suggestions a bit

Change-Id: Ic7d2cbb2c1b2deaa4e735484bdc7413c0b3b1939
main
Tadashi G. Takaoka 2014-01-20 12:06:44 +09:00
parent 3f3b0af5b7
commit 3033cc51b8
2 changed files with 18 additions and 23 deletions

View File

@ -1407,7 +1407,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO[IL]: Move this to InputLogic // TODO[IL]: Move this to InputLogic
public SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, public SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
final SuggestedWords suggestedWords) { final SuggestedWords suggestedWords, final SuggestedWords previousSuggestedWords) {
// TODO: consolidate this into getSuggestedWords // TODO: consolidate this into getSuggestedWords
// We update the suggestion strip only when we have some suggestions to show, i.e. when // We update the suggestion strip only when we have some suggestions to show, i.e. when
// the suggestion count is > 1; else, we leave the old suggestions, with the typed word // the suggestion count is > 1; else, we leave the old suggestions, with the typed word
@ -1420,22 +1420,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|| mSuggestionStripView.isShowingAddToDictionaryHint()) { || mSuggestionStripView.isShowingAddToDictionaryHint()) {
return suggestedWords; return suggestedWords;
} else { } else {
return getOlderSuggestions(typedWord); final SuggestedWords punctuationList =
} mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList;
} final SuggestedWords oldSuggestedWords = previousSuggestedWords == punctuationList
? SuggestedWords.EMPTY : previousSuggestedWords;
private SuggestedWords getOlderSuggestions(final String typedWord) { if (TextUtils.isEmpty(typedWord)) {
SuggestedWords previousSuggestedWords = mInputLogic.mSuggestedWords; return oldSuggestedWords;
if (previousSuggestedWords
== mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList) {
previousSuggestedWords = SuggestedWords.EMPTY;
}
if (typedWord == null) {
return previousSuggestedWords;
} }
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
previousSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions, return new SuggestedWords(typedWordAndPreviousSuggestions,
false /* typedWordValid */, false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */, false /* hasAutoCorrectionCandidate */,
@ -1443,6 +1436,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
true /* isObsoleteSuggestions */, true /* isObsoleteSuggestions */,
false /* isPrediction */); false /* isPrediction */);
} }
}
private void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords, private void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
final String typedWord) { final String typedWord) {

View File

@ -1031,7 +1031,8 @@ public final class InputLogic {
public void onGetSuggestedWords(final SuggestedWords suggestedWords) { public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
final SuggestedWords suggestedWordsWithMaybeOlderSuggestions = final SuggestedWords suggestedWordsWithMaybeOlderSuggestions =
mLatinIME.maybeRetrieveOlderSuggestions( mLatinIME.maybeRetrieveOlderSuggestions(
mWordComposer.getTypedWord(), suggestedWords); mWordComposer.getTypedWord(), suggestedWords,
mSuggestedWords);
holder.set(suggestedWordsWithMaybeOlderSuggestions); holder.set(suggestedWordsWithMaybeOlderSuggestions);
} }
} }