use of com.vodafone360.people.datatypes.ContactDetail 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.ContactDetail 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.ContactDetail 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.ContactDetail in project 360-Engine-for-Android by 360.
the class ContactSummaryTable method getDisplayNameDetail.
/**
* Retrieves display name detail for a contact
* @param contact Contact to retrieve display name from
* @return Found display name detail - maybe be null
*/
private static ContactDetail getDisplayNameDetail(Contact contact) {
// These two Arrays contains the order in which the details are queried.
// First valid (not empty or unknown) detail is taken
ContactDetail.DetailKeys[] preferredNameDetails = { ContactDetail.DetailKeys.VCARD_NAME, ContactDetail.DetailKeys.VCARD_ORG, ContactDetail.DetailKeys.VCARD_EMAIL, ContactDetail.DetailKeys.VCARD_PHONE };
ContactDetail name = null;
// Query the details for the name field
for (ContactDetail.DetailKeys key : preferredNameDetails) {
if ((name = contact.getContactDetail(key)) != null) {
// (gmail for example)
if (key == ContactDetail.DetailKeys.VCARD_NAME && name.getName() == null)
continue;
if (key != ContactDetail.DetailKeys.VCARD_NAME && TextUtils.isEmpty(name.getValue()))
continue;
break;
}
}
return name;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method mergeContactDetails.
/**
* Moves native details ownership from the duplicate contact to the original
* contact.
*
* @param info the info for duplicated and original contacts
* @param nativeInfoList the list of native details from the duplicated
* contact
* @param writableDb A writable SQLite database object
* @return SUCCESS or a suitable error code.
*/
public static ServiceStatus mergeContactDetails(ContactIdInfo info, List<ContactDetail> nativeInfoList, SQLiteDatabase writableDb) {
DatabaseHelper.trace(true, "ContactDetailsTable.mergeContactDetails()");
/**
* Used to hold some contact details info.
*/
final class DetailsInfo {
/**
* The detail local id.
*/
public Long localId;
/**
* The detail server id.
*/
public Long serverId;
public DetailsInfo(Long localId, Long serverId) {
this.localId = localId;
this.serverId = serverId;
}
}
// the list of details from the original contact
List<DetailsInfo> detailLocalIds = new ArrayList<DetailsInfo>();
// the result cursor from the original contact details query
Cursor cursor = null;
try {
// Retrieve a list of detail local IDs from the merged contact
// (original one)
final String[] args = { String.valueOf(info.mergedLocalId) };
cursor = writableDb.rawQuery(QUERY_DETAIL_LOCAL_AND_SERVER_IDS_BY_LOCAL_CONTACT_ID, args);
while (cursor.moveToNext()) {
if (!cursor.isNull(0) && !cursor.isNull(1)) {
// only adding details with a detailServerId (Name and
// Nickname don't have detailServerIds)
detailLocalIds.add(new DetailsInfo(cursor.getLong(0), cursor.getLong(1)));
}
}
DatabaseHelper.trace(true, "ContactDetailsTable.mergeContactDetails(): detailLocalIds.size()=" + detailLocalIds.size());
} catch (Exception e) {
LogUtils.logE("ContactDetailsTable.mergeContactDetails() Exception - " + "Unable to query merged contact details list", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
try {
final ContentValues cv = new ContentValues();
// duplicated contact to the original contact
for (int infoListIndex = 0; infoListIndex < nativeInfoList.size(); infoListIndex++) {
final ContactDetail detailInfo = nativeInfoList.get(infoListIndex);
// Change the ownership
for (int detailsIndex = 0; detailsIndex < detailLocalIds.size(); detailsIndex++) {
final DetailsInfo currentDetails = detailLocalIds.get(detailsIndex);
if (currentDetails.serverId.equals(detailInfo.unique_id)) {
cv.put(Field.LOCALCONTACTID.toString(), info.mergedLocalId);
cv.put(Field.NATIVECONTACTID.toString(), detailInfo.nativeContactId);
cv.put(Field.NATIVEDETAILID.toString(), detailInfo.nativeDetailId);
cv.put(Field.NATIVEDETAILVAL1.toString(), detailInfo.nativeVal1);
cv.put(Field.NATIVEDETAILVAL2.toString(), detailInfo.nativeVal2);
cv.put(Field.NATIVEDETAILVAL3.toString(), detailInfo.nativeVal3);
cv.put(Field.NATIVESYNCCONTACTID.toString(), detailInfo.syncNativeContactId);
DatabaseHelper.trace(true, "ContactDetailsTable.mergeContactDetails():" + " changing ownership for duplicated detail: " + detailInfo);
writableDb.update(TABLE_NAME, cv, Field.DETAILLOCALID + "=" + currentDetails.localId, null);
cv.clear();
detailLocalIds.remove(detailsIndex);
break;
}
}
}
return ServiceStatus.SUCCESS;
} catch (SQLException e) {
LogUtils.logE("ContactDetailsTable.mergeContactDetails() SQLException - " + "Unable to merge contact detail native info", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
}
Aggregations