use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method populateWithDeletedContactDetails.
/**
* This method adds the deleted details to the detail list sent to server...
* @param dbHelper DatabaseHelper - database
* @param contactDetails List<ContactDetail> - the deleted details list
* @param contactId Long - Me Profile local contact id.
*/
private static void populateWithDeletedContactDetails(final DatabaseHelper dbHelper, final List<ContactDetail> contactDetails, final Long contactId) {
List<ContactChangeInfo> deletedDetails = new ArrayList<ContactChangeInfo>();
if (!ContactChangeLogTable.fetchMeProfileChangeLog(deletedDetails, ContactChangeType.DELETE_DETAIL, dbHelper.getReadableDatabase(), contactId)) {
LogUtils.logE("UploadServerContacts populateWithDeletedContactDetails -" + " Unable to fetch contact changes from database");
return;
}
for (int i = 0; i < deletedDetails.size(); i++) {
ContactChangeInfo info = deletedDetails.get(i);
final ContactDetail detail = new ContactDetail();
detail.localDetailID = info.mLocalDetailId;
detail.key = info.mServerDetailKey;
detail.unique_id = info.mServerDetailId;
detail.deleted = true;
contactDetails.add(detail);
}
dbHelper.deleteContactChanges(deletedDetails);
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method processMyContactDetailsChanges.
/**
* This method stores the getMyChanges() response to database - details part.
* @param dbHelper DatabaseHelper - database.
* @param currentMeProfile Contact - me profile contact.
* @param profileChanges UserProfile - the contact changes.
* @return ServiceStatus - SUCCESS if the contact changes have been successfully processed stored.
*/
private static String processMyContactDetailsChanges(final DatabaseHelper dbHelper, final Contact currentMeProfile, final UserProfile profileChanges) {
String ret = null;
final ArrayList<ContactDetail> modifiedDetailList = new ArrayList<ContactDetail>();
final ArrayList<ContactDetail> addedDetailList = new ArrayList<ContactDetail>();
final ArrayList<ContactDetail> deletedDetailList = new ArrayList<ContactDetail>();
for (ContactDetail newDetail : profileChanges.details) {
boolean found = false;
for (int i = 0; i < currentMeProfile.details.size(); i++) {
ContactDetail oldDetail = currentMeProfile.details.get(i);
if (DatabaseHelper.doDetailsMatch(newDetail, oldDetail)) {
found = true;
if (newDetail.deleted != null && newDetail.deleted.booleanValue()) {
deletedDetailList.add(oldDetail);
} else if (DatabaseHelper.hasDetailChanged(oldDetail, newDetail)) {
newDetail.localDetailID = oldDetail.localDetailID;
newDetail.localContactID = oldDetail.localContactID;
newDetail.nativeContactId = oldDetail.nativeContactId;
newDetail.nativeDetailId = oldDetail.nativeDetailId;
modifiedDetailList.add(newDetail);
if (newDetail.key == DetailKeys.PHOTO) {
dbHelper.markMeProfileAvatarChanged();
ret = newDetail.value;
}
}
break;
}
}
// in the response or the deleted flag was false we have to add the new detail to the list
if ((!found) && ((null == newDetail.deleted) || (!newDetail.deleted.booleanValue()))) {
newDetail.localContactID = currentMeProfile.localContactID;
newDetail.nativeContactId = currentMeProfile.nativeContactId;
if (newDetail.key == DetailKeys.PHOTO) {
dbHelper.markMeProfileAvatarChanged();
ret = newDetail.value;
}
addedDetailList.add(newDetail);
}
}
if (!addedDetailList.isEmpty()) {
dbHelper.syncAddContactDetailList(addedDetailList, false, false);
}
if (!modifiedDetailList.isEmpty()) {
dbHelper.syncModifyContactDetailList(modifiedDetailList, false, false);
}
if (!deletedDetailList.isEmpty()) {
dbHelper.syncDeleteContactDetailList(deletedDetailList, false, false);
}
return ret;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method updateStatus.
/**
* The utility method to save the status text change to the database...
* @param dbHelper DatabaseHelper - database
* @param statusText String - status text
* @return ContactDetail - the modified or created ContactDetail with key
* ContactDetail.DetailKeys.PRESENCE_TEXT
*/
public static ContactDetail updateStatus(final DatabaseHelper dbHelper, final String statusText) {
Contact meContact = new Contact();
if (fetchMeProfile(dbHelper, meContact) == ServiceStatus.SUCCESS) {
// try to modify an existing detail
for (ContactDetail detail : meContact.details) {
if (detail.key == ContactDetail.DetailKeys.PRESENCE_TEXT) {
detail.value = statusText;
// Currently it's only possible to post a status on
// Vodafone sns
detail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
if (ServiceStatus.SUCCESS == dbHelper.modifyContactDetail(detail)) {
return detail;
}
}
}
// create a new detail instead
ContactDetail contactDetail = new ContactDetail();
contactDetail.setValue(statusText, ContactDetail.DetailKeys.PRESENCE_TEXT, null);
contactDetail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
contactDetail.localContactID = meContact.localContactID;
if (ServiceStatus.SUCCESS == dbHelper.addContactDetail(contactDetail)) {
return contactDetail;
}
}
return null;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method updateMeProfileDbDetailIds.
/**
* The utility method to save Contacts/setMe() response to the database...
* @param dbHelper Database - database
* @param uploadedMeProfile Contact - me profile which has been uploaded in
* Contacts/setMe() call
* @param result ContactChanges - the contents of response Contacts/setMe().
* The contact details in response need to be in the same order
* as they were in setMe() request
*/
public static void updateMeProfileDbDetailIds(final DatabaseHelper dbHelper, final ArrayList<ContactDetail> uploadedDetails, final ContactChanges result) {
Contact uploadedMeProfile = new Contact();
SyncMeDbUtils.fetchMeProfile(dbHelper, uploadedMeProfile);
boolean changed = false;
if (result.mUserProfile.userID != null && !result.mUserProfile.userID.equals(uploadedMeProfile.userID)) {
uploadedMeProfile.userID = result.mUserProfile.userID;
changed = true;
}
if (result.mUserProfile.contactID != null && !result.mUserProfile.contactID.equals(uploadedMeProfile.contactID)) {
uploadedMeProfile.contactID = result.mUserProfile.contactID;
changed = true;
}
if (changed) {
dbHelper.modifyContactServerId(uploadedMeProfile.localContactID, uploadedMeProfile.contactID, uploadedMeProfile.userID);
}
ListIterator<ContactDetail> destIt = uploadedDetails.listIterator();
for (ContactDetail srcDetail : result.mUserProfile.details) {
if (!destIt.hasNext()) {
LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - # of details in response > # in request");
return;
}
final ContactDetail destDetail = destIt.next();
if (srcDetail.key == null || !srcDetail.key.equals(destDetail.key)) {
LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - details order is wrong");
break;
}
destDetail.unique_id = srcDetail.unique_id;
dbHelper.syncContactDetail(destDetail.localDetailID, destDetail.unique_id);
}
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class NowPlusContactDetailsTableTest method testFetchContactDetailsForNative.
public void testFetchContactDetailsForNative() {
final String fnName = "testFetchContactDetailsForNative";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
startSubTest(fnName, "Creating table");
createTable();
Contact contact = new Contact();
contact.localContactID = TestModule.generateRandomLong();
// create and add NameDetail
ContactDetail nameDetail = mTestModule.createDummyDetailsName();
ContactDetail nicknameDetail = mTestModule.createDummyDetailsNickname(nameDetail);
nicknameDetail.localContactID = contact.localContactID;
nicknameDetail.nativeContactId = TestModule.generateRandomInt();
ServiceStatus status = ContactDetailsTable.addContactDetail(nicknameDetail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
List<ContactDetail> addedDetails = new ArrayList<ContactDetail>();
addedDetails.add(nicknameDetail);
// create and add phoneDetail
ContactDetail phoneDetail = new ContactDetail();
phoneDetail.localContactID = contact.localContactID;
phoneDetail.key = ContactDetail.DetailKeys.VCARD_PHONE;
String number = "07967 123456";
phoneDetail.setTel(number, ContactDetail.DetailKeyTypes.CELL);
// phoneDetail.nativeContactId = mTestModule.GenerateRandomInt();
phoneDetail.nativeContactId = nicknameDetail.nativeContactId;
status = ContactDetailsTable.addContactDetail(phoneDetail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
addedDetails.add(phoneDetail);
// create and add phoneDetail
ContactDetail emailDetail = new ContactDetail();
emailDetail.localContactID = contact.localContactID;
emailDetail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
emailDetail.setEmail(TestModule.generateRandomString() + "@mail.co.uk", ContactDetail.DetailKeyTypes.HOME);
// emailDetail.nativeContactId = mTestModule.GenerateRandomInt();
emailDetail.nativeContactId = nicknameDetail.nativeContactId;
status = ContactDetailsTable.addContactDetail(emailDetail, true, true, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
addedDetails.add(emailDetail);
ContactDetail.DetailKeys[] keyList = { ContactDetail.DetailKeys.VCARD_NICKNAME, ContactDetail.DetailKeys.VCARD_PHONE, ContactDetail.DetailKeys.VCARD_EMAIL };
List<ContactDetail> detailList = new ArrayList<ContactDetail>();
assertTrue(ContactDetailsTable.fetchContactDetailsForNative(detailList, keyList, false, 0, MAX_MODIFY_NOWPLUS_DETAILS_COUNT, readableDb));
for (int i = 0; i < detailList.size(); i++) {
assertTrue(DatabaseHelper.doDetailsMatch(detailList.get(i), addedDetails.get(i)));
}
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
}
Aggregations