Search in sources :

Example 6 with NetworkPresence

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;
}
Also used : NetworkPresence(com.vodafone360.people.engine.presence.NetworkPresence) User(com.vodafone360.people.engine.presence.User) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 7 with NetworkPresence

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;
    }
}
Also used : NetworkPresence(com.vodafone360.people.engine.presence.NetworkPresence) Cursor(android.database.Cursor)

Example 8 with NetworkPresence

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;
}
Also used : NetworkPresence(com.vodafone360.people.engine.presence.NetworkPresence) Cursor(android.database.Cursor)

Aggregations

NetworkPresence (com.vodafone360.people.engine.presence.NetworkPresence)6 ArrayList (java.util.ArrayList)4 Cursor (android.database.Cursor)3 SocialNetwork (com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork)2 ContentValues (android.content.ContentValues)1 OnlineStatus (com.vodafone360.people.datatypes.ContactSummary.OnlineStatus)1 Identity (com.vodafone360.people.datatypes.Identity)1 User (com.vodafone360.people.engine.presence.User)1