LOG.debug("Feeds json string :: " + respStr);
JSONArray jarr = new JSONArray(respStr);
LOG.debug("Feeds count :: " + jarr.length());
for (int i = 0; i < jarr.length(); i++) {
Album album = new Album();
JSONObject jobj = jarr.getJSONObject(i);
if (jobj.has("user")) {
JSONObject userObj = jobj.getJSONObject("user");
if (jobj.has("entities")) {
JSONObject entitiesObj = jobj.getJSONObject("entities");
if (entitiesObj.has("media")) {
JSONObject mediaObj = entitiesObj.getJSONArray("media")
.getJSONObject(0);
if (mediaObj.has("type")
&& mediaObj.getString("type").equalsIgnoreCase(
"photo")) {
if (userObj.has("name")
&& mediaObj.has("media_url")) {
List<Photo> photos = photo_data.get(userObj
.getString("name"));
if (photos == null) {
photos = new ArrayList<Photo>();
photo_data.put(userObj.getString("name"),
photos);
album.setName(userObj.getString("name"));
album.setCoverPhoto(userObj.getString(
"profile_image_url").replaceAll(
"_normal", "_reasonably_small"));
albums.add(album);
}
Photo photo = new Photo();
String photoURL = mediaObj
.getString("media_url");
photo.setThumbImage(photoURL + ":thumb");
photo.setSmallImage(photoURL + ":small");
photo.setMediumImage(photoURL);
photo.setLargeImage(photoURL + ":large");
if (jobj.has("text")) {
photo.setTitle(jobj.getString("text"));
}
if (mediaObj.has("id_str")) {
photo.setId(mediaObj.getString("id_str"));
}
if (mediaObj.has("expanded_url")) {
photo.setLink(mediaObj
.getString("expanded_url"));
}
if (jobj.has("retweet_count")) {
Map<String, String> map = new HashMap<String, String>();
map.put("retweet_count", String
.valueOf(jobj
.getInt("retweet_count")));
photo.setMetaData(map);
}
photos.add(photo);
}
}
}
}
}
}
for (Album album : albums) {
List<Photo> photos = photo_data.get(album.getName());
album.setPhotos(photos);
album.setPhotosCount(photos.size());
}
return albums;
}