Search in sources :

Example 1 with NotificationDeserializer

use of com.abewy.android.apps.klyph.core.fql.serializer.NotificationDeserializer in project Klyph by jonathangerbaud.

the class NotificationRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray notifications = result[0];
    JSONArray friendRequests = result[1];
    JSONArray urls = result[2];
    JSONArray names = result[3];
    JSONArray groups = result[4];
    assocData(notifications, urls, "sender_id", "id", "sender_pic", "url");
    assocData(notifications, names, "sender_id", "id", "sender_name", "name");
    assocStreamToObjectById(notifications, groups, "object_id", "gid", "group");
    for (int i = 0; i < urls.length(); i++) {
        JSONObject jsonObject = urls.optJSONObject(i);
        try {
            jsonObject.putOpt("id", String.valueOf(jsonObject.opt("id")));
        } catch (JSONException e) {
        // e.printStackTrace();
        }
    }
    for (int i = 0; i < names.length(); i++) {
        JSONObject jsonObject = names.optJSONObject(i);
        try {
            jsonObject.putOpt("id", String.valueOf(jsonObject.opt("id")));
        } catch (JSONException e) {
        // e.printStackTrace();
        }
    }
    assocData(notifications, names, "object_id", "id", "object_name", "name");
    assocData(friendRequests, urls, "uid_from", "id", "uid_from_pic", "url");
    assocData(friendRequests, names, "uid_from", "id", "uid_from_name", "name");
    NotificationDeserializer nDeserializer = new NotificationDeserializer();
    ArrayList<GraphObject> n = (ArrayList<GraphObject>) nDeserializer.deserializeArray(notifications);
    FriendRequestDeserializer fDeserializer = new FriendRequestDeserializer();
    ArrayList<GraphObject> f = (ArrayList<GraphObject>) fDeserializer.deserializeArray(friendRequests);
    ArrayList<GraphObject> list = new ArrayList<GraphObject>();
    list.addAll(n);
    list.addAll(f);
    setHasMoreData(false);
    return list;
}
Also used : JSONObject(org.json.JSONObject) FriendRequestDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer) NotificationDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.NotificationDeserializer) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 2 with NotificationDeserializer

use of com.abewy.android.apps.klyph.core.fql.serializer.NotificationDeserializer in project Klyph by jonathangerbaud.

the class NotificationRequest2 method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray notifications = result[0];
    JSONArray friendRequests = result[1];
    JSONArray urls = result[2];
    JSONArray names = result[3];
    JSONArray friends = result[4];
    JSONArray events = result[5];
    JSONArray pages = result[6];
    JSONArray groups = result[7];
    JSONArray comments = result[8];
    assocData(notifications, urls, "sender_id", "id", "sender_pic", "url");
    assocData(notifications, names, "sender_id", "id", "sender_name", "name");
    assocStreamToObjectById(notifications, friends, "object_id", "uid", "friend");
    assocStreamToObjectById(notifications, events, "object_id", "eid", "event");
    assocStreamToObjectById(notifications, pages, "object_id", "page_id", "page");
    assocStreamToObjectById(notifications, groups, "object_id", "gid", "group");
    assocStreamToObjectById(notifications, comments, "object_id", "object_id", "comment");
    for (int i = 0; i < urls.length(); i++) {
        JSONObject jsonObject = urls.optJSONObject(i);
        try {
            jsonObject.putOpt("id", String.valueOf(jsonObject.opt("id")));
        } catch (JSONException e) {
        // e.printStackTrace();
        }
    }
    for (int i = 0; i < names.length(); i++) {
        JSONObject jsonObject = names.optJSONObject(i);
        try {
            jsonObject.putOpt("id", String.valueOf(jsonObject.opt("id")));
        } catch (JSONException e) {
        // e.printStackTrace();
        }
    }
    assocData(friendRequests, urls, "uid_from", "id", "uid_from_pic", "url");
    assocData(friendRequests, names, "uid_from", "id", "uid_from_name", "name");
    NotificationDeserializer nDeserializer = new NotificationDeserializer();
    ArrayList<GraphObject> n = (ArrayList<GraphObject>) nDeserializer.deserializeArray(notifications);
    FriendRequestDeserializer fDeserializer = new FriendRequestDeserializer();
    ArrayList<GraphObject> f = (ArrayList<GraphObject>) fDeserializer.deserializeArray(friendRequests);
    ArrayList<GraphObject> list = new ArrayList<GraphObject>();
    list.addAll(n);
    list.addAll(f);
    setHasMoreData(false);
    return list;
}
Also used : JSONObject(org.json.JSONObject) FriendRequestDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer) NotificationDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.NotificationDeserializer) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 3 with NotificationDeserializer

use of com.abewy.android.apps.klyph.core.fql.serializer.NotificationDeserializer in project Klyph by jonathangerbaud.

the class PeriodicNotificationRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray data = result[0];
    JSONArray urls = result[1];
    JSONArray names = result[2];
    JSONArray friends = result[3];
    JSONArray events = result[4];
    JSONArray pages = result[5];
    JSONArray groups = result[6];
    JSONArray comments = result[7];
    Log.d("NotificationRequest", "size " + data.length());
    assocData(data, urls, "sender_id", "id", "sender_pic", "url");
    assocData(data, names, "sender_id", "id", "sender_name", "name");
    assocStreamToObjectById(data, friends, "object_id", "uid", "friend");
    assocStreamToObjectById(data, events, "object_id", "eid", "event");
    assocStreamToObjectById(data, pages, "object_id", "page_id", "page");
    assocStreamToObjectById(data, groups, "object_id", "gid", "group");
    assocStreamToObjectById(data, comments, "object_id", "object_id", "comment");
    NotificationDeserializer deserializer = new NotificationDeserializer();
    ArrayList<GraphObject> notifications = (ArrayList<GraphObject>) deserializer.deserializeArray(data);
    return notifications;
}
Also used : NotificationDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.NotificationDeserializer) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Aggregations

NotificationDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.NotificationDeserializer)3 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)3 ArrayList (java.util.ArrayList)3 JSONArray (org.json.JSONArray)3 FriendRequestDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2