use of com.vodafone360.people.datatypes.VCardHelper.Name in project 360-Engine-for-Android by 360.
the class FetchSmsLogEvents method syncNextMmsPage.
/**
* Sync. next page of MMS events (current page size is 2).
*/
private void syncNextMmsPage() {
if (mMmsCursor.isAfterLast()) {
complete(mStatus);
return;
}
boolean finished = false;
if (mPageCount < MAX_PAGES_TO_LOAD_AT_ONCE) {
int count = 0;
while (count < MAX_ITEMS_PER_PAGE && mMmsCursor.moveToNext()) {
final long timestamp = MmsDecoder.getTimestamp(mMmsCursor);
if (mRefresh) {
if (timestamp < mNewestMessage) {
finished = true;
break;
}
} else {
if (timestamp > mOldestMessage) {
finished = true;
break;
}
}
TimelineSummaryItem item = new TimelineSummaryItem();
if (MmsDecoder.getMmsData(mContext, mCr, mMmsCursor, item, mDb, MAX_DESC_LENGTH)) {
LogUtils.logD("FetchSmsLogEvents.syncNextMmsPage(): id = " + item.mNativeItemId + ", name = " + item.mContactName + ", date = " + item.mTimestamp + ", title = " + item.mTitle + ", desc = " + item.mDescription + "\n");
mSyncItemList.add(item);
}
count++;
}
mPageCount++;
if ((count == MAX_ITEMS_PER_PAGE && mSyncItemList.size() == MAX_ITEMS_TO_WRITE) || (count < MAX_ITEMS_PER_PAGE) || (mPageCount == MAX_PAGES_TO_LOAD_AT_ONCE)) {
ServiceStatus status = mDb.addTimelineEvents(mSyncItemList, false);
updateTimestamps();
mSyncItemList.clear();
if (ServiceStatus.SUCCESS != status) {
complete(mStatus);
return;
}
mEngine.fireNewState(ServiceUiRequest.DATABASE_CHANGED_EVENT, new Bundle());
}
} else {
finished = true;
}
if (finished) {
saveTimeStampMms();
complete(mStatus);
}
}
use of com.vodafone360.people.datatypes.VCardHelper.Name 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.VCardHelper.Name 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;
}
use of com.vodafone360.people.datatypes.VCardHelper.Name 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;
}
}
use of com.vodafone360.people.datatypes.VCardHelper.Name 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;
}
Aggregations