Search in sources :

Example 1 with UserDeserializer

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

the class ElementAlbumRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray data = result[0];
    JSONArray photos = result[1];
    assocData(data, photos, "cover_pid", "pid", "cover_images", "images");
    int n = 25;
    Album taggedAlbum = null;
    Album videoAlbum = null;
    if (result.length == 6) {
        JSONArray tagged = result[2];
        JSONArray user = result[3];
        JSONArray profile = result[4];
        PhotoDeserializer pd = new PhotoDeserializer();
        List<GraphObject> taggedPhotos = pd.deserializeArray(tagged);
        int nt = taggedPhotos.size();
        if (nt > 0) {
            taggedAlbum = new Album();
            taggedAlbum.setOwner(id);
            taggedAlbum.setPhoto_count(nt);
            taggedAlbum.setVideo_count(0);
            taggedAlbum.setIsTaggedAlbum(true);
            taggedAlbum.setIs_video_album(false);
            String eName = "";
            if (user.length() > 0) {
                UserDeserializer ud = new UserDeserializer();
                User u = (User) ud.deserializeArray(user).get(0);
                eName = u.getFirst_name().length() > 0 ? u.getFirst_name() : u.getName();
            } else if (profile.length() > 0) {
                ProfileDeserializer prd = new ProfileDeserializer();
                Profile p = (Profile) prd.deserializeArray(profile).get(0);
                eName = p.getName();
            }
            taggedAlbum.setName(KlyphApplication.getInstance().getString(R.string.tagged_photos_of, eName));
            Photo photo = (Photo) taggedPhotos.get(0);
            taggedAlbum.setCover_pid(photo.getPid());
            taggedAlbum.setCover_images(photo.getImages());
        }
        JSONArray videos = result[5];
        if (videos.length() > 0) {
            videoAlbum = new Album();
            videoAlbum.setOwner(id);
            videoAlbum.setPhoto_count(nt);
            videoAlbum.setVideo_count(0);
            videoAlbum.setIsTaggedAlbum(false);
            videoAlbum.setIs_video_album(true);
            for (int i = 0; i < videos.length(); i++) {
                JSONObject v = videos.optJSONObject(i);
                if (v != null && v.optString("thumbnail_link") != null) {
                    Image cover = new Photo.Image();
                    cover.setSource(v.optString("thumbnail_link"));
                    List<Image> images = new ArrayList<Photo.Image>();
                    images.add(cover);
                    videoAlbum.setOwner(v.optString("owner"));
                    videoAlbum.setCover_images(images);
                    break;
                }
            }
        }
    }
    AlbumDeserializer deserializer = new AlbumDeserializer();
    ArrayList<GraphObject> albums = (ArrayList<GraphObject>) deserializer.deserializeArray(data);
    if (videoAlbum != null)
        albums.add(0, videoAlbum);
    if (taggedAlbum != null)
        albums.add(0, taggedAlbum);
    setHasMoreData(albums.size() >= n);
    return albums;
}
Also used : UserDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.UserDeserializer) User(com.abewy.android.apps.klyph.core.fql.User) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Album(com.abewy.android.apps.klyph.core.fql.Album) PhotoDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.PhotoDeserializer) Photo(com.abewy.android.apps.klyph.core.fql.Photo) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject) Image(com.abewy.android.apps.klyph.core.fql.Photo.Image) Profile(com.abewy.android.apps.klyph.core.fql.Profile) JSONObject(org.json.JSONObject) AlbumDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.AlbumDeserializer) ProfileDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.ProfileDeserializer)

Example 2 with UserDeserializer

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

the class UserRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray userData = result[0];
    JSONArray urls = result[1];
    assocData(userData, urls, "uid", "id", "pic", "url");
    JSONObject user = userData.optJSONObject(0);
    ArrayList<GraphObject> data = null;
    if (user != null) {
        UserDeserializer deserializer = new UserDeserializer();
        data = (ArrayList<GraphObject>) deserializer.deserializeArray(userData);
    } 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) JSONArray(org.json.JSONArray) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 3 with UserDeserializer

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

Aggregations

UserDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.UserDeserializer)3 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 Album (com.abewy.android.apps.klyph.core.fql.Album)1 Photo (com.abewy.android.apps.klyph.core.fql.Photo)1 Image (com.abewy.android.apps.klyph.core.fql.Photo.Image)1 Profile (com.abewy.android.apps.klyph.core.fql.Profile)1 User (com.abewy.android.apps.klyph.core.fql.User)1 AlbumDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.AlbumDeserializer)1 FriendRequestDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.FriendRequestDeserializer)1 PhotoDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.PhotoDeserializer)1 ProfileDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.ProfileDeserializer)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1