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

Commit 01a9fac7 authored by Dave Santoro's avatar Dave Santoro
Browse files

Fix phone number comparison in Phone Favorites.

This switches to using ContactsUtils.shouldCollapse for determining
whether we should combine the two numbers.

Bug 5294289

Change-Id: Id1ec369cfe698b52186ff392255d789458622e9d
parent 6f8bc03d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -102,8 +102,8 @@ public class ContactsUtils {
     * considered equal for collapsing in the GUI. For caller-id, use
     * {@link PhoneNumberUtils#compare(Context, String, String)} instead
     */
    public static final boolean shouldCollapse(Context context, CharSequence mimetype1,
            CharSequence data1, CharSequence mimetype2, CharSequence data2) {
    public static final boolean shouldCollapse(CharSequence mimetype1, CharSequence data1,
            CharSequence mimetype2, CharSequence data2) {
        // different mimetypes? don't collapse
        if (!TextUtils.equals(mimetype1, mimetype2)) return false;

+1 −2
Original line number Diff line number Diff line
@@ -1348,8 +1348,7 @@ public class ContactDetailFragment extends Fragment implements FragmentKeyListen
                return false;
            }

            if (!ContactsUtils.shouldCollapse(context, mimetype, data, entry.mimetype,
                    entry.data)) {
            if (!ContactsUtils.shouldCollapse(mimetype, data, entry.mimetype, entry.data)) {
                return false;
            }

+3 −12
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.contacts.interactions;
import com.android.contacts.Collapser;
import com.android.contacts.Collapser.Collapsible;
import com.android.contacts.ContactSaveService;
import com.android.contacts.ContactsUtils;
import com.android.contacts.R;
import com.android.contacts.model.AccountType;
import com.android.contacts.model.AccountType.StringInflater;
@@ -123,18 +124,8 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
        }

        public boolean shouldCollapseWith(PhoneItem phoneItem) {
            try {
                PhoneNumberUtil util = PhoneNumberUtil.getInstance();
                PhoneNumber phoneNumber1 = util.parse(phoneNumber, "ZZ" /* Unknown */);
                PhoneNumber phoneNumber2 = util.parse(phoneItem.phoneNumber, "ZZ" /* Unknown */);
                MatchType matchType = util.isNumberMatch(phoneNumber1, phoneNumber2);
                if (matchType == MatchType.SHORT_NSN_MATCH) {
                    return true;
                }
            } catch (NumberParseException e) {
                return TextUtils.equals(phoneNumber, phoneItem.phoneNumber);
            }
            return false;
            return ContactsUtils.shouldCollapse(Phone.CONTENT_ITEM_TYPE, phoneNumber,
                    Phone.CONTENT_ITEM_TYPE, phoneItem.phoneNumber);
        }

        @Override
+1 −2
Original line number Diff line number Diff line
@@ -294,8 +294,7 @@ public class DataAction implements Action {
            return false;
        }
        DataAction that = (DataAction)t;
        if (!ContactsUtils.shouldCollapse(mContext, mMimeType, mBody, that.mMimeType,
                that.mBody)) {
        if (!ContactsUtils.shouldCollapse(mMimeType, mBody, that.mMimeType, that.mBody)) {
            return false;
        }
        if (!TextUtils.equals(mMimeType, that.mMimeType)
+4 −4
Original line number Diff line number Diff line
@@ -160,9 +160,9 @@ public class ContactsUtilsTests extends AndroidTestCase {
    private void assertCollapses(String message, boolean expected, CharSequence mimetype1,
            CharSequence data1, CharSequence mimetype2, CharSequence data2) {
        assertEquals(message, expected,
                ContactsUtils.shouldCollapse(mContext, mimetype1, data1, mimetype2, data2));
                ContactsUtils.shouldCollapse(mimetype1, data1, mimetype2, data2));
        assertEquals(message, expected,
                ContactsUtils.shouldCollapse(mContext, mimetype2, data2, mimetype1, data1));
                ContactsUtils.shouldCollapse(mimetype2, data2, mimetype1, data1));

        if (data1 == data2 && data1 != null) {
            // make sure we also do a test where object equality is not given
@@ -173,10 +173,10 @@ public class ContactsUtilsTests extends AndroidTestCase {

            // we have two different instances, now make sure we get the same result as before
            assertEquals(message, expected,
                    ContactsUtils.shouldCollapse(mContext, mimetype1, data1, mimetype2,
                    ContactsUtils.shouldCollapse(mimetype1, data1, mimetype2,
                    data2_newref));
            assertEquals(message, expected,
                    ContactsUtils.shouldCollapse(mContext, mimetype2, data2_newref, mimetype1,
                    ContactsUtils.shouldCollapse(mimetype2, data2_newref, mimetype1,
                    data1));
        }
    }