use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem in project 360-Engine-for-Android by 360.
the class ChatDbUtils method saveChatMessageAsATimeline.
/**
* This method saves the supplied
*
* @param msg
* @param type
* @param databaseHelper
*/
protected static void saveChatMessageAsATimeline(ChatMessage message, TimelineSummaryItem.Type type, DatabaseHelper databaseHelper) {
TimelineSummaryItem item = new TimelineSummaryItem();
fillInContactDetails(message, item, databaseHelper, type);
SQLiteDatabase writableDatabase = databaseHelper.getWritableDatabase();
boolean isRead = true;
if (type == TimelineSummaryItem.Type.INCOMING) {
isRead = false;
}
if (ActivitiesTable.addChatTimelineEvent(item, isRead, writableDatabase) != -1) {
ConversationsTable.addNewConversationId(message, writableDatabase);
} else {
LogUtils.logE("The msg was not saved to the ActivitiesTable");
}
}
use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem in project 360-Engine-for-Android by 360.
the class ChatDbUtils method fillInContactDetails.
/**
* Remove hard code
*
* @param msg
* @param item
* @param databaseHelper
* @param incoming
*/
private static void fillInContactDetails(ChatMessage msg, TimelineSummaryItem item, DatabaseHelper databaseHelper, TimelineSummaryItem.Type incoming) {
item.mTimestamp = System.currentTimeMillis();
// here we set the time stamp back into the chat message
// in order to be able to remove it from the chat history by time stamp in case its delivery fails
msg.setTimeStamp(item.mTimestamp);
item.mType = ActivityItem.Type.MESSAGE_IM_CONVERSATION;
item.mDescription = msg.getBody();
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
// we store sender's localContactId for incoming msgs and recipient's
// localContactId for outgoing msgs
item.mLocalContactId = msg.getLocalContactId();
if (item.mLocalContactId != null && item.mLocalContactId != -1) {
ContactDetail cd = ContactDetailsTable.fetchDetail(item.mLocalContactId, DetailKeys.VCARD_NAME, databaseHelper.getReadableDatabase());
if (cd == null || cd.getName() == null) {
// if we don't get any details, we have to check the summary
// table because gtalk contacts
// without name will be otherwise show as unknown
ContactSummary contactSummary = new ContactSummary();
ServiceStatus error = ContactSummaryTable.fetchSummaryItem(item.mLocalContactId, contactSummary, databaseHelper.getReadableDatabase());
if (error == ServiceStatus.SUCCESS) {
item.mContactName = (contactSummary.formattedName != null) ? contactSummary.formattedName : ContactDetail.UNKNOWN_NAME;
} else {
item.mContactName = ContactDetail.UNKNOWN_NAME;
}
} else {
/** Get name from contact details. **/
VCardHelper.Name name = cd.getName();
item.mContactName = (name != null) ? name.toString() : ContactDetail.UNKNOWN_NAME;
}
}
item.mIncoming = incoming;
item.mContactNetwork = SocialNetwork.getSocialNetworkValue(msg.getNetworkId()).toString();
item.mNativeItemType = TimelineNativeTypes.ChatLog.ordinal();
}
use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem in project 360-Engine-for-Android by 360.
the class FetchSmsLogEvents method updateTimestamps.
/**
* This method goes through the event list and updates the current newest
* and oldest message timestamps.
*/
private void updateTimestamps() {
if (mSyncItemList.size() > 0) {
long max = ((TimelineSummaryItem) mSyncItemList.get(0)).mTimestamp;
long min = max;
for (TimelineSummaryItem item : mSyncItemList) {
if (item.mTimestamp > max) {
max = item.mTimestamp;
}
if (item.mTimestamp < min) {
min = item.mTimestamp;
}
}
if (mNewestMessage < max) {
mNewestMessage = max;
}
if (mOldestMessage > min) {
mOldestMessage = min;
}
}
}
use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem 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.database.tables.ActivitiesTable.TimelineSummaryItem 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);
}
Aggregations