app/src/main/java/io/github/ilya_lebedev/popularmovies/data/MoviesProvider.java
/**
     * Handles query requests.
     *
     * @param uri           The URI to query
     * @param projection    The list of columns to put into the cursor.
     *                      If null, all columns are included.
     * @param selection     A selection criteria.
     *                      If null, all rows are included.
     * @param selectionArgs You may include ?s in selection, which will be replaced by the values
     *                      from selectionArgs, in order that they appear in the selection.
     *                      The values will be bound as Strings.
     * @param sortOrder     Sort order of the row in the cursor
     *
     * @return A cursor containing the results of the query
     */
Handles query requests.
@param uri           The URI to query
@param projection    The list of columns to put into the cursor.
If null, all columns are included.
@param selection     A selection criteria.
If null, all rows are included.
@param selectionArgs You may include ?s in selection, which will be replaced by the values
from selectionArgs, in order that they appear in the selection.
The values will be bound as Strings.
@param sortOrder     Sort order of the row in the cursor

@return A cursor containing the results of the query
Handles query requests . @param uri The URI to query @param projection The list of columns to put into the cursor . If null all columns are included . @param selection A selection criteria . If null all rows are included . @param selectionArgs You may include ?s in selection which will be replaced by the values from selectionArgs in order that they appear in the selection . The values will be bound as Strings . @param sortOrder Sort order of the row in the cursor @return A cursor containing the results of the query
@Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
                        @Nullable String[] selectionArgs, @Nullable String sortOrder) {
        Cursor cursor;
        switch (sUriMatcher.match(uri)) {
            case CODE_TOP_RATED_MOVIE: {
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.MovieEntry.TABLE_NAME_TOP_RATED,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_TOP_RATED_MOVIE_WITH_TMDB_ID: {
                String id = uri.getLastPathSegment();
                selection = MoviesContract.MovieEntry.COLUMN_MOVIE_ID + " = ?";
                selectionArgs = new String[] {id};
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.MovieEntry.TABLE_NAME_TOP_RATED,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_MOST_POPULAR_MOVIE: {
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.MovieEntry.TABLE_NAME_MOST_POPULAR,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_MOST_POPULAR_MOVIE_WITH_TMDB_ID: {
                String id = uri.getLastPathSegment();
                selection = MoviesContract.MovieEntry.COLUMN_MOVIE_ID + " = ?";
                selectionArgs = new String[] {id};
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.MovieEntry.TABLE_NAME_MOST_POPULAR,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_FAVORITE_MOVIE: {
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.MovieEntry.TABLE_NAME_FAVORITE,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_FAVORITE_MOVIE_WITH_TMDB_ID: {
                String id = uri.getLastPathSegment();
                selection = MoviesContract.MovieEntry.COLUMN_MOVIE_ID + " = ?";
                selectionArgs = new String[] {id};
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.MovieEntry.TABLE_NAME_FAVORITE,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_MOVIE_VIDEO_WITH_MOVIE_TMDB_ID: {
                String movieId = uri.getLastPathSegment();
                selection = MoviesContract.VideoEntry.COLUMN_MOVIE_TMDB_ID + " = ?";
                selectionArgs = new String[] { movieId };
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.VideoEntry.TABLE_NAME,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_MOVIE_REVIEW_WITH_ID: {
                String id = uri.getLastPathSegment();
                selection = MoviesContract.VideoEntry._ID + " = ?";
                selectionArgs = new String[] { id };
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.ReviewEntry.TABLE_NAME,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            case CODE_MOVIE_REVIEW_WITH_MOVIE_TMDB_ID: {
                String movieId = uri.getLastPathSegment();
                selection = MoviesContract.ReviewEntry.COLUMN_MOVIE_TMDB_ID + " = ?";
                selectionArgs = new String[] { movieId };
                cursor = mOpenHelper.getReadableDatabase().query(
                        MoviesContract.ReviewEntry.TABLE_NAME,
                        projection,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        sortOrder
                );
                break;
            }
            default:
                throw new UnsupportedOperationException("Unknown uri: " + uri);
        }
        cursor.setNotificationUri(getContext().getContentResolver(), uri);
        return cursor;
    }
@ Nullable @ Override public Cursor query ( @ NonNull Uri uri , @ Nullable String [ ] projection , @ Nullable String selection , @ Nullable String [ ] selectionArgs , @ Nullable String sortOrder ) { Cursor cursor ; switch ( sUriMatcher . match ( uri ) ) { case CODE_TOP_RATED_MOVIE : { cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . MovieEntry . TABLE_NAME_TOP_RATED , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_TOP_RATED_MOVIE_WITH_TMDB_ID : { String id = uri . getLastPathSegment ( ) ; selection = MoviesContract . MovieEntry . COLUMN_MOVIE_ID + " = ?" ; selectionArgs = new String [ ] { id } ; cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . MovieEntry . TABLE_NAME_TOP_RATED , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_MOST_POPULAR_MOVIE : { cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . MovieEntry . TABLE_NAME_MOST_POPULAR , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_MOST_POPULAR_MOVIE_WITH_TMDB_ID : { String id = uri . getLastPathSegment ( ) ; selection = MoviesContract . MovieEntry . COLUMN_MOVIE_ID + " = ?" ; selectionArgs = new String [ ] { id } ; cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . MovieEntry . TABLE_NAME_MOST_POPULAR , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_FAVORITE_MOVIE : { cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . MovieEntry . TABLE_NAME_FAVORITE , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_FAVORITE_MOVIE_WITH_TMDB_ID : { String id = uri . getLastPathSegment ( ) ; selection = MoviesContract . MovieEntry . COLUMN_MOVIE_ID + " = ?" ; selectionArgs = new String [ ] { id } ; cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . MovieEntry . TABLE_NAME_FAVORITE , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_MOVIE_VIDEO_WITH_MOVIE_TMDB_ID : { String movieId = uri . getLastPathSegment ( ) ; selection = MoviesContract . VideoEntry . COLUMN_MOVIE_TMDB_ID + " = ?" ; selectionArgs = new String [ ] { movieId } ; cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . VideoEntry . TABLE_NAME , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_MOVIE_REVIEW_WITH_ID : { String id = uri . getLastPathSegment ( ) ; selection = MoviesContract . VideoEntry . _ID + " = ?" ; selectionArgs = new String [ ] { id } ; cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . ReviewEntry . TABLE_NAME , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } case CODE_MOVIE_REVIEW_WITH_MOVIE_TMDB_ID : { String movieId = uri . getLastPathSegment ( ) ; selection = MoviesContract . ReviewEntry . COLUMN_MOVIE_TMDB_ID + " = ?" ; selectionArgs = new String [ ] { movieId } ; cursor = mOpenHelper . getReadableDatabase ( ) . query ( MoviesContract . ReviewEntry . TABLE_NAME , projection , selection , selectionArgs , null , null , sortOrder ) ; break ; } default : throw new UnsupportedOperationException ( "Unknown uri: " + uri ) ; } cursor . setNotificationUri ( getContext ( ) . getContentResolver ( ) , uri ) ; return cursor ; }
Handles query requests.
Handles query requests .