Search in sources :

Example 11 with TimelineSummaryItem

use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem 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;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) Uri(android.net.Uri) ActivityItem(com.vodafone360.people.datatypes.ActivityItem) Date(java.util.Date) Contact(com.vodafone360.people.datatypes.Contact)

Example 12 with TimelineSummaryItem

use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem in project 360-Engine-for-Android by 360.

the class FetchCallLogEvents method updateTimeStamps.

/**
     * This method goes through the event list and updates the current newest
     * and oldest phone call 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 (mNewestPhoneCall < max) {
            mNewestPhoneCall = max;
        }
        if (mOldestPhoneCall > min) {
            mOldestPhoneCall = min;
        }
    }
}
Also used : TimelineSummaryItem(com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem)

Example 13 with TimelineSummaryItem

use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem in project 360-Engine-for-Android by 360.

the class NowPlusActivitiesTableTest method testAddTimelineEvents.

/////////////////////////////////////////////////TIMELINES////////////////////////////////////////////////
/**
	 * This method checks that the added time line events are really present
	 * in the table.
	 */
@Suppress
public void testAddTimelineEvents() {
    SQLiteDatabase database = mTestDatabase.getWritableDatabase();
    ActivitiesTable.create(database);
    ArrayList<TimelineSummaryItem> timelineSummaryItemList = TestModule.generateFakeTimeLinesList();
    assertEquals("timelineSummaryItemList has size of 25", 25, timelineSummaryItemList.size());
    ActivitiesTable.addTimelineEvents(timelineSummaryItemList, false, database);
    assertEquals("timelineSummaryItemList has size of 25", 25, timelineSummaryItemList.size());
    /** Check if the records are there. **/
    Cursor cursor = null;
    ArrayList<TimelineSummaryItem> actualDBTimeLines = null;
    try {
        cursor = ActivitiesTable.fetchTimelineEventList(YESTERDAY_TIME_MILLIS, new TimelineNativeTypes[] { TimelineNativeTypes.SmsLog, TimelineNativeTypes.MmsLog }, database);
        assertEquals("Cursor contains less items than expected!", timelineSummaryItemList.size(), cursor.getCount());
        actualDBTimeLines = new ArrayList<TimelineSummaryItem>();
        for (int i = 0; i < timelineSummaryItemList.size(); i++) {
            if (cursor.moveToPosition(i)) {
                actualDBTimeLines.add(ActivitiesTable.getTimelineData(cursor));
            }
        }
    } finally {
        CloseUtils.close(cursor);
    }
    compareTimeLineIds(timelineSummaryItemList, actualDBTimeLines);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) TimelineNativeTypes(com.vodafone360.people.database.tables.ActivitiesTable.TimelineNativeTypes) TimelineSummaryItem(com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem) Cursor(android.database.Cursor) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 14 with TimelineSummaryItem

use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem in project 360-Engine-for-Android by 360.

the class NowPlusActivitiesTableTest method testUpdateTimelineContactNameAndId3.

/**
	 * this method checks the updated contacts are present in the database 
	 */
@Suppress
public void testUpdateTimelineContactNameAndId3() {
    Log.i(LOG_TAG, "***** testUpdateTimelineContactNameAndId3: create table *****");
    SQLiteDatabase writableDataBase = mTestDatabase.getWritableDatabase();
    ActivitiesTable.create(writableDataBase);
    Log.i(LOG_TAG, "***** testUpdateTimelineContactNameAndId3 , not call log though *****");
    ArrayList<TimelineSummaryItem> timeLines = TestModule.generateFakeTimeLinesList();
    ActivitiesTable.addTimelineEvents(timeLines, false, writableDataBase);
    // check if the records are there
    SQLiteDatabase readableDataBase = mTestDatabase.getReadableDatabase();
    Cursor c = ActivitiesTable.fetchTimelineEventList(YESTERDAY_TIME_MILLIS, new TimelineNativeTypes[] { TimelineNativeTypes.SmsLog, TimelineNativeTypes.MmsLog }, readableDataBase);
    ArrayList<TimelineSummaryItem> actualDBTimeLines = new ArrayList<TimelineSummaryItem>();
    for (int i = 0; i < timeLines.size(); i++) {
        if (c.moveToPosition(i)) {
            actualDBTimeLines.add(ActivitiesTable.getTimelineData(c));
        }
    }
    compareTimeLineIds(timeLines, actualDBTimeLines);
    final String NAME = "New";
    for (TimelineSummaryItem timeLineSummary : timeLines) {
        timeLineSummary.mContactName += NAME;
        ActivitiesTable.updateTimelineContactNameAndId(timeLineSummary.mContactName, timeLineSummary.mLocalContactId, writableDataBase);
    }
    c.requery();
    actualDBTimeLines.clear();
    for (int i = 0; i < timeLines.size(); i++) {
        if (c.moveToPosition(i)) {
            actualDBTimeLines.add(ActivitiesTable.getTimelineData(c));
        }
    }
    compareTimeLineIds(timeLines, actualDBTimeLines);
    Log.i(LOG_TAG, "***** testUpdateTimelineContactNameAndId3 SUCCEEDED *****");
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) TimelineSummaryItem(com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem) Cursor(android.database.Cursor) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 15 with TimelineSummaryItem

use of com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem 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);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) TimelineSummaryItem(com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem) Date(java.util.Date) Contact(com.vodafone360.people.datatypes.Contact)

Aggregations

TimelineSummaryItem (com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)7 ServiceStatus (com.vodafone360.people.service.ServiceStatus)7 Cursor (android.database.Cursor)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)4 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)4 Suppress (android.test.suitebuilder.annotation.Suppress)3 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)3 Contact (com.vodafone360.people.datatypes.Contact)3 TimelineNativeTypes (com.vodafone360.people.database.tables.ActivitiesTable.TimelineNativeTypes)2 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)1 IPeopleService (com.vodafone360.people.service.interfaces.IPeopleService)1