Search in sources :

Example 6 with PostalAddress

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

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

the class ContactChangeHelper method randomAddress.

private static PostalAddress randomAddress() {
    String addressLine1 = null, addressLine2 = null, city = null, county = null, pobox = null, postcode = null, country = null;
    if (randomTrue()) {
        pobox = randomString();
    }
    if (randomTrue()) {
        addressLine1 = randomString();
    }
    if (randomTrue()) {
        addressLine2 = randomString();
    }
    if (randomTrue()) {
        city = randomString();
    }
    if (randomTrue()) {
        county = randomString();
    }
    if (randomTrue()) {
        postcode = randomNumbersString();
    }
    if (randomTrue()) {
        country = randomString();
    }
    PostalAddress address = new PostalAddress();
    if (pobox != null || addressLine1 != null || addressLine2 != null || city != null || county != null || postcode != null || country != null) {
        address.addressLine1 = addressLine1;
        address.addressLine2 = addressLine2;
        address.postOfficeBox = pobox;
        address.postCode = postcode;
        address.city = city;
        address.county = county;
        address.country = country;
    } else {
        // So that we have one part not null
        address.addressLine1 = randomString();
    }
    return address;
}
Also used : PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress)

Aggregations

PostalAddress (com.vodafone360.people.datatypes.VCardHelper.PostalAddress)7 Name (com.vodafone360.people.datatypes.VCardHelper.Name)2 Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)2 Time (android.text.format.Time)1 Contact (com.vodafone360.people.datatypes.Contact)1 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)1