re-format the code and add image url
prithugoswami prithugoswami524@gmail.com
Wed, 01 May 2019 15:23:25 +0530
2 files changed,
10 insertions(+),
8 deletions(-)
M
src/com/oocpro/tmdbdesktop/Constants.java
→
src/com/oocpro/tmdbdesktop/Constants.java
@@ -2,5 +2,6 @@ package com.oocpro.tmdbdesktop;
public class Constants{ public static final String BASEURL="https://api.themoviedb.org/3"; + public static final String IMG_URL="https://image.tmdb.org/t/p/w500"; public static final String API_KEY="b888b64c9155c26ade5659ea4dd60e64"; }
M
src/com/oocpro/tmdbdesktop/tmdb/Movie.java
→
src/com/oocpro/tmdbdesktop/tmdb/Movie.java
@@ -1,13 +1,14 @@
-package com.oocpro.tmdbdesktop.Tmdb; +package com.oocpro.tmdbdesktop.tmdb; import com.oocpro.tmdbdesktop.Constants; -import java.io.IOException; + import java.io.InputStream; +import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; -import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; -import java.util.Iterator; -import java.util.ArrayList; import org.json.*; public class Movie{@@ -23,10 +24,10 @@ String geturl = MOVIEBASEURL+id+"?api_key="+Constants.API_KEY;
InputStream res = (InputStream)new URL(geturl).getContent(); JSONObject movie = new JSONObject(new JSONTokener(res)); - JSONArray ja_genres = movie.getJSONArray("genres"); - Iterator genres_itr = ja_genres.iterator(); - genres = new ArrayList<String>(); + Iterator genres_itr = movie.getJSONArray("genres").iterator(); + + // iterate through each genre and add it's `name` to the `genres` list while(genres_itr.hasNext()){ JSONObject jo = (JSONObject)genres_itr.next(); genres.add(jo.getString("name"));