diff options
author | Jean Chalard <jchalard@google.com> | 2012-05-09 19:51:20 +0900 |
---|---|---|
committer | Jean Chalard <jchalard@google.com> | 2012-05-09 19:57:14 +0900 |
commit | 657beac9bb27d8c40b5193ecd49ec2c8d46f72bb (patch) | |
tree | e58f3a68056b46150f1d063ee75d6196d524d662 /src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java | |
parent | 1571c0a377f4aa94ef424da326a52fad638b3e54 (diff) |
Rework the de-duplication scheme for shortcuts.
Bug: 4646172
Change-Id: I88966f3e910f51711ce49336fb9134d0953930de
Diffstat (limited to 'src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java')
-rw-r--r-- | src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java index 95e031ed30..1e8bf74885 100644 --- a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java +++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java @@ -90,22 +90,38 @@ public class UserDictionaryAddWordContents { /* package */ void apply(final Context context) { final ContentResolver resolver = context.getContentResolver(); if (UserDictionaryAddWordContents.MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) { - UserDictionarySettings.deleteWord(mOldWord, resolver); + // Mode edit: remove the old entry. + UserDictionarySettings.deleteWord(mOldWord, mOldShortcut, resolver); } final String newWord = mWordEditText.getText().toString(); + final String newShortcut; + if (null == mShortcutEditText) { + newShortcut = null; + } else { + final String tmpShortcut = mShortcutEditText.getText().toString(); + if (TextUtils.isEmpty(tmpShortcut)) { + newShortcut = null; + } else { + newShortcut = tmpShortcut; + } + } if (TextUtils.isEmpty(newWord)) { // If the word is somehow empty, don't insert it. return; } - // Disallow duplicates. - // TODO: Redefine the logic when we support shortcuts. - UserDictionarySettings.deleteWord(newWord, resolver); + // Disallow duplicates. If the same word with no shortcut is defined, remove it; if + // the same word with the same shortcut is defined, remove it; but we don't mind if + // there is the same word with a different, non-empty shortcut. + UserDictionarySettings.deleteWord(newWord, null, resolver); + if (!TextUtils.isEmpty(newShortcut)) { + // If newShortcut is empty we just deleted this, no need to do it again + UserDictionarySettings.deleteWord(newWord, newShortcut, resolver); + } // In this class we use the empty string to represent 'all locales' and mLocale cannot // be null. However the addWord method takes null to mean 'all locales'. UserDictionary.Words.addWord(context, newWord.toString(), - FREQUENCY_FOR_USER_DICTIONARY_ADDS, - null == mShortcutEditText ? null : mShortcutEditText.getText().toString(), + FREQUENCY_FOR_USER_DICTIONARY_ADDS, newShortcut, TextUtils.isEmpty(mLocale) ? null : Utils.createLocaleFromString(mLocale)); } |