use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method filterContactChanges.
/**
* Removes the nickname ContactChange if any as we don't support it currently.
*
* @param changes the array of ContactChange to filter
* @return the filtered array of ContactChange
*/
private ContactChange[] filterContactChanges(ContactChange[] changes) {
ArrayList<ContactChange> filtered = new ArrayList<ContactChange>(changes.length);
for (int i = 0; i < changes.length; i++) {
final ContactChange cc = changes[i];
filterFlags(cc);
if (cc.getKey() != ContactChange.KEY_VCARD_NICKNAME) {
filtered.add(cc);
}
}
if (filtered.size() == changes.length) {
return changes;
} else {
return filtered.toArray(new ContactChange[filtered.size()]);
}
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class NativeContactsApiTest method testAddGetRemoveContacts.
@MediumTest
@Suppress
public void testAddGetRemoveContacts() {
Account account = null;
if (mUsing2xApi) {
// Add Account for the case where we are in 2.X
mNabApi.addPeopleAccount(PEOPLE_USERNAME);
account = s360PeopleAccount;
threadWait(100);
}
long[] ids = getContactIdsForAllAccounts();
assertNull(ids);
final int numRandomContacts = 10;
long expectedContactId = ContactChange.INVALID_ID;
for (int i = 0; i < numRandomContacts; i++) {
long id = i;
final ContactChange[] newContactCcList = ContactChangeHelper.randomContact(id, id, -1);
final ContactChange[] newIds = mNabApi.addContact(account, newContactCcList);
// expected num ids is + 1 for contact id
verifyNewContactIds(expectedContactId, newContactCcList, newIds);
expectedContactId = newIds[0].getNabContactId() + 1;
// GET CONTACTS AND COMPARE
ids = getContactIdsForAllAccounts();
assertNotNull(ids);
assertEquals(i + 1, ids.length);
final ContactChange[] fetchedContactCcList = mNabApi.getContact(ids[i]);
assertNotNull(fetchedContactCcList);
if (!ContactChangeHelper.areChangeListsEqual(newContactCcList, fetchedContactCcList, false)) {
Log.e(LOG_TAG, "ADD FAILED: Print of contact to be added follows:");
ContactChangeHelper.printContactChangeList(newContactCcList);
Log.e(LOG_TAG, "ADD FAILED: Print of contact fetched follows:");
ContactChangeHelper.printContactChangeList(fetchedContactCcList);
// fail test at this point
assertFalse(true);
}
}
// DELETE
final int idCount = ids.length;
for (int i = 0; i < idCount; i++) {
mNabApi.removeContact(ids[i]);
}
ids = getContactIdsForAllAccounts();
assertNull(ids);
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class NativeContactsApi1 method preprocessContactToAdd.
/**
* "Pre-processing" of {@link ContactChange} list before it can be added to
* NAB. This needs to be done because of issues on the 1.X NAB and our CAB
* In 1.X NAB: Name and Note which are stored differently from other details
* In our CAB: Organization and Title are separate details contrary to the
* NAB
*
* @param ccList {@link ContactChange} list for the add operation
*/
private void preprocessContactToAdd(ContactChange[] ccList) {
final int ccListSize = ccList.length;
boolean nameFound = false, noteFound = false;
mValues.clear();
for (int i = 0; i < ccListSize; i++) {
final ContactChange cc = ccList[i];
if (cc != null) {
if (!nameFound && cc.getKey() == ContactChange.KEY_VCARD_NAME) {
final Name name = VCardHelper.getName(cc.getValue());
mValues.put(People.NAME, name.toString());
nameFound = true;
}
if (!noteFound && cc.getKey() == ContactChange.KEY_VCARD_NOTE) {
mValues.put(People.NOTES, cc.getValue());
noteFound = true;
}
if (mMarkedOrganizationIndex < 0 && cc.getKey() == ContactChange.KEY_VCARD_ORG) {
mMarkedOrganizationIndex = i;
}
if (mMarkedTitleIndex < 0 && cc.getKey() == ContactChange.KEY_VCARD_TITLE) {
mMarkedTitleIndex = i;
}
}
}
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class NativeContactsApi1 method updateDetail.
/**
* Updates a detail.
*
* @param cc {@link ContactChange} to read data from
* @param nabContactId ID of the NAB Contact
* @return true if the detail was updated, false if not
*/
private boolean updateDetail(ContactChange cc) {
mValues.clear();
Uri contentUri = null;
long nabDetailId = cc.getNabDetailId();
final long nabContactId = cc.getNabContactId();
switch(cc.getKey()) {
case ContactChange.KEY_VCARD_PHONE:
putPhoneValues(cc, nabContactId);
contentUri = Phones.CONTENT_URI;
break;
case ContactChange.KEY_VCARD_EMAIL:
putContactMethodValues(cc, CONTACT_METHODS_KIND_EMAIL, nabContactId);
contentUri = ContactMethods.CONTENT_URI;
break;
case ContactChange.KEY_VCARD_ADDRESS:
putContactMethodValues(cc, CONTACT_METHODS_KIND_ADDRESS, nabContactId);
contentUri = ContactMethods.CONTENT_URI;
break;
case ContactChange.KEY_VCARD_NAME:
final Name name = VCardHelper.getName(cc.getValue());
mValues.put(People.NAME, name.toString());
contentUri = People.CONTENT_URI;
nabDetailId = nabContactId;
break;
case ContactChange.KEY_VCARD_NOTE:
mValues.put(People.NOTES, cc.getValue());
contentUri = People.CONTENT_URI;
nabDetailId = nabContactId;
break;
}
if (contentUri != null) {
Uri uri = ContentUris.withAppendedId(contentUri, nabDetailId);
return mCr.update(uri, mValues, null, null) > 0;
}
return false;
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class NativeContactsApi2 method readName.
/**
* Reads an name detail as a {@link ContactChange} from the provided cursor.
* For this type of detail we need to use a VCARD (semicolon separated)
* value.
*
* @param cursor Cursor to read from
* @param ccList List of Contact Changes to add read detail data
* @param nabContactId ID of the NAB Contact
*/
private void readName(Cursor cursor, List<ContactChange> ccList, long nabContactId) {
// Using display name only to check if there is a valid name to read
final String displayName = CursorUtils.getString(cursor, StructuredName.DISPLAY_NAME);
if (!TextUtils.isEmpty(displayName)) {
final long nabDetailId = CursorUtils.getLong(cursor, StructuredName._ID);
// VCard Helper data type (CAB)
final Name name = new Name();
// NAB: Given name -> CAB: First name
name.firstname = CursorUtils.getString(cursor, StructuredName.GIVEN_NAME);
// NAB: Family name -> CAB: Surname
name.surname = CursorUtils.getString(cursor, StructuredName.FAMILY_NAME);
// NAB: Prefix -> CAB: Title
name.title = CursorUtils.getString(cursor, StructuredName.PREFIX);
// NAB: Middle name -> CAB: Middle name
name.midname = CursorUtils.getString(cursor, StructuredName.MIDDLE_NAME);
// NAB: Suffix -> CAB: Suffixes
name.suffixes = CursorUtils.getString(cursor, StructuredName.SUFFIX);
// NOTE: Ignoring Phonetics (DATA7, DATA8 and DATA9)!
// TODO: Need to get middle name and concatenate into value
final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_NAME, VCardHelper.makeName(name), ContactChange.FLAG_NONE);
cc.setNabContactId(nabContactId);
cc.setNabDetailId(nabDetailId);
ccList.add(cc);
}
}
Aggregations