use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class DatabaseHelper method syncDeleteContactDetailList.
/***
* Function used by the contact sync engine to delete a list of contact
* details from the database.
*
* @param contactDetailList The list of details which has been deleted on
* 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
* @param meProfile - TRUE if the added contact is Me profile.
* @return SUCCESS or a suitable error code
* @see #deleteContactDetail(long)
*/
public ServiceStatus syncDeleteContactDetailList(List<ContactDetail> contactDetailList, boolean syncToServer, boolean syncToNative) {
if (Settings.ENABLED_DATABASE_TRACE)
trace(false, "DatabaseHelper.syncDeleteContactDetailList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
syncToServer = false;
}
if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
syncToNative = false;
}
SQLiteDatabase db = getWritableDatabase();
boolean needFireDbUpdate = false;
for (ContactDetail contactDetail : contactDetailList) {
if ((contactDetail.serverContactId == null) || (contactDetail.serverContactId == -1)) {
ContactsTable.ContactIdInfo contactIdInfo = ContactsTable.validateContactId(contactDetail.localContactID, db);
if (contactIdInfo == null) {
return ServiceStatus.ERROR_NOT_FOUND;
}
contactDetail.nativeContactId = contactIdInfo.nativeId;
contactDetail.serverContactId = contactIdInfo.serverId;
}
try {
db.beginTransaction();
if (syncToNative) {
if (!NativeChangeLogTable.addDeletedContactDetailChange(contactDetail, db)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
if (syncToServer) {
if (!ContactChangeLogTable.addDeletedContactDetailChange(contactDetail, syncToServer, db)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
if (!ContactDetailsTable.deleteDetailByDetailId(contactDetail.localDetailID, db)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
// in order not to override the new picture before it is uploaded.
if (contactDetail.key == ContactDetail.DetailKeys.PHOTO && TextUtils.isEmpty(contactDetail.photo_url)) {
ContactSummaryTable.modifyPictureLoadedFlag(contactDetail.localContactID, false, db);
deleteThumbnail(contactDetail.localContactID);
}
String displayName = updateContactNameInSummary(db, contactDetail.localContactID, SyncMeDbUtils.isMeProfile(this, contactDetail.localContactID));
if (displayName == null) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
if (updateTimelineNames(contactDetail, displayName, contactDetail.localContactID, 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 syncDeleteContactList.
/***
* Function used by the contact sync engine to delete a list of contacts
* from the database.
*
* @param contactIdList The list of contact IDs received from the server (at
* least localId should be set)
* @param syncToServer true if the contacts need to be deleted from the
* server
* @param syncToNative true if the contacts need to be deleted from the
* native phonebook
* @return SUCCESS or a suitable error code
* @see #deleteContact(long)
*/
public ServiceStatus syncDeleteContactList(List<ContactsTable.ContactIdInfo> contactIdList, boolean syncToServer, boolean syncToNative) {
if (Settings.ENABLED_DATABASE_TRACE)
trace(false, "DatabaseHelper.syncDeleteContactList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
syncToServer = false;
}
if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
syncToNative = false;
}
SQLiteDatabase writableDb = getWritableDatabase();
for (ContactsTable.ContactIdInfo contactIdInfo : contactIdList) {
try {
writableDb.beginTransaction();
if (syncToNative && contactIdInfo.mergedLocalId == null) {
if (!NativeChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.nativeId, writableDb)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
if (syncToServer) {
if (!ContactChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.serverId, syncToServer, writableDb)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
if (!ContactGroupsTable.deleteContact(contactIdInfo.localId, writableDb)) {
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
if (SyncMeDbUtils.getMeProfileLocalContactId(this) != null && SyncMeDbUtils.getMeProfileLocalContactId(this).longValue() == contactIdInfo.localId) {
ServiceStatus status = StateTable.modifyMeProfileID(null, writableDb);
if (ServiceStatus.SUCCESS != status) {
return status;
}
SyncMeDbUtils.setMeProfileId(null);
PresenceDbUtils.resetMeProfileIds();
}
ServiceStatus status = ContactSummaryTable.deleteContact(contactIdInfo.localId, writableDb);
if (ServiceStatus.SUCCESS != status) {
return status;
}
status = ContactDetailsTable.deleteDetailByContactId(contactIdInfo.localId, writableDb);
if (ServiceStatus.SUCCESS != status && ServiceStatus.ERROR_NOT_FOUND != status) {
return status;
}
status = ContactsTable.deleteContact(contactIdInfo.localId, writableDb);
if (ServiceStatus.SUCCESS != status) {
return status;
}
if (!deleteThumbnail(contactIdInfo.localId))
LogUtils.logE("Not able to delete thumbnail for: " + contactIdInfo.localId);
// timeline
ActivitiesTable.removeTimelineContactData(contactIdInfo.localId, writableDb);
writableDb.setTransactionSuccessful();
} finally {
writableDb.endTransaction();
}
}
return ServiceStatus.SUCCESS;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method addContact.
/**
* Adds contact summary information to the table for a new contact. If the
* contact has no name or no status, an alternative detail will be used such
* as telephone number or email address.
*
* @param contact The new contact
* @param writableDb Writable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus addContact(Contact contact, SQLiteDatabase writableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(true, "ContactSummeryTable.addContact() contactID[" + contact.contactID + "]");
}
if (contact.localContactID == null) {
LogUtils.logE("ContactSummeryTable.addContact() Invalid parameters");
return ServiceStatus.ERROR_NOT_FOUND;
}
try {
final ContentValues values = new ContentValues();
values.put(Field.LOCALCONTACTID.toString(), contact.localContactID);
values.put(Field.NATIVEID.toString(), contact.nativeContactId);
values.put(Field.FRIENDOFMINE.toString(), contact.friendOfMine);
values.put(Field.SYNCTOPHONE.toString(), contact.synctophone);
ContactDetail altDetail = findAlternativeNameContactDetail(values, contact.details);
updateAltValues(values, altDetail);
addToPresenceMap(contact.localContactID);
if (writableDb.insertOrThrow(TABLE_NAME, null, values) < 0) {
LogUtils.logE("ContactSummeryTable.addContact() " + "Unable to insert new contact summary");
return ServiceStatus.ERROR_NOT_FOUND;
}
return ServiceStatus.SUCCESS;
} catch (SQLException e) {
LogUtils.logE("ContactSummeryTable.addContact() SQLException - " + "Unable to insert new contact summary", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method updateContactDisplayName.
/**
* Updates the summary for a contact Replaces the complex logic of updating
* the summary with a new contactdetail. Instead the method gets a whole
* contact after it has been modified and builds the summary infos.
*
* @param contact A Contact object that has been modified
* @param writeableDb Writable SQLite database
* @param isMeProfile Specifies if the contact in question is the Me Contact or not
* @return String - the contact name to display and null in case of database error.
*/
public static String updateContactDisplayName(Contact contact, SQLiteDatabase writableDb, boolean isMeProfile) {
ContactDetail name = getDisplayNameDetail(contact);
String nameString = null;
if (isVcardNameDetail(name)) {
nameString = name.getName().toString();
} else if (!isMeProfile) {
if (name != null) {
// Apply non VCard name
nameString = name.getValue();
}
if (nameString == null) {
// Unknown name
nameString = ContactDetail.UNKNOWN_NAME;
}
} else {
// Me Profile with no name - set the default name
nameString = SyncMeDbUtils.ME_PROFILE_DEFAULT_NAME;
}
// Start updating the table
SQLiteStatement statement = null;
try {
final StringBuffer updateQuery = StringBufferPool.getStringBuffer(SQLKeys.UPDATE);
updateQuery.append(TABLE_NAME).append(SQLKeys.SET).append(Field.DISPLAYNAME).append("=?, ").append(Field.SEARCHNAME).append("=?").append(" WHERE ").append(Field.LOCALCONTACTID).append("=?");
statement = writableDb.compileStatement(StringBufferPool.toStringThenRelease(updateQuery));
writableDb.beginTransaction();
statement.bindString(1, nameString);
//need to update the Field.SEARCHNAME too.
statement.bindString(2, nameString.toLowerCase());
statement.bindLong(3, contact.localContactID);
statement.execute();
writableDb.setTransactionSuccessful();
} catch (SQLException e) {
LogUtils.logE("ContactSummaryTable.updateNameAndStatus() " + "SQLException - Unable to update contact native Ids", e);
return null;
} finally {
writableDb.endTransaction();
if (statement != null) {
statement.close();
statement = null;
}
}
return nameString;
}
use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method syncSetNativeIds.
/**
* Updates the native IDs for a list of contacts.
*
* @param contactIdList A list of ContactIdInfo objects. For each object,
* the local ID must match a local contact ID in the table. The
* Native ID will be used for the update. Other fields are
* unused.
* @param writeableDb Writable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus syncSetNativeIds(List<ContactIdInfo> contactIdList, SQLiteDatabase writableDb) {
DatabaseHelper.trace(true, "ContactSummaryTable.syncSetNativeIds()");
if (contactIdList.size() == 0) {
return ServiceStatus.SUCCESS;
}
final SQLiteStatement statement1 = writableDb.compileStatement("UPDATE " + TABLE_NAME + " SET " + Field.NATIVEID + "=? WHERE " + Field.LOCALCONTACTID + "=?");
for (int i = 0; i < contactIdList.size(); i++) {
final ContactIdInfo info = contactIdList.get(i);
try {
writableDb.beginTransaction();
if (info.nativeId == null) {
statement1.bindNull(1);
} else {
statement1.bindLong(1, info.nativeId);
}
statement1.bindLong(2, info.localId);
statement1.execute();
writableDb.setTransactionSuccessful();
} catch (SQLException e) {
LogUtils.logE("ContactSummaryTable.syncSetNativeIds() " + "SQLException - Unable to update contact native Ids", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
writableDb.endTransaction();
}
}
return ServiceStatus.SUCCESS;
}
Aggregations