|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.engine.BaseEngine com.vodafone360.people.engine.activities.ActivitiesEngine
public class ActivitiesEngine
Engine response for handling of Activities (i.e Timeline and Status events). It also interfaces to the native Call and Message logs to allow these events to be handled within the People Client's Timeline.
Nested Class Summary | |
---|---|
(package private) static interface |
ActivitiesEngine.ISyncHelper
Interface for Native call and message log sync classes. |
private static class |
ActivitiesEngine.State
Definitions of Activities engines states; IDLE - engine is inactive FETCH_STATUSES_FIRST_TIME: 1st time sync of statuses, FETCH_CALLOG_FIRST_TIME: first time sync of phone calls, UPDATE_STATUSES: updating statuses from server (user has pressed the "refresh button" or push event's triggered the sync), UPDATE_CALLOG_FROM_NATIVE: new timeline item appeared on the phone, FETCH_OLDER_CALLLOG_FROM_NATIVE_DB: user has pressed "more timelines" button, FETCH_SMS_FROM_NATIVE_DB: fetching SMS/MMS |
Nested classes/interfaces inherited from class com.vodafone360.people.engine.BaseEngine |
---|
BaseEngine.IEngineEventCallback |
Field Summary | |
---|---|
private static java.lang.String |
ACTIVITY_ITEM
|
static java.lang.String |
FETCHING_OLDER_STATUSES
|
static java.lang.String |
FETCHING_OLDER_TIMELINE
|
private static java.lang.String |
FILTER_GT
|
private static java.lang.String |
FILTER_LIDS
Identifier for filtering against local ids (LIDs) |
private static java.lang.String |
FILTER_NUM
maximum number of identities fetched at the same time |
private static java.lang.String |
FILTER_SORT
|
private static java.lang.String |
FILTER_STATUS
|
private static java.lang.String |
FILTER_TRUE
|
private static java.lang.String |
FILTER_UPDATED
filter definitions |
private static java.lang.String |
FILTER_UPDATED_REV
|
private java.util.Hashtable<java.lang.Integer,java.lang.String> |
mActiveRequests
|
private ActivitiesEngine.ISyncHelper |
mActiveSyncHelper
current processor (fetching timelines), is null if no action for timelines is taken |
private Context |
mContext
|
private DatabaseHelper |
mDb
|
private long |
mLastStatusUpdated
Timestamp for most recent Status event update |
private java.lang.Object |
mMutex
mutex for thread synchronization |
private long |
mOldestStatusUpdated
Timestamp for oldest Status event update |
private java.lang.Object |
mQueueMutex
|
private boolean |
mRequestActivitiesRequired
|
private static long |
MS_IN_SECOND
|
private ActivitiesEngine.State |
mState
engine's current state |
private TimelineEventWatcher |
mTimelineEventWatcher
Instance of TimelineEventWatcher which listens for native call and message logs events that ActivitiesEngine should sync. |
private boolean |
mTimelinesUpdated
|
private static long |
READ_TIMELINES_TIMEOUT_MILLS
|
private static long |
STATUSES_SYNC_TIMEOUT_MILLIS
|
static java.lang.String |
UPDATING_STATUSES
below are the constants to communicate the engine state states to UI: 3 buttons (update statuses, load older statuses, older timelines) |
private static long |
WEEK_OLD_MILLIS
|
Fields inherited from class com.vodafone360.people.engine.BaseEngine |
---|
mActiveUiRequest, mCurrentTimeout, mEngineId, mEventCallback |
Constructor Summary | |
---|---|
ActivitiesEngine(Context context,
BaseEngine.IEngineEventCallback eventCallback,
DatabaseHelper db)
Constructor |
Method Summary | |
---|---|
protected void |
addGetNewPhonesCallsRequest()
This method adds a request to get latest timelines. |
protected void |
addGetNewSMSRequest()
This method adds a request to get latest timelines. |
void |
addGetOlderStatusesRequest()
This method adds a request to start sync of older statuses from Now+ server. |
void |
addOlderTimelinesRequest()
This method adds a request to get older timelines. |
void |
addStatusesSyncRequest()
This method adds a request to start sync of the most recent statuses from Now+ server. |
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
applyActivitiesFilter(boolean refresh)
|
private boolean |
checkConnectivity()
Get current connectivity state from the NetworkAgent. |
private void |
cleanDatabase()
Trigger the ActivitiesTable cleanup when the Engine is in "CLEANUP_DATABASE" state. |
private void |
dequeueRequest(int requestId)
This method stores removes a busy state of engine and males the change available to UI through the ApplicationCache. |
private void |
enqueueRequest(int requestId,
java.lang.String requestType)
This method stores the current busy state of engine in ApplicationCache to make it available to UI. |
private java.lang.Long |
findFirstStatusUpdateTime(java.util.ArrayList<ActivityItem> activityList)
Find oldest item in list of Activities retrieved from server. |
private java.lang.Long |
findLastStatusUpdateTime(java.util.ArrayList<ActivityItem> activityList)
|
private void |
fireNewState(ServiceUiRequest request)
This method fires states change of an engine to UI (between "busy" and IDLE). |
long |
getNextRunTime()
Return next run time for ActivitiesEngine. |
private void |
handleGetActivitiesResponse(java.util.List<BaseDataType> data)
Handle GetActivities response message received from Server |
private void |
handlePushRequest(PushMessageTypes evt)
Handle Status or Timeline Activity change Push message |
private boolean |
isContactSyncReady()
This method is necessary for the tests. |
boolean |
isTimelinesUpdated()
This method returns if the timelines have been updated with the previous "show more" call or push message. |
private void |
newState(ActivitiesEngine.State newState)
Changes the state of the engine. |
void |
onContactSyncStateChange(ContactSyncEngine.Mode mode,
ContactSyncEngine.State oldState,
ContactSyncEngine.State newState)
Called when the contact sync engine changes state or mode |
void |
onCreate()
onCreate. |
void |
onDestroy()
On destruction of ActivitiesEngine stop the timeline event watcher. |
void |
onLoginStateChanged(boolean loggedIn)
|
void |
onProgressEvent(ContactSyncEngine.State currentState,
int percent)
Called to update interested parties on contact sync progress. |
protected void |
onRequestComplete()
This function must be implemented in the derived engine implementation. |
void |
onSyncComplete(ServiceStatus status)
Receive notification from ContactSyncEngine that a Contact sync has completed. |
protected void |
onSyncHelperComplete(ServiceStatus status)
Function called when helper classes ends their work. |
protected void |
onTimeoutEvent()
Drive state machine for Activities sync. |
protected void |
processCommsResponse(ResponseQueue.Response resp)
Handle response received from transport layer (via EngineManager) |
protected void |
processUiRequest(ServiceUiRequest requestId,
java.lang.Object data)
Handle an outstanding UI request. |
private void |
removeDuplicates(java.util.ArrayList<ActivityItem> activityList)
TODO: investigate why duplicates here can appear. this method might be not necessary. |
private void |
requestStatusesFromServer(boolean refresh)
Request Activities (Status/Timeline) events from Server. |
void |
run()
ActivitiesEngine run implementation Processes a response if one is available, Processes any events in engine's UI queue. |
void |
setTimelinesUpdated(boolean timelinesUpdated)
This method sets the state - if the timelines have been updated or not. |
private void |
startCallLogSync(boolean refresh)
Start sync of call log from native call log data base |
private ServiceStatus |
updateDatabase(java.util.ArrayList<ActivityItem> activityList)
|
private void |
updateLatestStatusUpdateTime()
|
private void |
updateOldestStatusUpdateTime()
|
Methods inherited from class com.vodafone360.people.engine.BaseEngine |
---|
addUiRequestToQueue, clearTimeout, completeUiRequest, completeUiRequest, deactivateEngine, emptyUiRequestQueue, engineId, genericHandleResponseType, getCurrentTimeout, isCommsResponseOutstanding, isDeactivated, isUiRequestOutstanding, onCommsInMessage, onReset, processCommsInQueue, processTimeout, processUiQueue, setReqId, setTimeout |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String UPDATING_STATUSES
public static final java.lang.String FETCHING_OLDER_STATUSES
public static final java.lang.String FETCHING_OLDER_TIMELINE
private static final java.lang.String FILTER_UPDATED
private static final java.lang.String FILTER_GT
private static final java.lang.String FILTER_LIDS
private static final java.lang.String FILTER_NUM
private static final java.lang.String FILTER_SORT
private static final java.lang.String FILTER_UPDATED_REV
private static final java.lang.String FILTER_STATUS
private static final java.lang.String FILTER_TRUE
private static final long MS_IN_SECOND
private static final long STATUSES_SYNC_TIMEOUT_MILLIS
private static final long READ_TIMELINES_TIMEOUT_MILLS
private static final long WEEK_OLD_MILLIS
private static final java.lang.String ACTIVITY_ITEM
private long mLastStatusUpdated
private long mOldestStatusUpdated
private Context mContext
private ActivitiesEngine.State mState
private boolean mRequestActivitiesRequired
private final java.util.Hashtable<java.lang.Integer,java.lang.String> mActiveRequests
private TimelineEventWatcher mTimelineEventWatcher
private DatabaseHelper mDb
private final java.lang.Object mQueueMutex
private boolean mTimelinesUpdated
private ActivitiesEngine.ISyncHelper mActiveSyncHelper
private final java.lang.Object mMutex
Constructor Detail |
---|
public ActivitiesEngine(Context context, BaseEngine.IEngineEventCallback eventCallback, DatabaseHelper db)
context
- - valid contexteventCallback
- - callback objectdb
- - DatabaseHepler objectMethod Detail |
---|
public long getNextRunTime()
getNextRunTime
in class BaseEngine
public void onCreate()
onCreate
in class BaseEngine
public void onDestroy()
onDestroy
in class BaseEngine
protected void onRequestComplete()
onRequestComplete
in class BaseEngine
protected void onTimeoutEvent()
onTimeoutEvent
in class BaseEngine
protected void processCommsResponse(ResponseQueue.Response resp)
processCommsResponse
in class BaseEngine
resp
- Received Response item either a Status/Timeline related push
message or a response to a get activities request.protected void processUiRequest(ServiceUiRequest requestId, java.lang.Object data)
processUiRequest
in class BaseEngine
requestId
- The UI request IDdata
- Request data (object type is request specific)public void run()
run
in class BaseEngine
private void startCallLogSync(boolean refresh)
private boolean isContactSyncReady()
private void requestStatusesFromServer(boolean refresh)
refresh
- boolean - is true when fetching latest statuses, false -
when olderprivate java.util.Map<java.lang.String,java.util.List<java.lang.String>> applyActivitiesFilter(boolean refresh)
private void cleanDatabase()
private void handlePushRequest(PushMessageTypes evt)
evt
- Push message type (Status change or Timeline change).private void handleGetActivitiesResponse(java.util.List<BaseDataType> data)
reqId
- Request ID contained in response. This should match an ID of
a request we have issued to the Server.data
- List array of ActivityItem items returned from Server.private ServiceStatus updateDatabase(java.util.ArrayList<ActivityItem> activityList)
private void updateLatestStatusUpdateTime()
private void updateOldestStatusUpdateTime()
private java.lang.Long findLastStatusUpdateTime(java.util.ArrayList<ActivityItem> activityList)
private java.lang.Long findFirstStatusUpdateTime(java.util.ArrayList<ActivityItem> activityList)
private void removeDuplicates(java.util.ArrayList<ActivityItem> activityList)
public void onContactSyncStateChange(ContactSyncEngine.Mode mode, ContactSyncEngine.State oldState, ContactSyncEngine.State newState)
onContactSyncStateChange
in interface ContactSyncEngine.IContactSyncObserver
mode
- Current modeoldState
- Previous statenewState
- New statepublic void onSyncComplete(ServiceStatus status)
onSyncComplete
in interface ContactSyncEngine.IContactSyncObserver
status
- SUCCESS if the sync was successful, a suitable error
code otherwise.public void onProgressEvent(ContactSyncEngine.State currentState, int percent)
onProgressEvent
in interface ContactSyncEngine.IContactSyncObserver
currentState
- What the contact sync engine is currently doingpercent
- Percentage complete for the current taskprivate boolean checkConnectivity()
protected void onSyncHelperComplete(ServiceStatus status)
status
- - ServiceStatus of completed operation.protected void addGetNewPhonesCallsRequest()
protected void addGetNewSMSRequest()
public void addOlderTimelinesRequest()
public void addStatusesSyncRequest()
public void addGetOlderStatusesRequest()
private void newState(ActivitiesEngine.State newState)
newState
- The new stateprivate void fireNewState(ServiceUiRequest request)
request
- ServiceUIRequest UPDATING_UI or UPDATING_UI_FINISHEDprivate void enqueueRequest(int requestId, java.lang.String requestType)
requestId
- int - the request Id for network communications, or the
ServiceUIRequest ordinal for fetching/updating timelinesrequestType
- one of UPDATING_STATUSES, FETCHING_OLDER_STATUSES,
FETCHING_OLDER_TIMELINEprivate void dequeueRequest(int requestId)
requestId
- int - the request Id for network communications, or the
ServiceUIRequest ordinal for fetching/updating timelinesrequestType
- one of UPDATING_STATUSES, FETCHING_OLDER_STATUSES,
FETCHING_OLDER_TIMELINEpublic void onLoginStateChanged(boolean loggedIn)
onLoginStateChanged
in interface LoginEngine.ILoginEventsListener
public boolean isTimelinesUpdated()
public void setTimelinesUpdated(boolean timelinesUpdated)
timelinesUpdated
- boolean
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc