use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class LoginEngine method setRegistrationComplete.
/**
* Helper function to set the registration complete flag and update the
* database with the new state.
*
* @param value true if registration is completed
*/
private void setRegistrationComplete(boolean value) {
LogUtils.logD("LoginEngine.setRegistrationComplete(" + value + ")");
if (value != mIsRegistrationComplete) {
StateTable.setRegistrationComplete(value, mDb.getWritableDatabase());
mIsRegistrationComplete = value;
if (mIsRegistrationComplete) {
// Create NAB Account at this point (does nothing on 1.X
// devices)
final NativeContactsApi nabApi = NativeContactsApi.getInstance();
if (!nabApi.isPeopleAccountCreated()) {
// TODO: React upon failure to create account
nabApi.addPeopleAccount(LoginPreferences.getUsername());
}
}
}
}
use of com.vodafone360.people.datatypes.ActivityItem.Flag 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.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testUpdateGetNativeContactWithDelete.
/**
* Tests the updateNativeContact() method when a detail is deleted outside.
*/
public void testUpdateGetNativeContactWithDelete() {
final long NATIVE_ID = 15;
PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
// the database is empty, it shall not return any ids
assertNull(pca.getNativeContactsIds());
// let's add a contact
ContactChange[] contact = filterContactChanges(ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_ID));
assertTrue(pca.addNativeContact(contact));
// check that it exists
long[] ids = pca.getNativeContactsIds();
assertEquals(1, ids.length);
assertEquals(NATIVE_ID, ids[0]);
// get the contact back
ContactChange[] savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
// let's add a detail
ContactChange addedDetail = new ContactChange(ContactChange.KEY_VCARD_PHONE, "+3300000", ContactChange.FLAG_HOME);
addedDetail.setNabContactId(NATIVE_ID);
addedDetail.setType(ContactChange.TYPE_ADD_DETAIL);
addedDetail.setInternalContactId(savedContact[0].getInternalContactId());
ContactChange[] updates = { addedDetail };
pca.updateNativeContact(updates);
// get the contact back
savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
assertEquals(contact.length + 1, savedContact.length);
// find the localId of the detail to delete
int index = findContactChangeIndex(savedContact, addedDetail);
assertTrue(index != -1);
addedDetail.setInternalDetailId(savedContact[index].getInternalDetailId());
// remove the detail as if coming from user or server (i.e. not yet synced to native)
ArrayList<ContactDetail> detailList = new ArrayList<ContactDetail>(1);
detailList.add(mDatabaseHelper.convertContactChange(addedDetail));
mDatabaseHelper.syncDeleteContactDetailList(detailList, false, true);
// get the contact back
savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
// the deleted detail shall be given
assertEquals(contact.length + 1, savedContact.length);
// check that one contact has the deleted flag
int deletedIndex = -1;
int deletedCount = 0;
for (int i = 0; i < savedContact.length; i++) {
if (savedContact[i].getType() == ContactChange.TYPE_DELETE_DETAIL) {
deletedIndex = i;
deletedCount++;
}
}
// there shall be only one deleted detail
assertEquals(1, deletedCount);
assertEquals(addedDetail.getInternalDetailId(), savedContact[deletedIndex].getInternalDetailId());
}
use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class ContactSyncEngine method setFirstTimeSyncComplete.
/**
* Helper function to update the database when the state of the
* {@link #mFirstTimeSyncComplete} flag changes.
*
* @param value New value to the flag. True indicates that first time sync
* has been completed. The flag is never set to false again by
* the engine, it will be only set to false when a remove user
* data is done (and the database is deleted).
* @return SUCCESS or a suitable error code if the database could not be
* updated.
*/
private ServiceStatus setFirstTimeSyncComplete(boolean value) {
if (mFirstTimeSyncComplete == value) {
return ServiceStatus.SUCCESS;
}
PersistSettings setting = new PersistSettings();
setting.putFirstTimeSyncComplete(value);
ServiceStatus status = mDb.setOption(setting);
if (ServiceStatus.SUCCESS == status) {
synchronized (this) {
mFirstTimeSyncComplete = value;
}
}
return status;
}
use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class ContactSyncEngine method setFirstTimeSyncStarted.
/**
* Helper function to update the database when the state of the
* {@link #mFirstTimeSyncStarted} flag changes.
*
* @param value New value to the flag. True indicates that first time sync
* has been started. The flag is never set to false again by the
* engine, it will be only set to false when a remove user data
* is done (and the database is deleted).
* @return SUCCESS or a suitable error code if the database could not be
* updated.
*/
private ServiceStatus setFirstTimeSyncStarted(boolean value) {
if (mFirstTimeSyncStarted == value) {
return ServiceStatus.SUCCESS;
}
PersistSettings setting = new PersistSettings();
setting.putFirstTimeSyncStarted(value);
ServiceStatus status = mDb.setOption(setting);
if (ServiceStatus.SUCCESS == status) {
synchronized (this) {
mFirstTimeSyncStarted = value;
}
}
return status;
}
Aggregations