use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class DownloadServerContacts method updateProgressUi.
/**
* Check the given contact to see if it has a valid name, and if so send it
* to be shown in the contacts sync progress UI.
*
* @param contact Contact which has been downloaded.
* @param incOfCurrentPage Number of contacts that have so far been
* downloaded for the current page.
*/
private void updateProgressUi(Contact contact, int incOfCurrentPage) {
String name = "";
if (contact != null) {
ContactDetail contactDetail = contact.getContactDetail(ContactDetail.DetailKeys.VCARD_NAME);
if (contactDetail != null) {
VCardHelper.Name vCardHelperName = contactDetail.getName();
if (vCardHelperName != null) {
name = vCardHelperName.toString();
}
}
}
int totalNumberOfContacts = ((mTotalNoOfPages * 10) - 1) * MAX_DOWN_PAGE_SIZE / 10;
if (mLastPageSize != -1) {
totalNumberOfContacts = (mTotalNoOfPages - 1) * MAX_DOWN_PAGE_SIZE + mLastPageSize;
}
int progress = (incOfCurrentPage + (mNoOfPagesDone * MAX_DOWN_PAGE_SIZE)) * 100 / totalNumberOfContacts;
setSyncStatus(new SyncStatus(progress, name, Task.DOWNLOAD_SERVER_CONTACTS, TaskStatus.RECEIVED_CONTACTS, incOfCurrentPage + mNoOfPagesDone * MAX_DOWN_PAGE_SIZE, totalNumberOfContacts));
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class DownloadServerContacts method syncDownContact.
/**
* Modifies a contact from the NowPlus database to match the one received
* from the server
*
* @param srcContact Contact received from the server
* @param destContact Contact as stored in the database
* @return SUCCESS or a suitable error code.
*/
private ServiceStatus syncDownContact(Contact srcContact, Contact destContact) {
final long localContactId = destContact.localContactID;
final Integer nativeContactId = destContact.nativeContactId;
if (srcContact.deleted != null && srcContact.deleted.booleanValue()) {
if (EXTRA_DEBUG_TRACE) {
LogUtils.logD("DownloadServerContacts.syncDownContact - Deleting contact " + srcContact.contactID);
}
ContactsTable.ContactIdInfo idInfo = new ContactsTable.ContactIdInfo();
idInfo.localId = localContactId;
idInfo.serverId = srcContact.contactID;
idInfo.nativeId = nativeContactId;
mDeleteContactList.add(idInfo);
mSyncDataPending = true;
return ServiceStatus.SUCCESS;
}
if (checkContactMods(srcContact, destContact)) {
if (EXTRA_DEBUG_TRACE) {
LogUtils.logD("DownloadServerContacts.syncDownContact - Modifying contact " + srcContact.contactID);
}
srcContact.localContactID = localContactId;
srcContact.nativeContactId = nativeContactId;
mModifyContactList.add(srcContact);
mSyncDataPending = true;
}
if (srcContact.details == null) {
if (EXTRA_DEBUG_TRACE) {
LogUtils.logD("DownloadServerContacts.syncDownContact - No details changed " + srcContact.contactID);
}
return ServiceStatus.SUCCESS;
}
for (ContactDetail srcDetail : srcContact.details) {
srcDetail.localContactID = localContactId;
srcDetail.nativeContactId = nativeContactId;
boolean detailFound = false;
for (ContactDetail destDetail : destContact.details) {
if (DatabaseHelper.doDetailsMatch(srcDetail, destDetail)) {
detailFound = true;
srcDetail.localDetailID = destDetail.localDetailID;
srcDetail.nativeContactId = destDetail.nativeContactId;
srcDetail.nativeDetailId = destDetail.nativeDetailId;
srcDetail.serverContactId = srcContact.contactID;
if (srcDetail.deleted != null && srcDetail.deleted.booleanValue()) {
if (EXTRA_DEBUG_TRACE) {
LogUtils.logD("DownloadServerContacts.syncDownContact - Deleting detail " + srcDetail.key + " contact ID = " + srcContact.contactID);
}
mDeleteDetailList.add(srcDetail);
mSyncDataPending = true;
} else if (DatabaseHelper.hasDetailChanged(destDetail, srcDetail)) {
if (EXTRA_DEBUG_TRACE) {
LogUtils.logD("DownloadServerContacts.syncDownContact - Modifying detail " + srcDetail.key + " local detail ID = " + srcDetail.localDetailID);
}
srcDetail.serverContactId = srcContact.contactID;
mModifyDetailList.add(srcDetail);
mSyncDataPending = true;
}
break;
}
}
if (!detailFound) {
if (srcDetail.deleted == null || !srcDetail.deleted.booleanValue()) {
if (EXTRA_DEBUG_TRACE) {
LogUtils.logD("DownloadServerContacts.syncDownContact - Adding detail " + srcDetail.key + " local contact ID = " + srcDetail.localContactID);
}
mAddDetailList.add(srcDetail);
mSyncDataPending = true;
} else {
if (EXTRA_DEBUG_TRACE) {
LogUtils.logD("DownloadServerContacts.syncDownContact - Detail already deleted (nothing to do) " + srcDetail.key + " local detail ID = " + srcDetail.localDetailID);
}
}
}
}
return ServiceStatus.SUCCESS;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class FetchSmsLogEvents method addSmsData.
/**
* Create TimelineSummaryItem from Native message-log item.
*
* @param id ID of item from Native log.
*/
private void addSmsData(int id) {
ActivityItem.Type type = nativeToNpTypeConvert(mSmsCursor.getInt(COLUMN_SMS_TYPE));
if (type == null) {
return;
}
TimelineSummaryItem item = new TimelineSummaryItem();
String address = null;
/* Francisco: Unknown contact SMS sending bug resolved here
* I am keeping previous case SN_MESSAGE_RECEIVED besides MESSAGE_SMS_RECEIVED just to be safe.
*/
if (type == ActivityItem.Type.SN_MESSAGE_RECEIVED || type == ActivityItem.Type.MESSAGE_SMS_RECEIVED) {
item.mIncoming = TimelineSummaryItem.Type.INCOMING;
} else {
item.mIncoming = TimelineSummaryItem.Type.OUTGOING;
}
item.mNativeItemId = id;
item.mNativeItemType = ActivitiesTable.TimelineNativeTypes.SmsLog.ordinal();
item.mType = type;
item.mTimestamp = mSmsCursor.getLong(COLUMN_SMS_DATE);
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
item.mNativeThreadId = mSmsCursor.getInt(COLUMN_SMS_THREAD_ID);
item.mDescription = null;
if (!mSmsCursor.isNull(COLUMN_SMS_SUBJECT)) {
item.mDescription = mSmsCursor.getString(COLUMN_SMS_SUBJECT);
}
if (item.mDescription == null || item.mDescription.length() == 0) {
if (!mSmsCursor.isNull(COLUMN_SMS_BODY)) {
item.mDescription = mSmsCursor.getString(COLUMN_SMS_BODY);
}
}
if (!mSmsCursor.isNull(COLUMN_SMS_ADDRESS)) {
address = mSmsCursor.getString(COLUMN_SMS_ADDRESS);
}
item.mContactName = address;
item.mContactAddress = address;
Contact c = new Contact();
ContactDetail phoneDetail = new ContactDetail();
ServiceStatus status = mDb.fetchContactInfo(address, 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 = d.getName().toString();
}
break;
case VCARD_IMADDRESS:
item.mContactNetwork = d.alt;
break;
default:
// do nothing
break;
}
}
}
if (item.mContactId == null) {
LogUtils.logI("FetchSmsLogEvents.addSmsData: id " + item.mNativeItemId + ", time " + item.mTitle + ", description " + item.mDescription);
} else {
LogUtils.logI("FetchSmsLogEvents.addSmsData: id " + item.mNativeItemId + ", name = " + item.mContactName + ", time " + item.mTitle + ", description " + item.mDescription);
}
mSyncItemList.add(item);
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class MmsDecoder method getMmsData.
/**
* Get the MMS data for the message at current Cursor position and use it to
* populate a TimelineSummaryItem. We initially check if the MMS is an Inbox
* or sent item returning false if this is not the case.
*
* @param context Context.
* @param cr ContentResolver.
* @param mmsCursor Cursor pointing to MMS message entry in native message
* log.
* @param item TimeLineSummaryItem to populate using MMS message details
* @param db Handle to People database.
* @param maxDescLength maximum length of the description.
* @return true if we have created the TimelineSummaryItem false if we
* haven't (because the MMS is not of a valid type).
*/
protected static boolean getMmsData(Context context, ContentResolver cr, Cursor mmsCursor, TimelineSummaryItem item, DatabaseHelper db, int maxDescLength) {
int msgId = mmsCursor.getInt(COLUMN_MMS_ID);
Uri msgUri = MMS_CONTENT_URI.buildUpon().appendPath(Long.toString(msgId)).build();
ActivityItem.Type type = nativeToNpMessageType(mmsCursor.getInt(COLUMN_MSG_BOX));
if (type == null) {
return false;
}
String address = getToOrFrom(cr, type, msgUri);
String sub = mmsCursor.getString(COLUMN_SUBJECT);
int subcs = mmsCursor.getInt(COLUMN_SUBJECT_CS);
String subject = TextUtils.isEmpty(sub) ? "" : decodeString(subcs, getMmsBytes(sub));
item.mTimestamp = mmsCursor.getLong(COLUMN_DATE) * MS_IN_SECONDS;
item.mNativeItemId = msgId;
item.mNativeItemType = TimelineNativeTypes.MmsLog.ordinal();
item.mType = type;
item.mNativeThreadId = mmsCursor.getInt(COLUMN_MSG_THREAD_ID);
item.mContactAddress = address;
if (subject.length() > 0) {
if (subject.length() <= maxDescLength) {
item.mDescription = subject;
} else {
item.mDescription = subject.substring(0, maxDescLength) + ELLIPSIZE;
}
} else {
item.mDescription = getMmsText(cr, msgId, maxDescLength);
}
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
Contact c = new Contact();
ContactDetail phoneDetail = new ContactDetail();
ServiceStatus status = db.fetchContactInfo(address, c, phoneDetail);
if (ServiceStatus.SUCCESS == status) {
item.mContactId = c.contactID;
item.mLocalContactId = c.localContactID;
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 = d.getName().toString();
}
break;
case VCARD_IMADDRESS:
item.mContactNetwork = d.alt;
break;
default:
// do nothing.
break;
}
}
} else {
item.mContactName = address;
}
return true;
}
use of com.vodafone360.people.datatypes.ContactDetail in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method modifyDetail.
/**
* Updates an existing contact detail in the table.
*
* @param detail The modified detail.
* @param syncToServer Mark the new detail so it will be synced to the
* server
* @param syncToNative Mark the new detail so it will be synced to the
* native database
* @param writeableDb A writable SQLite database object.
* @return SUCCESS or a suitable error code.
* @note If any given field values in the contact detail are NULL they will
* NOT be modified in the database.
*/
public static ServiceStatus modifyDetail(ContactDetail detail, boolean syncToServer, boolean syncToNative, SQLiteDatabase writeableDb) {
try {
// back to server if we change anything
if (VersionUtils.is2XPlatform() == false && detail.key == DetailKeys.VCARD_NAME) {
Name name = VCardHelper.getName(detail.value);
if (name.surname.length() > 0) {
name.firstname = name.firstname.replace(name.surname, "").trim();
name.midname = name.midname.replace(name.surname, "").trim();
}
String vcardName = VCardHelper.makeName(name);
if (!detail.value.equals(vcardName)) {
syncToServer = true;
detail.value = vcardName;
}
}
ContentValues contactDetailValues = fillUpdateData(detail, syncToServer, syncToNative);
if (writeableDb.update(TABLE_NAME, contactDetailValues, Field.DETAILLOCALID + " = " + detail.localDetailID, null) <= 0) {
LogUtils.logE("ContactDetailsTable.modifyDetail() Unable to update contact detail , localDetailID[" + detail.localDetailID + "]");
return ServiceStatus.ERROR_NOT_FOUND;
}
} catch (SQLException e) {
LogUtils.logE("ContactDetailsTable.modifyDetail() SQLException - Unable to modify contact detail", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
DatabaseHelper.trace(true, "ContactDetailsTable.modifyDetail() localContactID[" + detail.localContactID + "] localDetailID[" + detail.localDetailID + "]");
return ServiceStatus.SUCCESS;
}
Aggregations