use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class ContactChangeHelper method areChangesEqual.
public static boolean areChangesEqual(ContactChange a, ContactChange b, boolean compareAll) {
if (a.getKey() != b.getKey()) {
return false;
}
// just for convenience
final int key = a.getKey();
if (!VersionUtils.is2XPlatform() && key == ContactChange.KEY_VCARD_NAME) {
// Need to convert to raw string or else we can't compare them because of NAB 1.X limitations
final Name nameA = VCardHelper.getName(a.getValue());
final Name nameB = VCardHelper.getName(b.getValue());
final String nameAStr = nameA.toString();
final String nameBStr = nameB.toString();
if (!TextUtils.equals(nameAStr, nameBStr)) {
return false;
}
} else if (!VersionUtils.is2XPlatform() && key == ContactChange.KEY_VCARD_ADDRESS) {
// Need to convert to raw string or else we can't compare them because of NAB 1.X limitations
final PostalAddress addressA = VCardHelper.getPostalAddress(a.getValue());
final PostalAddress addressB = VCardHelper.getPostalAddress(b.getValue());
// Need to also remove \n's that were put there by .toString
final String addressAStr = addressA.toString().replaceAll("\n", "");
final String addressBStr = addressB.toString().replaceAll("\n", "");
if (!TextUtils.equals(addressAStr, addressBStr)) {
return false;
}
} else if (!VersionUtils.is2XPlatform() && key == ContactChange.KEY_VCARD_ORG) {
// Org on 1.X does not support department, need to NOT compare that
final Organisation orgA = VCardHelper.getOrg(a.getValue());
final Organisation orgB = VCardHelper.getOrg(b.getValue());
if (!TextUtils.equals(orgA.name, orgB.name)) {
return false;
}
} else if (!TextUtils.equals(a.getValue(), b.getValue())) {
return false;
}
switch(key) {
case ContactChange.KEY_VCARD_ORG:
case ContactChange.KEY_VCARD_TITLE:
case ContactChange.KEY_VCARD_PHONE:
case ContactChange.KEY_VCARD_EMAIL:
case ContactChange.KEY_VCARD_ADDRESS:
// NAB may have changed these fields to preferred even though they were inserted as not preferred!
final int flagsWithoutPreferredA = a.getFlags() & ~ContactChange.FLAG_PREFERRED;
final int flagsWithoutPreferredB = b.getFlags() & ~ContactChange.FLAG_PREFERRED;
if (flagsWithoutPreferredA != flagsWithoutPreferredB) {
return false;
}
break;
default:
if (a.getFlags() != b.getFlags()) {
return false;
}
break;
}
if (VersionUtils.is2XPlatform() && a.getFlags() != b.getFlags()) {
return false;
} else if (!VersionUtils.is2XPlatform()) {
}
if (compareAll) {
if (a.getType() != b.getType()) {
return false;
}
if (a.getInternalContactId() != b.getInternalContactId()) {
return false;
}
if (a.getInternalDetailId() != b.getInternalDetailId()) {
return false;
}
if (a.getBackendContactId() != b.getBackendContactId()) {
return false;
}
if (a.getBackendDetailId() != b.getBackendDetailId()) {
return false;
}
if (a.getNabContactId() != b.getNabContactId()) {
return false;
}
if (a.getNabDetailId() != b.getNabDetailId()) {
return false;
}
}
return true;
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method fetchContactInfo.
/**
* Finds a phone contact detail which matches a given telephone number. Uses
* the native Android functionality for matching the numbers.
*
* @param phoneNumber The number to find
* @param phoneDetail An empty contact detail where the resulting phone
* contact detail will be stored.
* @param nameDetail An empty contact detail where the resulting name
* contact detail will be stored.
* @param readableDb A readable SQLite database object.
* @return SUCCESS or a suitable error code.
*/
public static ServiceStatus fetchContactInfo(String phoneNumber, ContactDetail phoneDetail, ContactDetail nameDetail, SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "ContactDetailsTable.fetchContactInfo() phoneNumber[" + phoneNumber + "]");
if (phoneNumber == null) {
return ServiceStatus.ERROR_NOT_FOUND;
}
Cursor c2 = null;
final String searchNumber = DatabaseUtils.sqlEscapeString(phoneNumber);
try {
String[] args = { String.format("%d", ContactDetail.DetailKeys.VCARD_PHONE.ordinal()) };
c2 = readableDb.rawQuery(getQueryStringSql(Field.KEY + "=? AND PHONE_NUMBERS_EQUAL(" + Field.STRINGVAL + "," + searchNumber + ")"), args);
if (!c2.moveToFirst()) {
return ServiceStatus.ERROR_NOT_FOUND;
}
phoneDetail.copy(getQueryData(c2));
if (nameDetail != null) {
ContactDetail fetchedNameDetail = fetchDetail(phoneDetail.localContactID, ContactDetail.DetailKeys.VCARD_NAME, readableDb);
if (fetchedNameDetail != null) {
nameDetail.copy(fetchedNameDetail);
}
}
} catch (SQLiteException e) {
LogUtils.logE("ContactDetailsTable.fetchContactInfo() Exception - Unable to fetch contact detail", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
CloseUtils.close(c2);
c2 = null;
}
return ServiceStatus.SUCCESS;
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method findNativeContact.
/**
* Searches the contact details table for a contact from the native
* phonebook. If a match is found, the native sync information is transfered
* from the given contact into the matching database contact. Tries to match
* in the following sequence: 1) If there is a name, match by name 2)
* Otherwise, if there is a phone number, match by number 3) Otherwise, if
* there is an email, match by email 4) Otherwise return false For a match
* to occur, all given contact details must be identical to those in the
* database. There may be more details in the database but this won't change
* the result.
*
* @param c The contact to match
* @param writableDb A writable SQLite database object
* @return true if the contact was found, false otherwise
*/
public static boolean findNativeContact(Contact c, SQLiteDatabase writableDb) {
String name = null;
String phone = null;
String email = null;
List<ContactIdInfo> contactIdList = new ArrayList<ContactIdInfo>();
List<NativeIdInfo> detailIdList = new ArrayList<NativeIdInfo>();
for (int i = 0; i < c.details.size(); i++) {
if (c.details.get(i).key == ContactDetail.DetailKeys.VCARD_NICKNAME) {
name = c.details.get(i).getValue();
if (name != null && name.length() > 0) {
break;
}
}
if (c.details.get(i).key == ContactDetail.DetailKeys.VCARD_PHONE) {
if (phone == null || phone.length() > 0) {
phone = c.details.get(i).getValue();
}
}
if (c.details.get(i).key == ContactDetail.DetailKeys.VCARD_EMAIL) {
if (email == null || email.length() > 0) {
email = c.details.get(i).getValue();
}
}
}
Cursor candidateListCursor = null;
if (name != null && name.length() > 0) {
LogUtils.logD("ContactDetailsTable.findNativeContact - " + "Searching for contact called " + name);
candidateListCursor = findDetailByKey(name, ContactDetail.DetailKeys.VCARD_NICKNAME, writableDb);
} else if (phone != null && phone.length() > 0) {
LogUtils.logD("ContactDetailsTable.findNativeContact - " + "Searching for contact with phone " + phone);
candidateListCursor = findDetailByKey(phone, ContactDetail.DetailKeys.VCARD_PHONE, writableDb);
} else if (email != null && email.length() > 0) {
LogUtils.logD("ContactDetailsTable.findNativeContact - " + "Searching for contact with email " + email);
candidateListCursor = findDetailByKey(email, ContactDetail.DetailKeys.VCARD_EMAIL, writableDb);
}
List<NativeIdInfo> tempDetailIdList = new ArrayList<NativeIdInfo>();
List<NativeIdInfo> currentDetailIdList = new ArrayList<NativeIdInfo>();
Integer minNoOfDetails = null;
Long chosenContactId = null;
if (candidateListCursor != null) {
while (candidateListCursor.moveToNext()) {
long localContactId = candidateListCursor.getLong(1);
tempDetailIdList.clear();
if (doContactsMatch(c, localContactId, tempDetailIdList, writableDb)) {
if (minNoOfDetails == null || minNoOfDetails.intValue() > tempDetailIdList.size()) {
if (ContactsTable.fetchSyncToPhone(localContactId, writableDb)) {
minNoOfDetails = tempDetailIdList.size();
chosenContactId = localContactId;
currentDetailIdList.clear();
currentDetailIdList.addAll(tempDetailIdList);
}
}
}
}
candidateListCursor.close();
if (chosenContactId != null) {
LogUtils.logD("ContactDetailsTable.findNativeContact - " + "Found contact (no need to add)");
ContactIdInfo contactIdInfo = new ContactIdInfo();
contactIdInfo.localId = chosenContactId;
contactIdInfo.nativeId = c.nativeContactId;
contactIdList.add(contactIdInfo);
detailIdList.addAll(currentDetailIdList);
// Update contact IDs of the contacts which are already in the
// database
ServiceStatus status = ContactsTable.syncSetNativeIds(contactIdList, writableDb);
if (ServiceStatus.SUCCESS != status) {
return false;
}
status = ContactSummaryTable.syncSetNativeIds(contactIdList, writableDb);
if (ServiceStatus.SUCCESS != status) {
return false;
}
status = ContactDetailsTable.syncSetNativeIds(detailIdList, writableDb);
if (ServiceStatus.SUCCESS != status) {
return false;
}
return true;
}
}
LogUtils.logD("ContactDetailsTable.findNativeContact - Contact not found (will be added)");
return false;
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class FetchCallLogEvents method addCallLogData.
/**
* Create TimelineSummaryItem from Native call-log item.
*
* @param id ID of item from Native log.
*/
private void addCallLogData(int id) {
TimelineSummaryItem item = new TimelineSummaryItem();
final String phoneNo = mNativeCursor.getString(COLUMN_CALLLOG_PHONE);
item.mNativeItemId = id;
item.mNativeItemType = ActivitiesTable.TimelineNativeTypes.CallLog.ordinal();
item.mType = nativeTypeToNpType(mNativeCursor.getInt(COLUMN_CALLLOG_TYPE));
item.mTimestamp = mNativeCursor.getLong(COLUMN_CALLLOG_DATE);
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
item.mDescription = null;
if (phoneNo.compareToIgnoreCase(NATIVE_NUMBER_UNKNOWN_STRING) != 0 && phoneNo.compareToIgnoreCase(NATIVE_NUMBER_PRIVATE_STRING) != 0) {
item.mContactName = PhoneNumberUtils.formatNumber(phoneNo);
item.mContactAddress = phoneNo;
} else {
item.mContactName = null;
item.mContactAddress = null;
}
Contact c = new Contact();
ContactDetail phoneDetail = new ContactDetail();
ServiceStatus status = mDb.fetchContactInfo(phoneNo, c, phoneDetail);
if (ServiceStatus.SUCCESS == status) {
item.mLocalContactId = c.localContactID;
item.mContactId = c.contactID;
item.mUserId = c.userID;
item.mContactName = null;
for (ContactDetail d : c.details) {
switch(d.key) {
case VCARD_NAME:
final VCardHelper.Name name = d.getName();
if (name != null) {
item.mContactName = name.toString();
}
break;
case VCARD_IMADDRESS:
item.mContactNetwork = d.alt;
break;
default:
// do nothing
break;
}
}
item.mDescription = ServiceUtils.getDetailTypeString(mContext.getResources(), phoneDetail.keyType) + " " + phoneNo;
}
if (item.mContactId == null) {
LogUtils.logI("FetchCallLogEvents.addCallLogData: id " + item.mNativeItemId + ", time " + item.mTitle + ", number " + item.mContactName);
} else {
LogUtils.logI("FetchCallLogEvents.addCallLogData: id " + item.mNativeItemId + ", name = " + item.mContactName + ", time " + item.mTitle + ", number " + item.mDescription);
}
mSyncItemList.add(item);
}
use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class NativeContactsApi1 method updateOrganization.
/**
* Updates the Organization detail in the context of a Contact Update
* operation. The end of result of this is that the Organization may be
* inserted, updated or deleted depending on the update data. For example,
* if the title is deleted but there is also a company name then the
* Organization is just updated. However, if there was no company name then
* the detail should be deleted altogether.
*
* @param ccList {@link ContactChange} list where Organization and Title may
* be found
* @param nabContactId The NAB ID of the Contact
* @return In the Organization insertion case this should contain the new ID
* and in the update case should contain the existing ID
*/
private long updateOrganization(ContactChange[] ccList, long nabContactId) {
if (mMarkedOrganizationIndex < 0 && mMarkedTitleIndex < 0) {
// no organization or title to update - do nothing
return ContactChange.INVALID_ID;
}
long detailId = ContactChange.INVALID_ID;
int flags = ContactChange.FLAG_NONE;
String company = null;
String title = null;
final Uri organizationUri = Uri.withAppendedPath(ContentUris.withAppendedId(People.CONTENT_URI, nabContactId), Contacts.Organizations.CONTENT_DIRECTORY);
final Cursor cursor = mCr.query(organizationUri, null, null, null, Organizations._ID);
// assuming that the lowest id is the one in CAB
try {
if (cursor != null && cursor.moveToNext()) {
company = CursorUtils.getString(cursor, Organizations.COMPANY);
title = CursorUtils.getString(cursor, Organizations.TITLE);
detailId = CursorUtils.getLong(cursor, Organizations._ID);
flags = mapFromNabOrganizationType(CursorUtils.getInt(cursor, Organizations.TYPE));
final boolean isPrimary = CursorUtils.getInt(cursor, Organizations.ISPRIMARY) > 0;
if (isPrimary) {
flags |= ContactChange.FLAG_PREFERRED;
}
}
} finally {
CursorUtils.closeCursor(cursor);
}
if (mMarkedOrganizationIndex >= 0) {
final ContactChange cc = ccList[mMarkedOrganizationIndex];
if (cc.getType() != ContactChange.TYPE_DELETE_DETAIL) {
final String value = cc.getValue();
if (value != null) {
final VCardHelper.Organisation organization = VCardHelper.getOrg(value);
if (!TextUtils.isEmpty(organization.name)) {
company = organization.name;
}
}
flags = cc.getFlags();
} else {
// Delete case
company = null;
}
}
if (mMarkedTitleIndex >= 0) {
final ContactChange cc = ccList[mMarkedTitleIndex];
title = cc.getValue();
if (cc.getType() != ContactChange.TYPE_DELETE_DETAIL) {
flags = cc.getFlags();
}
}
if (company != null || title != null) {
mValues.clear();
/*
* Forcing the label field to be null because we don't support
* custom labels and in case we replace from a custom label to home
* or private type without setting label to null, mCr.update() will
* throw a SQL constraint exception.
*/
mValues.put(Organizations.LABEL, (String) null);
mValues.put(Organizations.COMPANY, company);
mValues.put(Organizations.TITLE, title);
mValues.put(Organizations.TYPE, mapToNabOrganizationType(flags));
mValues.put(Organizations.ISPRIMARY, flags & ContactChange.FLAG_PREFERRED);
final Uri existingUri = ContentUris.withAppendedId(Contacts.Organizations.CONTENT_URI, detailId);
if (detailId != ContactChange.INVALID_ID) {
mCr.update(existingUri, mValues, null, null);
} else {
// insert
final Uri idUri = mCr.insert(organizationUri, mValues);
if (idUri != null) {
return ContentUris.parseId(idUri);
}
}
} else if (detailId != ContactChange.INVALID_ID) {
final Uri existingUri = ContentUris.withAppendedId(Contacts.Organizations.CONTENT_URI, detailId);
mCr.delete(existingUri, null, null);
} else {
mMarkedOrganizationIndex = mMarkedTitleIndex = -1;
}
// Updated detail id or ContactChange.INVALID_ID if deleted
return detailId;
}
Aggregations