Search in sources :

Example 46 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class ContactChangeHelper method areChangesEqual.

public static boolean areChangesEqual(ContactChange a, ContactChange b, boolean compareAll) {
    if (a.getKey() != b.getKey()) {
        return false;
    }
    // just for convenience
    final int key = a.getKey();
    if (!VersionUtils.is2XPlatform() && key == ContactChange.KEY_VCARD_NAME) {
        // Need to convert to raw string or else we can't compare them because of NAB 1.X limitations
        final Name nameA = VCardHelper.getName(a.getValue());
        final Name nameB = VCardHelper.getName(b.getValue());
        final String nameAStr = nameA.toString();
        final String nameBStr = nameB.toString();
        if (!TextUtils.equals(nameAStr, nameBStr)) {
            return false;
        }
    } else if (!VersionUtils.is2XPlatform() && key == ContactChange.KEY_VCARD_ADDRESS) {
        // Need to convert to raw string or else we can't compare them because of NAB 1.X limitations
        final PostalAddress addressA = VCardHelper.getPostalAddress(a.getValue());
        final PostalAddress addressB = VCardHelper.getPostalAddress(b.getValue());
        // Need to also remove \n's that were put there by .toString
        final String addressAStr = addressA.toString().replaceAll("\n", "");
        final String addressBStr = addressB.toString().replaceAll("\n", "");
        if (!TextUtils.equals(addressAStr, addressBStr)) {
            return false;
        }
    } else if (!VersionUtils.is2XPlatform() && key == ContactChange.KEY_VCARD_ORG) {
        // Org on 1.X does not support department, need to NOT compare that
        final Organisation orgA = VCardHelper.getOrg(a.getValue());
        final Organisation orgB = VCardHelper.getOrg(b.getValue());
        if (!TextUtils.equals(orgA.name, orgB.name)) {
            return false;
        }
    } else if (!TextUtils.equals(a.getValue(), b.getValue())) {
        return false;
    }
    switch(key) {
        case ContactChange.KEY_VCARD_ORG:
        case ContactChange.KEY_VCARD_TITLE:
        case ContactChange.KEY_VCARD_PHONE:
        case ContactChange.KEY_VCARD_EMAIL:
        case ContactChange.KEY_VCARD_ADDRESS:
            // NAB may have changed these fields to preferred even though they were inserted as not preferred! 
            final int flagsWithoutPreferredA = a.getFlags() & ~ContactChange.FLAG_PREFERRED;
            final int flagsWithoutPreferredB = b.getFlags() & ~ContactChange.FLAG_PREFERRED;
            if (flagsWithoutPreferredA != flagsWithoutPreferredB) {
                return false;
            }
            break;
        default:
            if (a.getFlags() != b.getFlags()) {
                return false;
            }
            break;
    }
    if (VersionUtils.is2XPlatform() && a.getFlags() != b.getFlags()) {
        return false;
    } else if (!VersionUtils.is2XPlatform()) {
    }
    if (compareAll) {
        if (a.getType() != b.getType()) {
            return false;
        }
        if (a.getInternalContactId() != b.getInternalContactId()) {
            return false;
        }
        if (a.getInternalDetailId() != b.getInternalDetailId()) {
            return false;
        }
        if (a.getBackendContactId() != b.getBackendContactId()) {
            return false;
        }
        if (a.getBackendDetailId() != b.getBackendDetailId()) {
            return false;
        }
        if (a.getNabContactId() != b.getNabContactId()) {
            return false;
        }
        if (a.getNabDetailId() != b.getNabDetailId()) {
            return false;
        }
    }
    return true;
}
Also used : PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress) Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 47 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class ContactChangeHelper method generateRandomChangesForKey.

private static void generateRandomChangesForKey(List<ContactChange> ccList, int key, long internalContactId, long backendContactId, long nabContactId, int numChanges) {
    boolean preferredSelected = false;
    for (int i = 0; i < numChanges; i++) {
        ContactChange cc = randomContactChange(key, internalContactId, backendContactId, nabContactId, !preferredSelected);
        if (!preferredSelected) {
            preferredSelected = (cc.getFlags() & ContactChange.FLAG_PREFERRED) == ContactChange.FLAG_PREFERRED;
        }
        ccList.add(cc);
    }
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 48 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class ContactChangeHelper method areChangeListsEqual.

public static boolean areChangeListsEqual(ContactChange[] a, ContactChange[] b, boolean compareAll) {
    final int aLength = a.length;
    final int bLength = b.length;
    if (aLength != bLength) {
        printContactChangeList(a);
        printContactChangeList(b);
        return false;
    }
    for (int i = 0; i < aLength; i++) {
        final ContactChange ccA = a[i];
        final ContactChange ccB = b[i];
        if (!areChangesEqual(ccA, ccB, compareAll)) {
            Log.e("CC COMPARISON", "Contact Change comparison mismatch, ContactChange A to follow:");
            printContactChange(ccA);
            Log.e("CC COMPARISON", "Contact Change comparison mismatch, ContactChange B to follow:");
            printContactChange(ccB);
            return false;
        }
    }
    return true;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 49 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class ContactChangeHelper method printContactChangeList.

public static void printContactChangeList(ContactChange[] ccList) {
    final int length = ccList.length;
    Log.i("CCLIST", "############### START ###############");
    for (int i = 0; i < length; i++) {
        final ContactChange cc = ccList[i];
        printContactChange(cc);
    }
    Log.i("CCLIST", "###############  END  ###############");
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 50 with ContactChange

use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.

the class ContactChangeHelper method randomContactChange.

private static ContactChange randomContactChange(int key, long internalContactId, long backendContactId, long nabContactId, boolean allowPreferred) {
    ContactChange cc = randomContactChange(key, allowPreferred);
    cc.setInternalContactId(internalContactId);
    cc.setBackendContactId(backendContactId);
    cc.setNabContactId(nabContactId);
    return cc;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Aggregations

ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)33 Name (com.vodafone360.people.datatypes.VCardHelper.Name)6 Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)6 PeopleContactsApi (com.vodafone360.people.engine.contactsync.PeopleContactsApi)6 Cursor (android.database.Cursor)5 Suppress (android.test.suitebuilder.annotation.Suppress)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 ArrayList (java.util.ArrayList)5 SQLException (android.database.SQLException)4 SQLiteException (android.database.sqlite.SQLiteException)4 Uri (android.net.Uri)4 PostalAddress (com.vodafone360.people.datatypes.VCardHelper.PostalAddress)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Contact (com.vodafone360.people.datatypes.Contact)3 ContentValues (android.content.ContentValues)2 StructuredName (android.provider.ContactsContract.CommonDataKinds.StructuredName)2 MediumTest (android.test.suitebuilder.annotation.MediumTest)2 SmallTest (android.test.suitebuilder.annotation.SmallTest)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)2 NativeContactsApi (com.vodafone360.people.engine.contactsync.NativeContactsApi)2