use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class ContactSyncEngine method setFirstTimeNativeSyncComplete.
/**
* Helper function to update the database when the state of the
* {@link #mFirstTimeNativeSyncComplete} flag changes.
*
* @param value New value to the flag. True indicates that the native fetch
* part of the 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 setFirstTimeNativeSyncComplete(boolean value) {
if (mFirstTimeSyncComplete == value) {
return ServiceStatus.SUCCESS;
}
PersistSettings setting = new PersistSettings();
setting.putFirstTimeNativeSyncComplete(value);
ServiceStatus status = mDb.setOption(setting);
if (ServiceStatus.SUCCESS == status) {
mFirstTimeNativeSyncComplete = value;
}
return status;
}
use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class PeopleContactsApi method getContact.
/**
* Gets a contact from its native id.
*
* @param nativeId the native id of the contact
* @return an array of ContactChange representing the contact, null if not found
*/
public ContactChange[] getContact(long nativeId) {
try {
final SQLiteDatabase readableDb = mDbh.getReadableDatabase();
if (NativeChangeLogTable.isContactChangeInList(nativeId, ContactChangeType.DELETE_CONTACT, readableDb)) {
// the contact exists as a deleted contact in the NativeChangeLogTable
// return one ContactChange with the deleted contact flag
ContactChange[] changes = new ContactChange[1];
changes[0] = new ContactChange(ContactChange.TYPE_DELETE_CONTACT);
return changes;
} else {
// get the corresponding local contact id
final ContactIdInfo info = ContactsTable.fetchContactIdFromNative((int) nativeId, readableDb);
if (info != null) {
// we found the contact on CAB, let's get the details
final ContactChange[] existingDetails = ContactDetailsTable.getContactChanges((long) info.localId, false, readableDb);
// get also the deleted details if any
final ContactChange[] deletedDetails = NativeChangeLogTable.getDeletedDetails((long) info.localId, readableDb);
if (existingDetails != null && deletedDetails != null) {
// merge both arrays
ContactChange[] mergedDetails = new ContactChange[existingDetails.length + deletedDetails.length];
System.arraycopy(existingDetails, 0, mergedDetails, 0, existingDetails.length);
System.arraycopy(deletedDetails, 0, mergedDetails, existingDetails.length, deletedDetails.length);
return mergedDetails;
} else if (existingDetails != null) {
return existingDetails;
} else {
return deletedDetails;
}
}
}
} catch (Exception e) {
LogUtils.logE("getContact(" + nativeId + "), error: " + e);
}
// no contact found
return null;
}
use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class DatabaseHelper method convertContactChange.
/**
* Converts a ContactChange object into an equivalent ContactDetail object.
*
* @see ContactChange
* @see ContactDetail
* @param change the ContactChange to convert
* @return the equivalent ContactDetail
*/
public ContactDetail convertContactChange(ContactChange change) {
final ContactDetail detail = new ContactDetail();
final int flag = change.getFlags();
// conversion is not straightforward, needs a little tweak
final int key = ContactDetailsTable.mapContactChangeKeyToInternalKey(change.getKey());
detail.localContactID = change.getInternalContactId() != ContactChange.INVALID_ID ? change.getInternalContactId() : null;
detail.localDetailID = change.getInternalDetailId() != ContactChange.INVALID_ID ? change.getInternalDetailId() : null;
detail.nativeContactId = change.getNabContactId() != ContactChange.INVALID_ID ? new Integer((int) change.getNabContactId()) : null;
detail.nativeDetailId = change.getNabDetailId() != ContactChange.INVALID_ID ? new Integer((int) change.getNabDetailId()) : null;
detail.unique_id = change.getBackendDetailId() != ContactChange.INVALID_ID ? new Long(change.getBackendDetailId()) : null;
detail.key = DetailKeys.values()[key];
detail.keyType = DetailKeyTypes.values()[ContactDetailsTable.mapContactChangeFlagToInternalType(flag)];
detail.value = change.getValue();
detail.order = ContactDetailsTable.mapContactChangeFlagToInternalOrder(flag);
return detail;
}
use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class DatabaseHelper method modifyPictureLoadedFlag.
/**
* Sets the picture loaded flag and fires a databaseChanged event.
*
* @param localContactId Local contact id of the contact where to set the
* flag
* @param value Value of the flag
* @return true in case everything went fine, false otherwise
*/
public final boolean modifyPictureLoadedFlag(final Long localContactId, final Boolean value) {
ServiceStatus serviceStatus = ContactSummaryTable.modifyPictureLoadedFlag(localContactId, value, getWritableDatabase());
if (ServiceStatus.SUCCESS != serviceStatus) {
return false;
}
fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, true);
return true;
}
use of com.vodafone360.people.datatypes.ActivityItem.Flag in project 360-Engine-for-Android by 360.
the class ContactChangeHelper method randomContactUpdate.
public static ContactChange[] randomContactUpdate(ContactChange[] contact) {
final int originalDetailsNum = contact.length;
final long internalCntId = contact[0].getInternalContactId();
final long backendCntId = contact[0].getBackendContactId();
final long nabCntId = contact[0].getNabContactId();
int numDeletedDetails = 0, curNumDeletedDetails = 0, numAddedDetails = 0, curNumAddedDetails = 0, numChangedDetails = 0, curNumChangedDetails = 0;
// At best we can only delete all but one detail
numDeletedDetails = randomPositiveInt(originalDetailsNum - 1);
// At best we can only change all details minus the ones we will delete
numChangedDetails = randomPositiveInt(originalDetailsNum - numDeletedDetails);
// Reasonable maximum of details we can add
numAddedDetails = randomPositiveInt(MAX_NUM_DETAILS_ADD);
final int updateCcListSize = numAddedDetails + numChangedDetails + numDeletedDetails;
ContactChange[] updateCcList = new ContactChange[updateCcListSize];
for (int i = 0; i < updateCcListSize; i++) {
if (curNumChangedDetails < numChangedDetails) {
updateCcList[i] = generateUpdateDetailChange(contact[i]);
curNumChangedDetails++;
continue;
}
if (curNumDeletedDetails < numDeletedDetails) {
updateCcList[i] = generateDeleteDetailChange(contact[i]);
curNumDeletedDetails++;
continue;
}
if (curNumAddedDetails < numAddedDetails) {
int key;
do {
// get a random key and don't let it be a unique key to simplify things
key = randomKey();
if (isKeyPlatformSupported(key)) {
if (!isUniqueKeyForContact(key) || (isUniqueKeyForContact(key) && !isKeyPresent(key, updateCcList) && !isKeyPresent(key, contact))) {
break;
}
}
} while (true);
// The new detail, preferred flag not allowed to simplify things a little
final ContactChange addDetailCc = randomContactChange(key, internalCntId, backendCntId, nabCntId, false);
//addDetailCc.setInternalDetailId(randomPositiveLong());
addDetailCc.setType(ContactChange.TYPE_ADD_DETAIL);
updateCcList[i] = addDetailCc;
curNumAddedDetails++;
}
}
return updateCcList;
}
Aggregations