use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class DatabaseHelper method syncModifyContactDetailList.
/**
* Function used by the contact sync engine to modify a list of contact
* details in the database.
*
* @param contactDetailList The list of details received from the server
* @param serverIdList A list of server IDs if known, or null
* @param syncToServer true if the details need to be sent to the server
* @param syncToNative true if the contacts need to be added to the native
* phonebook
* @return SUCCESS or a suitable error code
* @see #modifyContactDetail(ContactDetail)
*/
public ServiceStatus syncModifyContactDetailList(List<ContactDetail> contactDetailList, boolean syncToServer, boolean syncToNative) {
if (Settings.ENABLED_DATABASE_TRACE)
trace(false, "DatabaseHelper.syncModifyContactDetailList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
syncToServer = false;
}
if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
syncToNative = false;
}
boolean needFireDbUpdate = false;
SQLiteDatabase db = getWritableDatabase();
for (ContactDetail contactDetail : contactDetailList) {
ContactsTable.ContactIdInfo contactIdInfo = ContactsTable.validateContactId(contactDetail.localContactID, db);
if (contactIdInfo == null) {
return ServiceStatus.ERROR_NOT_FOUND;
}
contactDetail.serverContactId = contactIdInfo.serverId;
if (contactIdInfo.syncToPhone) {
contactDetail.syncNativeContactId = contactIdInfo.nativeId;
} else {
contactDetail.syncNativeContactId = -1;
}
try {
db.beginTransaction();
if (contactDetail.order != null && contactDetail.order.equals(ContactDetail.ORDER_PREFERRED)) {
ContactDetailsTable.removePreferred(contactDetail.localContactID, contactDetail.key, db);
}
ServiceStatus status = ContactDetailsTable.modifyDetail(contactDetail, syncToServer, syncToNative, db);
if (ServiceStatus.SUCCESS != status) {
return status;
}
// in order not to override the new picture before it is uploaded.
if (ContactDetail.DetailKeys.PHOTO == contactDetail.key && TextUtils.isEmpty(contactDetail.photo_url)) {
ContactSummaryTable.modifyPictureLoadedFlag(contactDetail.localContactID, false, db);
}
String displayName = updateContactNameInSummary(db, contactDetail.localContactID, SyncMeDbUtils.isMeProfile(this, contactDetail.localContactID));
if (null == displayName) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
if (updateTimelineNames(contactDetail, displayName, null, db)) {
needFireDbUpdate = true;
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (needFireDbUpdate) {
fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, false);
}
return ServiceStatus.SUCCESS;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class DatabaseHelper method modifyContactDetail.
/**
* Modifies an existing contact detail in the database. Also fires an
* internal database change event.
*
* @param detail A {@link ContactDetail} object which contains the detail to add
*
* @return SUCCESS or a suitable error code
* @see #addContactDetail(ContactDetail)
* @see #deleteContactDetail(long)
* @see #addContact(Contact)
* @see #deleteContact(long)
* @see #addContactToGroup(long, long)
* @see #deleteContactFromGroup(long, long)
*/
public ServiceStatus modifyContactDetail(ContactDetail detail) {
if (Settings.ENABLED_DATABASE_TRACE) {
trace(false, "DatabaseHelper.modifyContactDetail() name[" + detail.getName() + "]");
}
boolean isMeProfile = SyncMeDbUtils.isMeProfile(this, detail.localContactID);
List<ContactDetail> detailList = new ArrayList<ContactDetail>();
detailList.add(detail);
ServiceStatus status = syncModifyContactDetailList(detailList, !isMeProfile, !isMeProfile);
if (ServiceStatus.SUCCESS == status) {
fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
if (isMeProfile) {
WidgetUtils.kickWidgetUpdateNow(mContext);
}
}
return status;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class DatabaseHelper method syncMergeContactList.
/**
* Function used by the contact sync engine to merge contacts which are
* marked as duplicate by the server. This involves moving native
* information from one contact to the other, before deleting it.
*
* @param contactIdList The list of contact IDs (localId, serverId and
* mergedLocalId should be set)
* @return SUCCESS or a suitable error code
*/
public ServiceStatus syncMergeContactList(List<ContactsTable.ContactIdInfo> contactIdList) {
if (Settings.ENABLED_DATABASE_TRACE)
trace(false, "DatabaseHelper.syncMergeContactList()");
List<ContactDetail> detailInfoList = new ArrayList<ContactDetail>();
SQLiteDatabase writableDb = getWritableDatabase();
SQLiteStatement contactStatement = null, contactSummaryStatement = null;
try {
contactStatement = ContactsTable.mergeContactStatement(writableDb);
contactSummaryStatement = ContactSummaryTable.mergeContactStatement(writableDb);
writableDb.beginTransaction();
for (int i = 0; i < contactIdList.size(); i++) {
ContactsTable.ContactIdInfo contactIdInfo = contactIdList.get(i);
if (contactIdInfo.mergedLocalId != null) {
contactIdInfo.nativeId = ContactsTable.fetchNativeFromLocalId(writableDb, contactIdInfo.localId);
LogUtils.logI("DatabaseHelper.syncMergeContactList - Copying native Ids from duplicate to original contact: Dup ID " + contactIdInfo.localId + ", Org ID " + contactIdInfo.mergedLocalId + ", Nat ID " + contactIdInfo.nativeId);
ServiceStatus status = ContactsTable.mergeContact(contactIdInfo, contactStatement);
if (status != ServiceStatus.SUCCESS) {
return status;
}
status = ContactSummaryTable.mergeContact(contactIdInfo, contactSummaryStatement);
if (status != ServiceStatus.SUCCESS) {
return status;
}
status = ContactDetailsTable.fetchNativeInfo(contactIdInfo.localId, detailInfoList, writableDb);
if (status != ServiceStatus.SUCCESS) {
return status;
}
status = ContactDetailsTable.mergeContactDetails(contactIdInfo, detailInfoList, writableDb);
if (status != ServiceStatus.SUCCESS) {
return status;
}
}
}
writableDb.setTransactionSuccessful();
} finally {
writableDb.endTransaction();
if (contactStatement != null) {
contactStatement.close();
contactStatement = null;
}
if (contactSummaryStatement != null) {
contactSummaryStatement.close();
contactSummaryStatement = null;
}
}
LogUtils.logI("DatabaseHelper.syncMergeContactList - Deleting duplicate contacts");
return syncDeleteContactList(contactIdList, false, true);
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class DatabaseHelper method fetchContact.
/**
* Fetches a contact from the database by its localContactId. The method
* {@link #fetchBaseContact(long, Contact)} should be used if the contact
* details properties are not required.
*
* @param localContactId Local ID of the contact to fetch.
* @param contact Empty {@link Contact} object which will be populated with
* data.
* @return SUCCESS or a suitable ServiceStatus error code.
*/
public synchronized ServiceStatus fetchContact(long localContactId, Contact contact) {
SQLiteDatabase db = getReadableDatabase();
ServiceStatus status = fetchBaseContact(localContactId, contact, db);
if (ServiceStatus.SUCCESS != status) {
return status;
}
status = ContactDetailsTable.fetchContactDetails(localContactId, contact.details, db);
if (ServiceStatus.SUCCESS != status) {
return status;
}
return ServiceStatus.SUCCESS;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class DatabaseHelper method addContactDetail.
/**
* Adds a contact detail to the database and fires an internal database
* change event.
*
* @param detail A {@link ContactDetail} object which contains the detail to
* add
* @return SUCCESS or a suitable error code
* @see #modifyContactDetail(ContactDetail)
* @see #deleteContactDetail(long)
* @see #addContact(Contact)
* @see #deleteContact(long)
* @see #addContactToGroup(long, long)
* @see #deleteContactFromGroup(long, long)
* @throws NullPointerException When detail is NULL
*/
public ServiceStatus addContactDetail(ContactDetail detail) {
if (Settings.ENABLED_DATABASE_TRACE) {
trace(false, "DatabaseHelper.addContactDetail() name[" + detail.getName() + "]");
}
if (detail == null) {
throw new NullPointerException("DatabaseHelper.addContactDetail() detail should not be NULL");
}
boolean isMeProfile = (SyncMeDbUtils.getMeProfileLocalContactId(this) != null && detail.localContactID != null && detail.localContactID.equals(SyncMeDbUtils.getMeProfileLocalContactId(this)));
List<ContactDetail> detailList = new ArrayList<ContactDetail>();
detailList.add(detail);
ServiceStatus status = syncAddContactDetailList(detailList, !isMeProfile, !isMeProfile);
if (status == ServiceStatus.SUCCESS) {
fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
if (isMeProfile) {
WidgetUtils.kickWidgetUpdateNow(mContext);
}
}
return status;
}
Aggregations