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;
}
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;
}
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()]);
}
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());
}
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;
}
Aggregations