use of com.vodafone360.people.service.ServiceStatus 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.service.ServiceStatus 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.service.ServiceStatus 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.service.ServiceStatus in project 360-Engine-for-Android by 360.
the class DatabaseHelper method updateContactNameInSummary.
/**
* Updates the ContactSummary table with the new/changed Contact.
* @param writableDatabase - SQLiteDatabase writable database.
* @param localContactId - long contact local id.
* @param isMeProfile - boolean that indicates if the localContactId belongs to Me Profile.
* @return The updated name, may be null in failure situations
*/
public String updateContactNameInSummary(SQLiteDatabase writableDatabase, long localContactId, boolean isMeProfile) {
Contact contact = new Contact();
ServiceStatus status = fetchBaseContact(localContactId, contact, writableDatabase);
if (ServiceStatus.SUCCESS != status) {
return null;
}
status = ContactDetailsTable.fetchContactDetails(localContactId, contact.details, writableDatabase);
if (ServiceStatus.SUCCESS != status) {
return null;
}
return ContactSummaryTable.updateContactDisplayName(contact, writableDatabase, isMeProfile);
}
use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.
the class DatabaseHelper method addActivities.
/**
* Add a list of new activities to the Activities table.
*
* @param activityList contains the list of activity item
* @return SUCCESS or a suitable error code
* @see #deleteActivities(Integer)
*/
public ServiceStatus addActivities(List<ActivityItem> activityList) {
SQLiteDatabase writableDb = getWritableDatabase();
ServiceStatus status = ActivitiesTable.addActivities(activityList, writableDb, mContext);
ActivitiesTable.cleanupActivityTable(writableDb);
fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, true);
return status;
}
Aggregations