Search in sources :

Example 1 with AlbumDeserializer

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

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

the class AlbumRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray[] result) {
    JSONArray album = result[0];
    JSONArray owner = result[1];
    JSONArray images = result[2];
    assocData(album, owner, "owner", "id", "owner_name", "name");
    assocData(album, images, "cover_pid", "pid", "cover_images", "images");
    AlbumDeserializer deserializer = new AlbumDeserializer();
    ArrayList<GraphObject> list = (ArrayList<GraphObject>) deserializer.deserializeArray(album);
    setHasMoreData(false);
    return list;
}
Also used : AlbumDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.AlbumDeserializer) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Example 3 with AlbumDeserializer

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

the class UploadableAlbumRequest method handleResult.

@Override
public ArrayList<GraphObject> handleResult(JSONArray result) {
    AlbumDeserializer deserializer = new AlbumDeserializer();
    ArrayList<GraphObject> albums = (ArrayList<GraphObject>) deserializer.deserializeArray(result);
    return albums;
}
Also used : AlbumDeserializer(com.abewy.android.apps.klyph.core.fql.serializer.AlbumDeserializer) ArrayList(java.util.ArrayList) GraphObject(com.abewy.android.apps.klyph.core.graph.GraphObject)

Aggregations

AlbumDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.AlbumDeserializer)3 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)3 ArrayList (java.util.ArrayList)3 JSONArray (org.json.JSONArray)2 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 PhotoDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.PhotoDeserializer)1 ProfileDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.ProfileDeserializer)1 UserDeserializer (com.abewy.android.apps.klyph.core.fql.serializer.UserDeserializer)1 JSONObject (org.json.JSONObject)1