Search in sources :

Example 1 with ContactChange

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

the class DatabaseHelper method convertNativeContactChanges.

/**
     * Converts an array of ContactChange into a Contact object.
     * 
     * @see ContactChange
     * @see Contact
     * @param contactChanges the array of ContactChange to convert
     * @return the equivalent Contact
     */
private Contact convertNativeContactChanges(ContactChange[] contactChanges) {
    if (contactChanges == null || contactChanges.length <= 0)
        return null;
    final Contact contact = new Contact();
    contact.localContactID = contactChanges[0].getInternalContactId();
    // coming from native
    contact.nativeContactId = new Integer((int) contactChanges[0].getNabContactId());
    contact.synctophone = true;
    // fill the contact with all the details
    for (int i = 0; i < contactChanges.length; i++) {
        final ContactDetail detail = convertContactChange(contactChanges[i]);
        // setting it to -1 means that it does not need to be synced back to
        // native
        detail.syncNativeContactId = -1;
        contact.details.add(detail);
    }
    return contact;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 2 with ContactChange

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

the class ContactChangeHelper method generateUpdateDetailChange.

private static ContactChange generateUpdateDetailChange(ContactChange cc) {
    if (cc == null) {
        return null;
    }
    final int key = cc.getKey();
    boolean changed = false;
    String value = cc.getValue();
    int flags = cc.getFlags();
    int newFlags = flags;
    if (randomTrue()) {
        value = randomValue(key);
        changed = true;
    }
    if (randomTrue()) {
        flags = randomFlags(key, false);
        if (newFlags != flags) {
            changed = true;
        }
    }
    if (!changed) {
        value = randomValue(key);
    }
    final ContactChange updateDetailCc = new ContactChange(key, value, newFlags);
    updateDetailCc.setType(ContactChange.TYPE_UPDATE_DETAIL);
    updateDetailCc.setInternalContactId(cc.getInternalContactId());
    updateDetailCc.setInternalDetailId(cc.getInternalDetailId());
    updateDetailCc.setBackendContactId(cc.getBackendContactId());
    updateDetailCc.setBackendDetailId(cc.getBackendDetailId());
    updateDetailCc.setNabContactId(cc.getNabContactId());
    updateDetailCc.setNabDetailId(cc.getNabDetailId());
    return updateDetailCc;
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 3 with ContactChange

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

the class ContactChangeHelper method generatedUpdatedContact.

public static ContactChange[] generatedUpdatedContact(ContactChange[] contact, ContactChange[] update) {
    if (update == null || update.length == 0) {
        return contact;
    }
    final List<ContactChange> updatedContact = new ArrayList<ContactChange>();
    final int contactSize = contact.length;
    final int updateSize = update.length;
    for (int i = 0; i < contactSize; i++) {
        ContactChange cc = contact[i];
        int updateType = ContactChange.TYPE_UNKNOWN;
        if (updateSize > i) {
            updateType = update[i].getType();
        }
        if (updateType == ContactChange.TYPE_UPDATE_DETAIL) {
            cc = update[i];
        } else if (updateType == ContactChange.TYPE_DELETE_DETAIL) {
            continue;
        }
        updatedContact.add(cc);
    }
    for (int i = 0; i < updateSize; i++) {
        final ContactChange cc = update[i];
        //final int key = cc.getKey();
        if (cc.getType() == ContactChange.TYPE_ADD_DETAIL) {
            //updatedContact.add(lastIndexForKeyInCcList(key, updatedContact) + 1, cc);
            // Since we are using areUnsortedChangeListsEqual to compare we can just add instead of above
            updatedContact.add(cc);
        }
    }
    return updatedContact.toArray(new ContactChange[updatedContact.size()]);
}
Also used : ArrayList(java.util.ArrayList) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 4 with ContactChange

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

the class ContactChangeTest method testSettersAndGetters.

@SmallTest
public void testSettersAndGetters() {
    // at the same time test the initial values of the default constructor
    ContactChange cc = new ContactChange();
    assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
    cc.setFlags(ContactChange.FLAGS_HOME_CELL);
    assertEquals(ContactChange.FLAGS_HOME_CELL, cc.getFlags());
    assertEquals(ContactChange.TYPE_UNKNOWN, cc.getType());
    cc.setType(ContactChange.TYPE_UPDATE_BACKEND_CONTACT_ID);
    assertEquals(ContactChange.TYPE_UPDATE_BACKEND_CONTACT_ID, cc.getType());
    assertEquals(-1L, cc.getBackendContactId());
    cc.setBackendContactId(Long.MAX_VALUE);
    assertEquals(Long.MAX_VALUE, cc.getBackendContactId());
    assertEquals(-1L, cc.getBackendDetailId());
    cc.setBackendDetailId(Long.MIN_VALUE);
    assertEquals(Long.MIN_VALUE, cc.getBackendDetailId());
    assertEquals(-1L, cc.getInternalContactId());
    cc.setInternalContactId(Long.MAX_VALUE);
    assertEquals(Long.MAX_VALUE, cc.getInternalContactId());
    assertEquals(-1L, cc.getInternalDetailId());
    cc.setInternalDetailId(Long.MIN_VALUE);
    assertEquals(Long.MIN_VALUE, cc.getInternalDetailId());
    assertEquals(-1L, cc.getNabContactId());
    cc.setNabContactId(Long.MAX_VALUE);
    assertEquals(Long.MAX_VALUE, cc.getNabContactId());
    assertEquals(-1L, cc.getNabDetailId());
    cc.setNabDetailId(Long.MIN_VALUE);
    assertEquals(Long.MIN_VALUE, cc.getNabDetailId());
    assertEquals(null, cc.getValue());
    assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
}
Also used : ContactChange(com.vodafone360.people.engine.contactsync.ContactChange) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 5 with ContactChange

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

the class ContactChangeHelper method generateDeleteDetailChange.

private static ContactChange generateDeleteDetailChange(ContactChange cc) {
    if (cc == null) {
        return null;
    }
    final ContactChange deleteDetailCc = new ContactChange();
    deleteDetailCc.setKey(cc.getKey());
    deleteDetailCc.setType(ContactChange.TYPE_DELETE_DETAIL);
    deleteDetailCc.setInternalContactId(cc.getInternalContactId());
    deleteDetailCc.setInternalDetailId(cc.getInternalDetailId());
    deleteDetailCc.setBackendContactId(cc.getBackendContactId());
    deleteDetailCc.setBackendDetailId(cc.getBackendDetailId());
    deleteDetailCc.setNabContactId(cc.getNabContactId());
    deleteDetailCc.setNabDetailId(cc.getNabDetailId());
    return deleteDetailCc;
}
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