public static long addMovieToFavorite(Context mContext, Movie movie) { long movieRowId = MovieUtils.getMovieRowFromDatabase(mContext, movie.getId()); if (movieRowId == -1) { ContentValues movieValues = new ContentValues(); movieValues.put(FavoriteMoviesContract.MovieEntry.COLUMN_TMDB_MOVIE_ID, movie.getId()); movieValues.put(FavoriteMoviesContract.MovieEntry.COLUMN_TITLE, movie.getTitle()); movieValues.put( FavoriteMoviesContract.MovieEntry.COLUMN_RELEASE_DATE, movie.getReleaseDate()); movieValues.put( FavoriteMoviesContract.MovieEntry.COLUMN_VOTE_AVERAGE, movie.getVoteAverage()); movieValues.put(FavoriteMoviesContract.MovieEntry.COLUMN_VOTE_COUNT, movie.getVoteCount()); movieValues.put(FavoriteMoviesContract.MovieEntry.COLUMN_POPULARITY, movie.getPopularity()); movieValues.put(FavoriteMoviesContract.MovieEntry.COLUMN_OVERVIEW, movie.getOverview()); movieValues.put(FavoriteMoviesContract.MovieEntry.COLUMN_POSTER_PATH, movie.getPosterPath()); movieValues.put( FavoriteMoviesContract.MovieEntry.COLUMN_BACKDROP_PATH, movie.getBackdropPath()); Uri insertedUri = mContext .getContentResolver() .insert(FavoriteMoviesContract.MovieEntry.CONTENT_URI, movieValues); movieRowId = ContentUris.parseId(insertedUri); } return movieRowId; }
public static Movie getMovieFromCursor(Cursor cursor, int pos) { Movie movie = new Movie(); Log.i(LOG_TAG, "Inside getMovieFromCursor(), with cursor position : " + pos); if (cursor.moveToPosition(pos)) { movie.setId(cursor.getLong(MovieUtils.COL_MOVIE_TMDB_MOVIE_ID)); movie.setTitle(cursor.getString(MovieUtils.COL_MOVIE_TITLE)); movie.setReleaseDate(cursor.getString(MovieUtils.COL_MOVIE_RELEASE_DATE)); movie.setVoteAverage(cursor.getDouble(MovieUtils.COL_MOVIE_VOTE_AVERAGE)); movie.setVoteCount(cursor.getLong(MovieUtils.COL_MOVIE_VOTE_COUNT)); movie.setOverview(cursor.getString(MovieUtils.COL_MOVIE_OVERVIEW)); movie.setPosterPath(cursor.getString(MovieUtils.COL_MOVIE_POSTER_PATH)); movie.setBackdropPath(cursor.getString(MovieUtils.COL_MOVIE_BACKDROP_PATH)); movie.setPopularity(cursor.getDouble(MovieUtils.COL_MOVIE_POPULARITY)); movie.setAdult(false); movie.setOriginalLanguage("en"); } else { Log.i(LOG_TAG, "Inside getMovieFromCursor(), invalid Row at given position"); } return movie; }