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;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class DatabaseHelper method deleteContactDetail.
/***
* Deletes a contact detail from the database. Also fires an internal
* database change event.
*
* @param localContactDetailID The local ID of the detail to delete
* @return SUCCESS or a suitable error code
* @see #addContactDetail(ContactDetail)
* @see #modifyContactDetail(ContactDetail)
* @see #addContact(Contact)
* @see #deleteContact(long)
* @see #addContactToGroup(long, long)
* @see #deleteContactFromGroup(long, long)
*/
public ServiceStatus deleteContactDetail(long localContactDetailID) {
if (Settings.ENABLED_DATABASE_TRACE) {
trace(false, "DatabaseHelper.deleteContactDetail() localContactDetailID[" + localContactDetailID + "]");
}
SQLiteDatabase db = getReadableDatabase();
ContactDetail detail = ContactDetailsTable.fetchDetail(localContactDetailID, db);
if (detail == null) {
LogUtils.logE("Database.deleteContactDetail() Unable to find detail for deletion");
return ServiceStatus.ERROR_NOT_FOUND;
}
boolean isMeProfile = false;
if (detail.localContactID.equals(SyncMeDbUtils.getMeProfileLocalContactId(this))) {
isMeProfile = true;
}
List<ContactDetail> detailList = new ArrayList<ContactDetail>();
detailList.add(detail);
ServiceStatus status = syncDeleteContactDetailList(detailList, true, !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 syncModifyContactList.
/***
* Function used by the contact sync engine to modify a list of contacts in
* the database.
*
* @param contactList The list of contacts received from the server
* @param syncToServer true if the contacts need to be sent to the server
* @param syncToNative true if the contacts need to be modified in the
* native phonebook
* @return SUCCESS or a suitable error code
*/
public ServiceStatus syncModifyContactList(List<Contact> contactList, boolean syncToServer, boolean syncToNative) {
if (Settings.ENABLED_DATABASE_TRACE)
trace(false, "DatabaseHelper.syncModifyContactList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
syncToServer = false;
}
if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
syncToNative = false;
}
SQLiteDatabase writableDb = getWritableDatabase();
boolean needFireDbUpdate = false;
for (Contact contact : contactList) {
if (syncToServer) {
contact.updated = null;
}
try {
writableDb.beginTransaction();
ServiceStatus status = ContactsTable.modifyContact(contact, writableDb);
if (ServiceStatus.SUCCESS != status) {
LogUtils.logE("DatabaseHelper.syncModifyContactList() Unable to modify contact, due to a database error");
return status;
}
status = ContactSummaryTable.modifyContact(contact, writableDb);
if (ServiceStatus.SUCCESS != status) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
if (contact.groupList != null) {
status = ContactGroupsTable.modifyContact(contact, writableDb);
if (ServiceStatus.SUCCESS != status) {
return status;
}
}
if (contact.sources != null) {
if (!ContactSourceTable.deleteAllContactSources(contact.localContactID, writableDb)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
for (String source : contact.sources) {
if (!ContactSourceTable.addContactSource(contact.localContactID, source, writableDb)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
}
// END updating timeline events
// Update the summary with the new contact
String displayName = updateContactNameInSummary(writableDb, contact.localContactID, SyncMeDbUtils.isMeProfile(this, contact.localContactID));
if (null == displayName) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
// updating phone no
for (ContactDetail detail : contact.details) {
detail.localContactID = contact.localContactID;
detail.nativeContactId = contact.nativeContactId;
if (updateTimelineNames(detail, displayName, contact.contactID, writableDb)) {
needFireDbUpdate = true;
}
}
writableDb.setTransactionSuccessful();
} finally {
writableDb.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 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;
}
Aggregations