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

Commit e1cabcd0 authored by Katherine Kuan's avatar Katherine Kuan
Browse files

Selecting "Add to my contacts" on tablet can show wrong contact

- The ALL_CONTACTS URI doesn't support sending a contact URI
in the intent as well. Hence, change intent action to
ACTION_VIEW.

- If you view a contact (selectedContactUri contains
that contact), if you modify the group it is in (i.e.
click the "Add to My Contacts" button OR edit contact
and remove them from the group you are currently
filtering your view with), then it's possible
it won't be in the list anymore.

In order to force a reload of the list, we need to have
mSelectionRequired = true, but it is never set to true
if the selected contact URI is the same as before. Thus,
we add a setSelectionRequired() method to force it to
require a selection if this is an incoming request on the
tablet. We don't want to modify the ContactBrowseListFragment
setSelectedContactUri code to set selection required = true
for all cases where the contact URI is equal because that
could lead to extra computation when the list reloads
and the selected contact is still the same.

- Don't compute selected position in adapter two times
(this is a linear search in the cursor). Just reuse the value
that was computed the first time.

Bug: 5478636
Change-Id: Ic5425d084df5492118a0e29cdc48a1c168e558e7
parent a91e74a3
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -879,6 +879,12 @@ public class PeopleActivity extends ContactsActivity
    private void configureContactListFragmentForRequest() {
        Uri contactUri = mRequest.getContactUri();
        if (contactUri != null) {
            // For an incoming request, explicitly require a selection if we are on 2-pane UI,
            // (i.e. even if we view the same selected contact, the contact may no longer be
            // in the list, so we must refresh the list).
            if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
                mAllFragment.setSelectionRequired(true);
            }
            mAllFragment.setSelectedContactUri(contactUri);
        }

@@ -1486,6 +1492,7 @@ public class PeopleActivity extends ContactsActivity
            case SUBACTIVITY_EDIT_CONTACT: {
                if (resultCode == RESULT_OK && PhoneCapabilityTester.isUsingTwoPanes(this)) {
                    mRequest.setActionCode(ContactsRequest.ACTION_VIEW_CONTACT);
                    mAllFragment.setSelectionRequired(true);
                    mAllFragment.reloadDataAndSetSelectedUri(data.getData());
                    // Suppress IME if in search mode
                    if (mActionBarAdapter != null) {
+1 −1
Original line number Diff line number Diff line
@@ -2007,7 +2007,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
            // should update the ui
            final Intent intent = ContactSaveService.createSaveContactIntent(getActivity(),
                    contactDeltaList, "", 0, false, getActivity().getClass(),
                    UI.LIST_ALL_CONTACTS_ACTION);
                    Intent.ACTION_VIEW);
            getActivity().startService(intent);
        }
    }
+16 −4
Original line number Diff line number Diff line
@@ -309,6 +309,19 @@ public abstract class ContactBrowseListFragment extends
        super.setQueryString(queryString, delaySelection);
    }

    /**
     * Sets whether or not a contact selection must be made.
     * @param required if true, we need to check if the selection is present in
     *            the list and if not notify the listener so that it can load a
     *            different list.
     * TODO: Figure out how to reconcile this with {@link #setSelectedContactUri},
     * without causing unnecessary loading of the list if the selected contact URI is
     * the same as before.
     */
    public void setSelectionRequired(boolean required) {
        mSelectionRequired = required;
    }

    /**
     * Sets the new contact selection.
     *
@@ -456,7 +469,7 @@ public abstract class ContactBrowseListFragment extends
        adapter.setSelectedContact(
                mSelectedContactDirectoryId, mSelectedContactLookupKey, mSelectedContactId);

        int selectedPosition = adapter.getSelectedContactPosition();
        final int selectedPosition = adapter.getSelectedContactPosition();
        if (selectedPosition != -1) {
            mLastSelectedPosition = selectedPosition;
        } else {
@@ -506,7 +519,7 @@ public abstract class ContactBrowseListFragment extends
        }

        if (mSelectionToScreenRequested) {
            requestSelectionToScreen();
            requestSelectionToScreen(selectedPosition);
        }

        getListView().invalidateViews();
@@ -554,8 +567,7 @@ public abstract class ContactBrowseListFragment extends
        setSelectedContactUri(contactUri, false, mSmoothScrollRequested, false, false);
    }

    protected void requestSelectionToScreen() {
        int selectedPosition = getAdapter().getSelectedContactPosition();
    protected void requestSelectionToScreen(int selectedPosition) {
        if (selectedPosition != -1) {
            AutoScrollListView listView = (AutoScrollListView)getListView();
            listView.requestPositionToScreen(