Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5031683a authored by Jean Chalard's avatar Jean Chalard Committed by Android Git Automerger
Browse files

am d0a9d5b6: am a374d816: Distinguish adding an already present word / cancelling

* commit 'd0a9d5b6':
  Distinguish adding an already present word / cancelling
parents aca1bb4a d0a9d5b6
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -33,8 +33,9 @@ public class UserDictionaryAddWordActivity extends Activity {
    public static final String MODE_EDIT_ACTION = "com.android.settings.USER_DICTIONARY_EDIT";
    public static final String MODE_INSERT_ACTION = "com.android.settings.USER_DICTIONARY_INSERT";

    private static final int CODE_WORD_ADDED = 0;
    private static final int CODE_CANCEL = 1;
    /* package */ static final int CODE_WORD_ADDED = 0;
    /* package */ static final int CODE_CANCEL = 1;
    /* package */ static final int CODE_ALREADY_PRESENT = 2;

    private UserDictionaryAddWordContents mContents;

@@ -73,7 +74,7 @@ public class UserDictionaryAddWordActivity extends Activity {
        mContents.saveStateIntoBundle(outState);
    }

    private void reportBackToCaller(final Bundle result) {
    private void reportBackToCaller(final int resultCode, final Bundle result) {
        final Intent senderIntent = getIntent();
        final Object listener = senderIntent.getExtras().get("listener");
        if (!(listener instanceof Messenger)) return; // This will work if listener is null too.
@@ -81,7 +82,7 @@ public class UserDictionaryAddWordActivity extends Activity {

        final Message m = Message.obtain();
        m.obj = result;
        m.what = (null != result) ? CODE_WORD_ADDED : CODE_CANCEL;
        m.what = resultCode;
        try {
            messenger.send(m);
        } catch (RemoteException e) {
@@ -90,12 +91,14 @@ public class UserDictionaryAddWordActivity extends Activity {
    }

    public void onClickCancel(final View v) {
        reportBackToCaller(null);
        reportBackToCaller(CODE_CANCEL, null);
        finish();
    }

    public void onClickConfirm(final View v) {
        reportBackToCaller(mContents.apply(this));
        final Bundle parameters = new Bundle();
        final int resultCode = mContents.apply(this, parameters);
        reportBackToCaller(resultCode, parameters);
        finish();
    }
}
+5 −6
Original line number Diff line number Diff line
@@ -103,7 +103,8 @@ public class UserDictionaryAddWordContents {
        // If we are in add mode, nothing was added, so we don't need to do anything.
    }

    /* package */ Bundle apply(final Context context) {
    /* package */ int apply(final Context context, final Bundle outParameters) {
        if (null != outParameters) saveStateIntoBundle(outParameters);
        final ContentResolver resolver = context.getContentResolver();
        if (MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) {
            // Mode edit: remove the old entry.
@@ -123,13 +124,13 @@ public class UserDictionaryAddWordContents {
        }
        if (TextUtils.isEmpty(newWord)) {
            // If the word is somehow empty, don't insert it.
            return null;
            return UserDictionaryAddWordActivity.CODE_CANCEL;
        }
        // If there is no shortcut, and the word already exists in the database, then we
        // should not insert, because either A. the word exists with no shortcut, in which
        // case the exact same thing we want to insert is already there, or B. the word
        // exists with at least one shortcut, in which case it has priority on our word.
        if (hasWord(newWord, context)) return null;
        if (hasWord(newWord, context)) return UserDictionaryAddWordActivity.CODE_ALREADY_PRESENT;

        // 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
@@ -146,9 +147,7 @@ public class UserDictionaryAddWordContents {
                FREQUENCY_FOR_USER_DICTIONARY_ADDS, newShortcut,
                TextUtils.isEmpty(mLocale) ? null : Utils.createLocaleFromString(mLocale));

        final Bundle returnValues = new Bundle();
        saveStateIntoBundle(returnValues);
        return returnValues;
        return UserDictionaryAddWordActivity.CODE_WORD_ADDED;
    }

    private static final String[] HAS_WORD_PROJECTION = { UserDictionary.Words.WORD };
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class UserDictionaryAddWordFragment extends Fragment
        super.onPause();
        // We are being hidden: commit changes to the user dictionary, unless we were deleting it
        if (!mIsDeleting) {
            mContents.apply(getActivity());
            mContents.apply(getActivity(), null);
        }
    }