Search in sources :

Example 1 with OnlineStatus

use of com.vodafone360.people.datatypes.ContactSummary.OnlineStatus in project 360-Engine-for-Android by 360.

the class NowPlusContactSummaryTest method testSetAllUsersOffline.

public void testSetAllUsersOffline() {
    Log.i(LOG_TAG, "Create ContactSummaryTable");
    ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    final Contact contact = mTestModule.createDummyContactData();
    contact.localContactID = new Long(10);
    contact.nativeContactId = new Integer(11);
    ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Fetching a ContactSummary from ContactSummaryTable");
    final ContactSummary contactSummary = new ContactSummary();
    final ServiceStatus serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    compareContactWithContactSummary(contact, contactSummary);
    // create a new user
    Hashtable<String, String> status = new Hashtable<String, String>();
    status.put("google", "online");
    status.put("microsoft", "online");
    status.put("mobile", "online");
    status.put("pc", "online");
    User user = new User("any", status);
    user.setLocalContactId(contactSummary.localContactID);
    // set him online
    assertEquals(ServiceStatus.SUCCESS, ContactSummaryTable.updateOnlineStatus(user));
    // fetch again
    final ContactSummary contactSummary2 = new ContactSummary();
    assertEquals(ServiceStatus.SUCCESS, ContactSummaryTable.fetchSummaryItem(user.getLocalContactId(), contactSummary2, mTestDatabase.getReadableDatabase()));
    // check if he's online
    assertEquals(OnlineStatus.ONLINE, contactSummary2.onlineStatus);
    // set offline
    assertEquals(ServiceStatus.SUCCESS, ContactSummaryTable.setOfflineStatus());
    // fetch again
    final ContactSummary contactSummary3 = new ContactSummary();
    assertEquals(ServiceStatus.SUCCESS, ContactSummaryTable.fetchSummaryItem(user.getLocalContactId(), contactSummary3, mTestDatabase.getReadableDatabase()));
    // check if it's offline
    assertEquals(OnlineStatus.OFFLINE, contactSummary3.onlineStatus);
}
Also used : ContactSummary(com.vodafone360.people.datatypes.ContactSummary) User(com.vodafone360.people.engine.presence.User) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Hashtable(java.util.Hashtable) Contact(com.vodafone360.people.datatypes.Contact)

Example 2 with OnlineStatus

use of com.vodafone360.people.datatypes.ContactSummary.OnlineStatus in project 360-Engine-for-Android by 360.

the class MePresenceCacheTableTest method testGetUpdateCache.

public void testGetUpdateCache() {
    final String userId = "1234";
    assertTrue(createTable());
    final ArrayList<NetworkPresence> presenceList = new ArrayList<NetworkPresence>();
    int onlineStatus = OnlineStatus.ONLINE.ordinal();
    for (int i = SocialNetwork.FACEBOOK_COM.ordinal(); i < SocialNetwork.MICROSOFT.ordinal(); i++) {
        NetworkPresence networkPresence = new NetworkPresence(userId, i, onlineStatus);
        presenceList.add(networkPresence);
        MePresenceCacheTable.updateCache(networkPresence, mTestDatabase.getWritableDatabase());
        assertTrue(checkCacheEquals(presenceList));
    }
    onlineStatus = OnlineStatus.OFFLINE.ordinal();
    for (int i = SocialNetwork.FACEBOOK_COM.ordinal(); i < SocialNetwork.MICROSOFT.ordinal(); i++) {
        NetworkPresence networkPresence = new NetworkPresence(userId, i, onlineStatus);
        presenceList.set(i, networkPresence);
        MePresenceCacheTable.updateCache(networkPresence, mTestDatabase.getWritableDatabase());
        assertTrue(checkCacheEquals(presenceList));
    }
}
Also used : NetworkPresence(com.vodafone360.people.engine.presence.NetworkPresence) ArrayList(java.util.ArrayList)

Example 3 with OnlineStatus

use of com.vodafone360.people.datatypes.ContactSummary.OnlineStatus in project 360-Engine-for-Android by 360.

the class NowPlusContactSummaryTest method testUpdateOnlineStatus.

public void testUpdateOnlineStatus() {
    Log.i(LOG_TAG, "***** EXECUTING testUpdateOnlineStatus() *****");
    Log.i(LOG_TAG, "Create ContactSummaryTable");
    ContactSummaryTable.create(mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Add a contact to ContactSummaryTable");
    final Contact contact = mTestModule.createDummyContactData();
    contact.localContactID = new Long(10);
    contact.nativeContactId = new Integer(11);
    ContactSummaryTable.addContact(contact, mTestDatabase.getWritableDatabase());
    Log.i(LOG_TAG, "Fetching a ContactSummary from ContactSummaryTable");
    final ContactSummary contactSummary = new ContactSummary();
    final ServiceStatus serviceStatus = ContactSummaryTable.fetchSummaryItem(contact.localContactID, contactSummary, mTestDatabase.getReadableDatabase());
    assertEquals(ServiceStatus.SUCCESS, serviceStatus);
    compareContactWithContactSummary(contact, contactSummary);
    // create a new user
    Hashtable<String, String> status = new Hashtable<String, String>();
    status.put("google", "online");
    status.put("microsoft", "online");
    status.put("mobile", "online");
    status.put("pc", "online");
    User user = new User("any", status);
    user.setLocalContactId(contactSummary.localContactID);
    // set him online
    assertEquals(ServiceStatus.SUCCESS, ContactSummaryTable.updateOnlineStatus(user));
    // fetch again
    final ContactSummary contactSummary2 = new ContactSummary();
    assertEquals(ServiceStatus.SUCCESS, ContactSummaryTable.fetchSummaryItem(user.getLocalContactId(), contactSummary2, mTestDatabase.getReadableDatabase()));
    // check if he's online
    assertEquals(OnlineStatus.ONLINE, contactSummary2.onlineStatus);
}
Also used : ContactSummary(com.vodafone360.people.datatypes.ContactSummary) User(com.vodafone360.people.engine.presence.User) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Hashtable(java.util.Hashtable) Contact(com.vodafone360.people.datatypes.Contact)

Example 4 with OnlineStatus

use of com.vodafone360.people.datatypes.ContactSummary.OnlineStatus in project 360-Engine-for-Android by 360.

the class User method createPayload.

/**
     * @param payload
     * @return
     */
private ArrayList<NetworkPresence> createPayload(String userId, Hashtable<String, String> payload) {
    ArrayList<NetworkPresence> presenceList = new ArrayList<NetworkPresence>(payload.size());
    String parsedUserId = parseUserName(userId);
    String key = null;
    SocialNetwork network = null;
    String value = null;
    OnlineStatus status = null;
    for (Enumeration<String> en = payload.keys(); en.hasMoreElements(); ) {
        key = en.nextElement();
        network = SocialNetwork.getValue(key);
        if (network != null) {
            int keyIdx = network.ordinal();
            value = payload.get(key);
            if (value != null) {
                status = OnlineStatus.getValue(value);
                if (status != null) {
                    int valueIdx = status.ordinal();
                    presenceList.add(new NetworkPresence(parsedUserId, keyIdx, valueIdx));
                }
            }
        }
    }
    return presenceList;
}
Also used : ArrayList(java.util.ArrayList) SocialNetwork(com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork) OnlineStatus(com.vodafone360.people.datatypes.ContactSummary.OnlineStatus)

Example 5 with OnlineStatus

use of com.vodafone360.people.datatypes.ContactSummary.OnlineStatus in project 360-Engine-for-Android by 360.

the class PresenceEngine method getPresencesForStatus.

/**
     * Convenience method.
     * Constructs a Hash table object containing My identities mapped against the provided status.
     * @param status Presence status to set for all identities
     * @return The resulting Hash table, is null if no identities are present
     */
public Hashtable<String, String> getPresencesForStatus(OnlineStatus status) {
    // Get cached identities from the presence engine 
    ArrayList<Identity> identities = EngineManager.getInstance().getIdentityEngine().getMyChattableIdentities();
    if (identities == null) {
        // No identities, just return null
        return null;
    }
    Hashtable<String, String> presences = new Hashtable<String, String>();
    String statusString = status.toString();
    for (Identity identity : identities) {
        presences.put(identity.mNetwork, statusString);
    }
    return presences;
}
Also used : Hashtable(java.util.Hashtable) Identity(com.vodafone360.people.datatypes.Identity)

Aggregations

NetworkPresence (com.vodafone360.people.engine.presence.NetworkPresence)3 User (com.vodafone360.people.engine.presence.User)3 ArrayList (java.util.ArrayList)3 Hashtable (java.util.Hashtable)3 Cursor (android.database.Cursor)2 Contact (com.vodafone360.people.datatypes.Contact)2 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)2 OnlineStatus (com.vodafone360.people.datatypes.ContactSummary.OnlineStatus)2 ServiceStatus (com.vodafone360.people.service.ServiceStatus)2 Identity (com.vodafone360.people.datatypes.Identity)1 SocialNetwork (com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork)1