@Override protected SearchMovieContainer doInBackground(String... params) { SearchMovieContainer searchMovieContainer = new SearchMovieContainer(); WatchListDatabaseHandler watchListDatabaseHandler = new WatchListDatabaseHandler(context); MovieContainer movieContainer = watchListDatabaseHandler.getMovieIdsByListTitle(listTitle); for (com.watchlistapp.watchlistserver.Movie myMovieId : movieContainer.getMovieArrayList()) { String url = BASE_URL + myMovieId.getId() + "?" + API_KEY_TITLE + "=" + DeveloperKeys.THE_MOVIE_DB_DEVELOPER_KEY; JSONObject jsonObject = RequestsUtil.getJSONObject(url); Movie movie = parseJSONObject(jsonObject); SearchMovieElement searchMovieElement = new SearchMovieElement(); searchMovieElement.setTitle(movie.getTitle()); searchMovieElement.setVote_average(movie.getVoteAverage()); searchMovieElement.setPoster_path(movie.getPosterPath()); searchMovieElement.setVote_count(movie.getVoteCount()); searchMovieElement.setRelease_date(movie.getReleaseDate()); searchMovieElement.setId(myMovieId.getId()); searchMovieContainer.getSearchMovieElementArrayList().add(searchMovieElement); } return searchMovieContainer; }
private Movie parseJSONObject(JSONObject jsonObject) { Movie movie = new Movie(); try { movie.setTitle(jsonObject.getString(API_TITLE_TITLE)); movie.setReleaseDate(jsonObject.getString("release_date")); movie.setVoteAverage(jsonObject.getString("vote_average")); movie.setVoteCount(jsonObject.getString("vote_count")); movie.setPosterPath(jsonObject.getString("poster_path")); } catch (JSONException exception) { exception.printStackTrace(); } return movie; }