use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class PresenceEngine method updatePresenceDatabaseNextPage.
/**
* This API makes the presence updates in pages of 10 with a timeout
* after each page. The HandlerAgent is notified after every 10 pages.
*/
private synchronized void updatePresenceDatabaseNextPage() {
UiAgent uiAgent = mEventCallback.getUiAgent();
if (mUsers == null) {
mState = IDLE;
return;
}
int listSize = mUsers.size();
int start = 0;
int end = UPDATE_PRESENCE_PAGE_SIZE;
if (listSize == 0) {
mState = IDLE;
mUsers = null;
notifyUiAgentOfResponse();
return;
} else if (listSize < end) {
end = listSize;
}
List<User> userSubset = mUsers.subList(start, end);
if ((userSubset != null)) {
long idListeningTo = UiAgent.ALL_USERS;
if (uiAgent != null) {
idListeningTo = uiAgent.getLocalContactId();
}
boolean updateUI = PresenceDbUtils.updateDatabase(userSubset, idListeningTo, mDbHelper);
userSubset.clear();
// Send the update notification to UI for every UPDATE_PRESENCE_PAGE_SIZE*NOTIFY_AGENT_PAGE_INTERVAL updates.
if (updateUI) {
if (mUsers.size() == 0 || NOTIFY_AGENT_PAGE_INTERVAL == mIterations) {
if (uiAgent != null) {
uiAgent.updatePresence(idListeningTo);
}
mIterations = 0;
} else {
mIterations++;
}
}
this.setTimeout(UPDATE_PRESENCE_TIMEOUT_MILLS);
}
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class ResponseQueue method addToResponseQueue.
/**
* Adds a response item to the queue.
*
* @param reqId The request ID to add the response for.
* @param data The response data to add to the queue.
* @param source The corresponding engine that fired off the request for the
* response.
*/
public void addToResponseQueue(final DecodedResponse response) {
synchronized (QueueManager.getInstance().lock) {
ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.UNKNOWN_DATA_TYPE, response.mDataTypes);
if (status == ServiceStatus.ERROR_INVALID_SESSION) {
EngineManager em = EngineManager.getInstance();
if (em != null) {
LogUtils.logE("Logging out the current user because of invalide session");
em.getLoginEngine().logoutAndRemoveUser();
return;
}
}
synchronized (mResponses) {
mResponses.add(response);
}
Request request = RequestQueue.getInstance().removeRequest(response.mReqId);
if (request != null) {
// we suppose the response being handled by the same engine
// that issued the request with the given id
response.mSource = request.mEngineId;
}
mEngMgr = EngineManager.getInstance();
if (mEngMgr != null) {
mEngMgr.onCommsInMessage(response.mSource);
}
}
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class PresenceTable method updateUser.
/**
* This method updates the user with the information from the User wrapper.
*
* @param user2Update - User info to update
* @param ignoredNetworkIds - ArrayList of integer network ids presence state for which must be ignored.
* @param writableDatabase - writable database
* @return USER_ADDED if no user with user id like the one in user2Update
* payload "status.getUserId()" ever existed in this table,
* USER_UPDATED if the user already existed in the table and has
* been successfully added, USER_NOT_ADDED - if user was not added.
* @throws SQLException if the database layer throws this exception.
* @throws NullPointerException if the passed in database instance is null.
*/
public static int updateUser(User user2Update, ArrayList<Integer> ignoredNetworkIds, SQLiteDatabase writableDatabase) throws SQLException, NullPointerException {
int ret = USER_NOTADDED;
if (writableDatabase == null) {
throw new NullPointerException(DEFAULT_ERROR_MESSAGE);
}
if (user2Update != null) {
ArrayList<NetworkPresence> statusesOnNetworks = user2Update.getPayload();
if (!statusesOnNetworks.isEmpty()) {
ContentValues values = new ContentValues();
StringBuffer where = null;
Iterator<NetworkPresence> itr = statusesOnNetworks.iterator();
NetworkPresence status = null;
long localContactId = user2Update.getLocalContactId();
int networkId = 0;
while (itr.hasNext()) {
status = itr.next();
networkId = status.getNetworkId();
if (ignoredNetworkIds == null || !ignoredNetworkIds.contains(networkId)) {
values.put(Field.LOCAL_CONTACT_ID.toString(), localContactId);
values.put(Field.USER_ID.toString(), status.getUserId());
values.put(Field.NETWORK_ID.toString(), networkId);
values.put(Field.NETWORK_STATUS.toString(), status.getOnlineStatusId());
where = StringBufferPool.getStringBuffer(Field.LOCAL_CONTACT_ID.toString());
where.append(SQLKeys.EQUALS).append(localContactId).append(SQLKeys.AND).append(Field.NETWORK_ID).append(SQLKeys.EQUALS).append(networkId);
int numberOfAffectedRows = writableDatabase.update(TABLE_NAME, values, StringBufferPool.toStringThenRelease(where), null);
if (numberOfAffectedRows == 0) {
if (writableDatabase.insert(TABLE_NAME, null, values) != -1) {
ret = USER_ADDED;
} else {
LogUtils.logE("PresenceTable updateUser(): could not add new user!");
}
} else if (ret == USER_NOTADDED) {
ret = USER_UPDATED;
}
values.clear();
} else if (ignoredNetworkIds != null) {
// presence information from this network needs to be ignored
itr.remove();
}
}
}
}
return ret;
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class ContactSyncEngine method setFirstTimeSyncComplete.
/**
* Helper function to update the database when the state of the
* {@link #mFirstTimeSyncComplete} flag changes.
*
* @param value New value to the flag. True indicates that first time sync
* has been completed. The flag is never set to false again by
* the engine, it will be only set to false when a remove user
* data is done (and the database is deleted).
* @return SUCCESS or a suitable error code if the database could not be
* updated.
*/
private ServiceStatus setFirstTimeSyncComplete(boolean value) {
if (mFirstTimeSyncComplete == value) {
return ServiceStatus.SUCCESS;
}
PersistSettings setting = new PersistSettings();
setting.putFirstTimeSyncComplete(value);
ServiceStatus status = mDb.setOption(setting);
if (ServiceStatus.SUCCESS == status) {
synchronized (this) {
mFirstTimeSyncComplete = value;
}
}
return status;
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class ContactSyncEngine method setFirstTimeSyncStarted.
/**
* Helper function to update the database when the state of the
* {@link #mFirstTimeSyncStarted} flag changes.
*
* @param value New value to the flag. True indicates that first time sync
* has been started. The flag is never set to false again by the
* engine, it will be only set to false when a remove user data
* is done (and the database is deleted).
* @return SUCCESS or a suitable error code if the database could not be
* updated.
*/
private ServiceStatus setFirstTimeSyncStarted(boolean value) {
if (mFirstTimeSyncStarted == value) {
return ServiceStatus.SUCCESS;
}
PersistSettings setting = new PersistSettings();
setting.putFirstTimeSyncStarted(value);
ServiceStatus status = mDb.setOption(setting);
if (ServiceStatus.SUCCESS == status) {
synchronized (this) {
mFirstTimeSyncStarted = value;
}
}
return status;
}
Aggregations