Search in sources :

Example 1 with CommentDeserializer

use of com.abewy.android.apps.klyph.core.graph.serializer.CommentDeserializer in project Klyph by jonathangerbaud.

the class CommentsRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray result) {
    JSONArray jsonArray = new JSONArray();
    int n = result.length();
    for (int i = 0; i < n; i++) {
        JSONObject comment = result.optJSONObject(i);
        if (comment != null) {
            JSONObject parent = comment.optJSONObject("parent");
            // If this is a reply, then we skip it
            if (parent != null) {
                continue;
            }
            jsonArray.put(comment);
            JSONObject subComments = comment.optJSONObject("comments");
            if (subComments != null) {
                JSONArray data = subComments.optJSONArray("data");
                if (data != null) {
                    int m = data.length();
                    for (int j = 0; j < m; j++) {
                        JSONObject subComment = data.optJSONObject(j);
                        if (subComment != null) {
                            jsonArray.put(subComment);
                        }
                    }
                }
            }
        }
    }
    CommentDeserializer deserializer = new CommentDeserializer();
    ArrayList<GraphObject> comments = (ArrayList<GraphObject>) deserializer.deserializeArray(jsonArray);
    setHasMoreData(comments.size() > 0);
    return comments;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) CommentDeserializer(com.abewy.android.apps.klyph.core.graph.serializer.CommentDeserializer) ArrayList(java.util.ArrayList) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Aggregations

GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)1 CommentDeserializer (com.abewy.android.apps.klyph.core.graph.serializer.CommentDeserializer)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1