use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class PresenceTable method getUserPresenceByLocalContactId.
/**
* This method returns user/me profile presence state.
*
* @param localContactId - me profile localContactId
* @param readableDatabase - the database to read from
* @return user/me profile presence state wrapped in "User" wrapper class,
* or NULL if the specified localContactId doesn't exist
* @throws SQLException if the database layer throws this exception.
* @throws NullPointerException if the passed in database instance is null.
* @return user - User object filled with presence information.
*/
public static User getUserPresenceByLocalContactId(long localContactId, SQLiteDatabase readableDatabase) throws SQLException, NullPointerException {
if (readableDatabase == null) {
throw new NullPointerException(DEFAULT_ERROR_MESSAGE);
}
User user = null;
if (localContactId < 0) {
LogUtils.logE("PresenceTable.getUserPresenceByLocalContactId(): " + "#localContactId# parameter is -1 ");
return user;
}
Cursor c = null;
try {
c = readableDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Field.LOCAL_CONTACT_ID + "=" + localContactId, null);
ArrayList<NetworkPresence> networkPresence = new ArrayList<NetworkPresence>();
user = new User();
// i.e. 0
int onlineStatus = OnlineStatus.OFFLINE.ordinal();
while (c.moveToNext()) {
user.setLocalContactId(c.getLong(LOCAL_CONTACT_ID));
String userId = c.getString(USER_ID);
int networkId = c.getInt(NETWORK_ID);
int statusId = c.getInt(NETWORK_STATUS);
if (statusId > onlineStatus) {
onlineStatus = statusId;
}
networkPresence.add(new NetworkPresence(userId, networkId, statusId));
}
if (!networkPresence.isEmpty()) {
user.setOverallOnline(onlineStatus);
user.setPayload(networkPresence);
}
} finally {
CloseUtils.close(c);
c = null;
}
return user;
}
use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class PresenceTable method getUserPresence.
/**
* This method fills the provided user object with presence information.
*
* @param user User - the user with a localContactId != -1
* @param readableDatabase - the database to read from
* @return user/me profile presence state wrapped in "User" wrapper class,
* or NULL if the specified localContactId doesn't exist
* @throws SQLException if the database layer throws this exception.
* @throws NullPointerException if the passed in database instance is null.
*/
public static void getUserPresence(User user, SQLiteDatabase readableDatabase) throws SQLException, NullPointerException {
if (readableDatabase == null) {
throw new NullPointerException(DEFAULT_ERROR_MESSAGE);
}
if (user.getLocalContactId() < 0) {
LogUtils.logE("PresenceTable.getUserPresenceByLocalContactId(): " + "#localContactId# parameter is -1 ");
return;
}
Cursor c = null;
try {
c = readableDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Field.LOCAL_CONTACT_ID + "=" + user.getLocalContactId(), null);
if (c != null) {
// i.e. 0
int onlineStatus = OnlineStatus.OFFLINE.ordinal();
ArrayList<NetworkPresence> payload = user.getPayload();
payload.clear();
while (c.moveToNext()) {
String userId = c.getString(USER_ID);
int networkId = c.getInt(NETWORK_ID);
int statusId = c.getInt(NETWORK_STATUS);
if (statusId > onlineStatus) {
onlineStatus = statusId;
}
payload.add(new NetworkPresence(userId, networkId, statusId));
}
user.setOverallOnline(onlineStatus);
}
} finally {
CloseUtils.close(c);
c = null;
}
}
use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class MePresenceCacheTable method getCache.
/**
* Retrieves current NetworkPresence values in the cache.
* @param readableDatabase Readable object to access db
* @return Current cached values or null if there are none.
* @throws SQLException if the database layer throws this exception.
* @throws NullPointerException if the passed in database instance is null.
*/
public static ArrayList<NetworkPresence> getCache(SQLiteDatabase readableDatabase) throws SQLException, NullPointerException {
Cursor c = null;
if (readableDatabase == null) {
throw new NullPointerException(DEFAULT_ERROR_MESSAGE);
}
ArrayList<NetworkPresence> presences = null;
try {
c = readableDatabase.rawQuery("SELECT * FROM " + TABLE_NAME, null);
if (c.getCount() > 0) {
presences = new ArrayList<NetworkPresence>();
}
while (c.moveToNext()) {
String userId = c.getString(USER_ID);
int networkId = c.getInt(NETWORK_ID);
int statusId = c.getInt(STATUS);
presences.add(new NetworkPresence(userId, networkId, statusId));
}
} finally {
CloseUtils.close(c);
c = null;
}
return presences;
}
Aggregations