Fix a code path that looks ridiculous

Bug: 12295276
Change-Id: I187016b59213d351c943c6e0b9a2ad3708499646
This commit is contained in:
Jean Chalard 2013-12-26 22:24:59 +09:00
parent be147f1fdc
commit f294ed3308
2 changed files with 12 additions and 12 deletions

View file

@ -274,10 +274,10 @@ public class DictionaryFacilitatorForSuggest {
mUserDictionary.addWordToUserDictionary(word);
}
public String addToUserHistory(final WordComposer wordComposer, final String previousWord,
public void addToUserHistory(final WordComposer wordComposer, final String previousWord,
final String suggestion) {
if (mUserHistoryDictionary == null) {
return null;
return;
}
final String secondWord;
if (wordComposer.wasAutoCapitalized() && !wordComposer.isMostlyCaps()) {
@ -289,12 +289,11 @@ public class DictionaryFacilitatorForSuggest {
// We don't add words with 0-frequency (assuming they would be profanity etc.).
final int maxFreq = getMaxFrequency(suggestion);
if (maxFreq == 0) {
return null;
return;
}
final boolean isValid = maxFreq > 0;
final int timeStamp = (int)TimeUnit.MILLISECONDS.toSeconds((System.currentTimeMillis()));
mUserHistoryDictionary.addToDictionary(previousWord, secondWord, isValid, timeStamp);
return previousWord;
}
public void cancelAddingUserHistory(final String previousWord, final String committedWord) {

View file

@ -974,19 +974,18 @@ public final class InputLogic {
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
}
private String performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
final String suggestion) {
private void performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
final String suggestion, final String prevWord) {
// If correction is not enabled, we don't add words to the user history dictionary.
// That's to avoid unintended additions in some sensitive fields, or fields that
// expect to receive non-words.
if (!settingsValues.mCorrectionEnabled) return null;
if (!settingsValues.mCorrectionEnabled) return;
if (TextUtils.isEmpty(suggestion)) return null;
if (TextUtils.isEmpty(suggestion)) return;
final Suggest suggest = mSuggest;
if (suggest == null) return null;
if (suggest == null) return;
final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2);
return suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
}
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
@ -1605,8 +1604,10 @@ public final class InputLogic {
final SuggestedWords suggestedWords = mSuggestedWords;
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord,
suggestedWords), 1);
// TODO: we pass 2 here, but would it be better to move this above and pass 1 instead?
final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2);
// Add the word to the user history dictionary
final String prevWord = performAdditionToUserHistoryDictionary(settingsValues, chosenWord);
performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWord);
// TODO: figure out here if this is an auto-correct or if the best word is actually
// what user typed. Note: currently this is done much later in
// LastComposedWord#didCommitTypedWord by string equality of the remembered