private void extractListFromJSON(String jsonStr) {

    try {
      moviesList.clear();
      JSONObject moviesJson = new JSONObject(jsonStr);
      JSONArray moviesArray = moviesJson.getJSONArray("results");

      for (int i = 0; i < moviesArray.length(); i++) {
        Movie tempMovie = new Movie();
        JSONObject jo = moviesArray.getJSONObject(i);
        tempMovie.setTitle(jo.getString(getString(R.string.ORIGIONAL_TITLE_PARAM)));
        tempMovie.setId(jo.getString(getString(R.string.ID)));
        tempMovie.setPoster_Location(jo.getString(getString(R.string.POSTER_PATH_PARAM)));
        tempMovie.setBackdrop_path(jo.getString(getString(R.string.BACKDROP_PATH_PARAM)));
        tempMovie.setOverview(jo.getString(getString(R.string.OVERVIEW_PARAM)));
        tempMovie.setRelease_Date(jo.getString(getString(R.string.RELEASE_DATE_PARAM)));
        tempMovie.setRating(jo.getString(getString(R.string.RATING_PARAM)));
        tempMovie.setPopularity(jo.getString(getString(R.string.POPULARITY_PARAM)));
        moviesList.add(tempMovie);
      }

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
 @Before
 public void setUp() throws Exception {
   movie = new Movie(ID, TITLE);
   movie.setOverview(OVERVIEW);
   movie.setReleaseDate(RELEASE_DATE);
   movie.setPosterPath(POSTER_PATH);
   movie.setPopularity(POPULARITY);
   movie.setOriginalTitle(ORIGINAL_TITLE);
   movie.setAverageVote(AVERAGE_VOTE);
   movie.setVoteCount(VOTE_COUNT);
   movie.setBackdropPath(BACKDROP_PATH);
 }
  private void extractMovieFromJSON(String jsonStr) {

    try {
      JSONObject jo = new JSONObject(jsonStr);

      Movie tempMovie = new Movie();
      tempMovie.setTitle(jo.getString(getString(R.string.ORIGIONAL_TITLE_PARAM)));
      tempMovie.setId(jo.getString(getString(R.string.ID)));
      tempMovie.setPoster_Location(jo.getString(getString(R.string.POSTER_PATH_PARAM)));
      tempMovie.setBackdrop_path(jo.getString(getString(R.string.BACKDROP_PATH_PARAM)));
      tempMovie.setOverview(jo.getString(getString(R.string.OVERVIEW_PARAM)));
      tempMovie.setRelease_Date(jo.getString(getString(R.string.RELEASE_DATE_PARAM)));
      tempMovie.setRating(jo.getString(getString(R.string.RATING_PARAM)));
      tempMovie.setPopularity(jo.getString(getString(R.string.POPULARITY_PARAM)));
      moviesList.add(tempMovie);

    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  public ArrayList<Movie> loadMovies() {
    ArrayList<Movie> movies = new ArrayList<Movie>();

    Cursor movieCursor =
        mContext
            .getContentResolver()
            .query(MovieContract.MovieEntry.CONTENT_URI, null, null, null, null);

    movieCursor.moveToFirst();
    do {
      Integer movieId =
          movieCursor.getInt(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_MOVIE_ID));
      String title =
          movieCursor.getString(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_TITLE));
      boolean adult =
          movieCursor.getInt(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_ADULT)) != 0
              ? true
              : false;
      String backDropPath =
          movieCursor.getString(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_BACKDROP_PATH));
      String genreIdsString =
          movieCursor.getString(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_GENRE_IDS));
      String[] genreStrings = genreIdsString.split(",");
      ArrayList<Integer> genreIds = new ArrayList<Integer>();
      for (String s : genreStrings) {
        genreIds.add(Integer.parseInt(s));
      }
      String orgLanguage =
          movieCursor.getString(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_ORIGINAL_LANGUAGE));
      String orgTitle =
          movieCursor.getString(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_ORIGINAL_TITLE));
      String overview =
          movieCursor.getString(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_OVERVIEW));
      String releasString =
          movieCursor.getString(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_RELEASE_DATE));
      SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", new Locale("us"));
      Date releaseDate = new Date();
      try {
        releaseDate = sdf.parse(releasString);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      String posterPath =
          movieCursor.getString(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_POSTER_PATH));
      Double popularity =
          movieCursor.getDouble(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_POPULARITY));
      boolean isVideo =
          movieCursor.getInt(movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_VIDEO)) != 0
              ? true
              : false;
      Double voteAverage =
          movieCursor.getDouble(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_VOTE_AVERAGE));
      Integer voteCount =
          movieCursor.getInt(
              movieCursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_VOTE_COUNT));

      Movie movie = new Movie();
      movie.setId(movieId);
      movie.setTitle(title);
      movie.setAdult(adult);
      movie.setBackdrop_path(backDropPath);
      movie.setOriginal_language(orgLanguage);
      movie.setOriginal_title(orgTitle);
      movie.setOverview(overview);
      movie.setRelease_date(releaseDate);
      movie.setPoster_path(posterPath);
      movie.setPopularity(popularity);
      movie.setVideo(isVideo);
      movie.setVote_average(voteAverage);
      movie.setVote_count(voteCount);
      movies.add(movie);
    } while (movieCursor.moveToNext());

    return movies;
  }