Search in sources :

Example 11 with Organisation

use of com.vodafone360.people.datatypes.VCardHelper.Organisation 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 12 with Organisation

use of com.vodafone360.people.datatypes.VCardHelper.Organisation in project 360-Engine-for-Android by 360.

the class NativeContactsApi1 method writeOrganization.

/**
 * Write Organization detail to NAB
 *
 * @param ccList {@link ContactChange} list where Organization and Title are
 *            found
 * @param nabContactId ID of the NAB Contact
 * @return ID of the NAB Contact
 */
private long writeOrganization(ContactChange[] ccList, long nabContactId) {
    mValues.clear();
    int flags = ContactChange.FLAG_NONE;
    if (mMarkedOrganizationIndex >= 0) {
        final ContactChange cc = ccList[mMarkedOrganizationIndex];
        final Organisation organization = VCardHelper.getOrg(cc.getValue());
        if (!TextUtils.isEmpty(organization.name)) {
            mValues.put(Organizations.COMPANY, organization.name);
            flags |= cc.getFlags();
        }
    }
    if (mMarkedTitleIndex >= 0) {
        final ContactChange cc = ccList[mMarkedTitleIndex];
        // No need to check for empty values as there is only one
        flags |= cc.getFlags();
        mValues.put(Organizations.TITLE, cc.getValue());
    }
    if (mValues.size() > 0) {
        mValues.put(Organizations.PERSON_ID, nabContactId);
        mValues.put(Organizations.TYPE, mapToNabOrganizationType(flags));
        final Uri uri = mCr.insert(Organizations.CONTENT_URI, mValues);
        if (uri != null) {
            return ContentUris.parseId(uri);
        }
    }
    return ContactChange.INVALID_ID;
}
Also used : Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation) Uri(android.net.Uri)

Aggregations

Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)9 Uri (android.net.Uri)5 Contact (com.vodafone360.people.datatypes.Contact)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 Cursor (android.database.Cursor)4 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)4 ContentValues (android.content.ContentValues)3 MediumTest (android.test.suitebuilder.annotation.MediumTest)3 Suppress (android.test.suitebuilder.annotation.Suppress)3 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)3 ServiceStatus (com.vodafone360.people.service.ServiceStatus)3 Time (android.text.format.Time)2 Name (com.vodafone360.people.datatypes.VCardHelper.Name)2 PostalAddress (com.vodafone360.people.datatypes.VCardHelper.PostalAddress)2