com.vodafone360.people.engine.activities
Class FetchCallLogEvents

java.lang.Object
  extended by com.vodafone360.people.engine.activities.FetchCallLogEvents
All Implemented Interfaces:
ActivitiesEngine.ISyncHelper

public class FetchCallLogEvents
extends java.lang.Object
implements ActivitiesEngine.ISyncHelper

Fetches call log events from the Native call log. These are treated as Activities and displayed in Timeline UI.


Nested Class Summary
private static class FetchCallLogEvents.InternalState
          Internal states for Call log event sync.
 
Field Summary
private static java.lang.String[] CALL_LOG_PROJECTION
          Set of Call log items to be fetched by query on Native call-log.
private static int COLUMN_CALLLOG_DATE
           
private static int COLUMN_CALLLOG_ID
           
private static int COLUMN_CALLLOG_PHONE
           
private static int COLUMN_CALLLOG_TYPE
           
private static int MAX_CALL_LOG_ITEMS_PER_PAGE
           
private static int MAX_ITEMS_TO_WRITE
           
private static int MAX_NUMBER_OF_PAGES
          the number of timeline pages to be loaded by one ISyncHelper
private  Context mContext
           
private  ContentResolver mCr
           
private  DatabaseHelper mDb
           
private  ActivitiesEngine mEngine
           
private  FetchCallLogEvents.InternalState mInternalState
           
private  Cursor mNativeCursor
           
private  long mNewestPhoneCall
          the current newest phone call time
private  long mOldestPhoneCall
          the current oldest phone call time
private  int mPageCount
          the number of pages have been read
private  boolean mRefresh
          is true if newer events need to be loaded, false - if older
private  java.util.ArrayList<ActivitiesTable.TimelineSummaryItem> mSyncItemList
           
private static java.lang.String NATIVE_NUMBER_UNKNOWN_STRING
           
 
Constructor Summary
FetchCallLogEvents(Context context, ActivitiesEngine engine, DatabaseHelper db, boolean refresh)
          Constructor.
 
Method Summary
private  void addCallLogData(int id)
          Create TimelineSummaryItem from Native call-log item.
 void cancel()
          Cancel fetch of call log events.
private  void complete(ServiceStatus status)
          Completion of fetch from Native call log.
private static ActivityItem.Type nativeTypeToNpType(int nativeType)
          Convert native call type to type stored in People's ActivityItem.
 void run()
          Drive internal state machine, either start call log sync, fetch next page of call-log items or complete call-log sync operation.
private  void saveTimestamp()
          This method updates the newest and oldest phone calls timestamps in the database.
private  void startSyncCallLog()
          Start sync of call events from Native call log.
private  void syncNextPage()
          Sync next page of call-log events (page-size is 2).
private  ServiceStatus updateDatabase()
           
private  void updateTimeStamps()
          This method goes through the event list and updates the current newest and oldest phone call timestamps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CALL_LOG_ITEMS_PER_PAGE

private static final int MAX_CALL_LOG_ITEMS_PER_PAGE
See Also:
Constant Field Values

MAX_ITEMS_TO_WRITE

private static final int MAX_ITEMS_TO_WRITE
See Also:
Constant Field Values

MAX_NUMBER_OF_PAGES

private static final int MAX_NUMBER_OF_PAGES
the number of timeline pages to be loaded by one ISyncHelper

See Also:
Constant Field Values

NATIVE_NUMBER_UNKNOWN_STRING

private static final java.lang.String NATIVE_NUMBER_UNKNOWN_STRING
See Also:
Constant Field Values

mContext

private Context mContext

mCr

private ContentResolver mCr

mNativeCursor

private Cursor mNativeCursor

mEngine

private ActivitiesEngine mEngine

mDb

private DatabaseHelper mDb

mSyncItemList

private final java.util.ArrayList<ActivitiesTable.TimelineSummaryItem> mSyncItemList

mRefresh

private boolean mRefresh
is true if newer events need to be loaded, false - if older


mPageCount

private int mPageCount
the number of pages have been read


mOldestPhoneCall

private long mOldestPhoneCall
the current oldest phone call time


mNewestPhoneCall

private long mNewestPhoneCall
the current newest phone call time


mInternalState

private FetchCallLogEvents.InternalState mInternalState

CALL_LOG_PROJECTION

private static final java.lang.String[] CALL_LOG_PROJECTION
Set of Call log items to be fetched by query on Native call-log.


COLUMN_CALLLOG_ID

private static final int COLUMN_CALLLOG_ID
See Also:
Constant Field Values

COLUMN_CALLLOG_PHONE

private static final int COLUMN_CALLLOG_PHONE
See Also:
Constant Field Values

COLUMN_CALLLOG_DATE

private static final int COLUMN_CALLLOG_DATE
See Also:
Constant Field Values

COLUMN_CALLLOG_TYPE

private static final int COLUMN_CALLLOG_TYPE
See Also:
Constant Field Values
Constructor Detail

FetchCallLogEvents

FetchCallLogEvents(Context context,
                   ActivitiesEngine engine,
                   DatabaseHelper db,
                   boolean refresh)
Constructor.

Parameters:
context - Context - actually RemoteServe's Context.
engine - Handle to ActivitiesEngine.
db - Handle to DatabaseHelper.
refresh - boolean - true if new phone call need to be fetched, false - if older
Method Detail

run

public void run()
Drive internal state machine, either start call log sync, fetch next page of call-log items or complete call-log sync operation.

Specified by:
run in interface ActivitiesEngine.ISyncHelper

cancel

public void cancel()
Cancel fetch of call log events. Close Cursor to Native Call log. Reset state to IDLE.

Specified by:
cancel in interface ActivitiesEngine.ISyncHelper

startSyncCallLog

private void startSyncCallLog()
Start sync of call events from Native call log. Use Timeline last update time-stamp to ensure we only fetch 'new' events.


syncNextPage

private void syncNextPage()
Sync next page of call-log events (page-size is 2).


updateDatabase

private ServiceStatus updateDatabase()

updateTimeStamps

private void updateTimeStamps()
This method goes through the event list and updates the current newest and oldest phone call timestamps.


saveTimestamp

private void saveTimestamp()
This method updates the newest and oldest phone calls timestamps in the database.


addCallLogData

private void addCallLogData(int id)
Create TimelineSummaryItem from Native call-log item.

Parameters:
id - ID of item from Native log.

complete

private void complete(ServiceStatus status)
Completion of fetch from Native call log. Notify ActivitiesEngine that call-log sync. has completed.

Parameters:
status - ServiceStatus containing result of sync.

nativeTypeToNpType

private static ActivityItem.Type nativeTypeToNpType(int nativeType)
Convert native call type to type stored in People's ActivityItem.

Parameters:
nativeType - Native call type.
Returns:
People's ActivityItem call type.


JavaDoc