Search in sources :

Example 1 with FriendRequestDeserializer

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

the class FriendsRequestNotificationRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray data = result[0];
    JSONArray urls = result[1];
    JSONArray names = result[2];
    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(data, urls, "uid_from", "id", "uid_from_pic", "url");
    assocData(data, names, "uid_from", "id", "uid_from_name", "name");
    FriendRequestDeserializer deserializer = new FriendRequestDeserializer();
    ArrayList<GraphObject> friendRequests = (ArrayList<GraphObject>) deserializer.deserializeArray(data);
    return friendRequests;
}
Also used : JSONObject(org.json.JSONObject) FriendRequestDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 2 with FriendRequestDeserializer

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

the class UserProfileRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray userData = result[0];
    JSONArray familyData = result[1];
    JSONArray urls = result[2];
    JSONArray isFriend = result[3];
    JSONArray friendRequest = result[4];
    assocData(userData, urls, "uid", "id", "pic", "url");
    JSONObject user = userData.optJSONObject(0);
    ArrayList<GraphObject> data = null;
    if (user != null) {
        try {
            user.put("family", familyData);
        } catch (JSONException e) {
        }
        if (isFriend != null && isFriend.length() == 1) {
            try {
                user.putOpt("isFriend", true);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        UserDeserializer deserializer = new UserDeserializer();
        data = (ArrayList<GraphObject>) deserializer.deserializeArray(userData);
        FriendRequestDeserializer frDeserializer = new FriendRequestDeserializer();
        List<GraphObject> fr = frDeserializer.deserializeArray(friendRequest);
        if (fr.size() > 0) {
            data.add(fr.get(0));
        }
    } else {
        data = new ArrayList<GraphObject>();
    }
    setHasMoreData(false);
    return data;
}
Also used : UserDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.UserDeserializer) JSONObject(org.json.JSONObject) FriendRequestDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 3 with FriendRequestDeserializer

use of com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer 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 4 with FriendRequestDeserializer

use of com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer 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)

Aggregations

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