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

Commit 5c3a0a14 authored by Katherine Kuan's avatar Katherine Kuan
Browse files

Fix wrong contact being selected after editing (after a search)

- The problem is that after finding a contact via search
and editing that contact, we launch a VIEW intent to view
the contact. Then sometimes, that contact is not in the
current contact filter, so we may have to enter single contact
mode.

To avoid that, go back to the HC functionality of preserving
search mode. Now after editing, we return to the PeopleActivity
and preserve search mode if that's where we came from.
This was the relevant change from early ICS that is being
partially reverted:
Ibbaaccb03ac7961784dfa7b15c246b8d6f6489a4

The reason it was changed was to support viewing the contact
after editing a contact when the edit request came from a 3rd
party app. This still works with this change by adding
an intent extra in ContactEditorActivity.

- After the editing is done, only launch the VIEW intent
for the contact if we didn't come from the detail page for
that contact (on phone and tablet). We can just finish
the editor activity. This saves some time with setup / configuring
fragments because we don't have to resolve the VIEW intent
(i.e. On tablet, previously the VIEW intent launched the
ContactDetailActivity --> redirected to PeopleActivity -->
resolved intent to show the right contact.
Now we can just receive the onActivityResult and refresh
the page).

- Renamed ContactDetailActivity intent key to be consistent

Bug: 5542197
Change-Id: Ieaa9c147beeaa7c40f34fc1689858642b47fdbf9
parent 183c6fec
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -374,6 +374,18 @@ public class ActionBarAdapter implements OnQueryTextListener, OnCloseListener {
        outState.putInt(EXTRA_KEY_SELECTED_TAB, mCurrentTab.ordinal());
    }

    /**
     * Clears the focus from the {@link SearchView} if we are in search mode.
     * This will suppress the IME if it is visible.
     */
    public void clearFocusOnSearchView() {
        if (isSearchMode()) {
            if (mSearchView != null) {
                mSearchView.clearFocus();
            }
        }
    }

    private void setFocusOnSearchView() {
        mSearchView.requestFocus();
        mSearchView.setIconified(false); // Workaround for the "IME not popping up" issue.
+16 −10
Original line number Diff line number Diff line
@@ -57,15 +57,16 @@ public class ContactDetailActivity extends ContactsActivity {
    private static final String TAG = "ContactDetailActivity";

    /**
     * Intent key for a boolean that specifies whether the "up" afforance in this activity should
     * behave as default (return user back to {@link PeopleActivity}) or whether the activity should
     * instead be finished.
     * Boolean intent key that specifies whether pressing the "up" affordance in this activity
     * should cause it to finish itself or launch an intent to bring the user back to a specific
     * parent activity - the {@link PeopleActivity}.
     */
    public static final String INTENT_KEY_IGNORE_DEFAULT_UP_BEHAVIOR = "ignoreDefaultUpBehavior";
    public static final String INTENT_KEY_FINISH_ACTIVITY_ON_UP_SELECTED =
            "finishActivityOnUpSelected";

    private ContactLoader.Result mContactData;
    private Uri mLookupUri;
    private boolean mIgnoreDefaultUpBehavior;
    private boolean mFinishActivityOnUpSelected;

    private ContactDetailLayoutController mContactDetailLayoutController;
    private ContactLoaderFragment mLoaderFragment;
@@ -92,8 +93,8 @@ public class ContactDetailActivity extends ContactsActivity {
            return;
        }

        mIgnoreDefaultUpBehavior = getIntent().getBooleanExtra(
                INTENT_KEY_IGNORE_DEFAULT_UP_BEHAVIOR, false);
        mFinishActivityOnUpSelected = getIntent().getBooleanExtra(
                INTENT_KEY_FINISH_ACTIVITY_ON_UP_SELECTED, false);

        setContentView(R.layout.contact_detail_activity);

@@ -211,8 +212,13 @@ public class ContactDetailActivity extends ContactsActivity {

        @Override
        public void onEditRequested(Uri contactLookupUri) {
            startActivity(new Intent(Intent.ACTION_EDIT, contactLookupUri));
            finish();
            Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
            intent.putExtra(
                    ContactEditorActivity.INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);
            // Don't finish the detail activity after launching the editor because when the
            // editor is done, we will still want to show the updated contact details using
            // this activity.
            startActivity(intent);
        }

        @Override
@@ -285,7 +291,7 @@ public class ContactDetailActivity extends ContactsActivity {

        switch (item.getItemId()) {
            case android.R.id.home:
                if (mIgnoreDefaultUpBehavior) {
                if (mFinishActivityOnUpSelected) {
                    finish();
                    return true;
                }
+21 −2
Original line number Diff line number Diff line
@@ -50,14 +50,31 @@ public class ContactEditorActivity extends ContactsActivity
    public static final String ACTION_JOIN_COMPLETED = "joinCompleted";
    public static final String ACTION_SAVE_COMPLETED = "saveCompleted";

    /**
     * Boolean intent key that specifies that this activity should finish itself
     * (instead of launching a new view intent) after the editor changes have been
     * saved.
     */
    public static final String INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED =
            "finishActivityOnSaveCompleted";

    private ContactEditorFragment mFragment;
    private boolean mFinishActivityOnSaveCompleted;

    private DialogManager mDialogManager = new DialogManager(this);

    @Override
    public void onCreate(Bundle savedState) {
        super.onCreate(savedState);
        String action = getIntent().getAction();

        final Intent intent = getIntent();
        final String action = intent.getAction();

        // Determine whether or not this activity should be finished after the user is done
        // editing the contact or if this activity should launch another activity to view the
        // contact's details.
        mFinishActivityOnSaveCompleted = intent.getBooleanExtra(
                INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, false);

        // The only situation where action could be ACTION_JOIN_COMPLETED is if the
        // user joined the contact with another and closed the activity before
@@ -146,7 +163,9 @@ public class ContactEditorActivity extends ContactsActivity

        @Override
        public void onSaveFinished(Intent resultIntent) {
            if (resultIntent != null) {
            if (mFinishActivityOnSaveCompleted) {
                setResult(RESULT_OK, resultIntent);
            } else if (resultIntent != null) {
                startActivity(resultIntent);
            }
            finish();
+1 −1
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public class GroupDetailActivity extends ContactsActivity {
        @Override
        public void onContactSelected(Uri contactUri) {
            Intent intent = new Intent(Intent.ACTION_VIEW, contactUri);
            intent.putExtra(ContactDetailActivity.INTENT_KEY_IGNORE_DEFAULT_UP_BEHAVIOR, true);
            intent.putExtra(ContactDetailActivity.INTENT_KEY_FINISH_ACTIVITY_ON_UP_SELECTED, true);
            startActivity(intent);
        }

+40 −10
Original line number Diff line number Diff line
@@ -110,9 +110,12 @@ public class PeopleActivity extends ContactsActivity

    private static final String TAG = "PeopleActivity";

    private static final int SUBACTIVITY_NEW_GROUP = 2;
    private static final int SUBACTIVITY_EDIT_GROUP = 3;
    private static final int SUBACTIVITY_ACCOUNT_FILTER = 4;
    // These values needs to start at 2. See {@link ContactEntryListFragment}.
    private static final int SUBACTIVITY_NEW_CONTACT = 2;
    private static final int SUBACTIVITY_EDIT_CONTACT = 3;
    private static final int SUBACTIVITY_NEW_GROUP = 4;
    private static final int SUBACTIVITY_EDIT_GROUP = 5;
    private static final int SUBACTIVITY_ACCOUNT_FILTER = 6;

    private final DialogManager mDialogManager = new DialogManager(this);

@@ -989,11 +992,10 @@ public class PeopleActivity extends ContactsActivity
            } else {
                Intent intent = new Intent(Intent.ACTION_VIEW, contactLookupUri);
                // In search mode, the "up" affordance in the contact detail page should return the
                // user to the search results, so suppress the normal behavior which would re-launch
                // {@link PeopleActivity} when the "up" affordance is clicked.
                // user to the search results, so finish the activity when that button is selected.
                if (mActionBarAdapter.isSearchMode()) {
                    intent.putExtra(ContactDetailActivity.INTENT_KEY_IGNORE_DEFAULT_UP_BEHAVIOR,
                            true);
                    intent.putExtra(
                            ContactDetailActivity.INTENT_KEY_FINISH_ACTIVITY_ON_UP_SELECTED, true);
                }
                startActivity(intent);
            }
@@ -1016,7 +1018,9 @@ public class PeopleActivity extends ContactsActivity
            if (extras != null) {
                intent.putExtras(extras);
            }
            startActivity(intent);
            intent.putExtra(
                    ContactEditorActivity.INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);
            startActivityForResult(intent, SUBACTIVITY_EDIT_CONTACT);
        }

        @Override
@@ -1101,7 +1105,10 @@ public class PeopleActivity extends ContactsActivity

        @Override
        public void onEditRequested(Uri contactLookupUri) {
            startActivity(new Intent(Intent.ACTION_EDIT, contactLookupUri));
            Intent intent = new Intent(Intent.ACTION_EDIT, contactLookupUri);
            intent.putExtra(
                    ContactEditorActivity.INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);
            startActivityForResult(intent, SUBACTIVITY_EDIT_CONTACT);
        }

        @Override
@@ -1390,7 +1397,17 @@ public class PeopleActivity extends ContactsActivity
            }
            case R.id.menu_add_contact: {
                final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                // On 2-pane UI, we can let the editor activity finish itself and return
                // to this activity to display the new contact.
                if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
                    intent.putExtra(
                        ContactEditorActivity.INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED, true);
                    startActivityForResult(intent, SUBACTIVITY_NEW_CONTACT);
                } else {
                    // Otherwise, on 1-pane UI, we need the editor to launch the view contact
                    // intent itself.
                    startActivity(intent);
                }
                return true;
            }
            case R.id.menu_add_group: {
@@ -1465,6 +1482,19 @@ public class PeopleActivity extends ContactsActivity
                break;
            }

            case SUBACTIVITY_NEW_CONTACT:
            case SUBACTIVITY_EDIT_CONTACT: {
                if (resultCode == RESULT_OK && PhoneCapabilityTester.isUsingTwoPanes(this)) {
                    mRequest.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT);
                    mAllFragment.reloadDataAndSetSelectedUri(data.getData());
                    // Suppress IME if in search mode
                    if (mActionBarAdapter != null) {
                        mActionBarAdapter.clearFocusOnSearchView();
                    }
                }
                break;
            }

            case SUBACTIVITY_NEW_GROUP:
            case SUBACTIVITY_EDIT_GROUP: {
                if (resultCode == RESULT_OK && PhoneCapabilityTester.isUsingTwoPanes(this)) {