app/src/main/java/io/github/ilya_lebedev/popularmovies/data/MoviesProvider.java
/**
     * Deletes data at a given URI with optional arguments.
     *
     * @param uri           The full URI to query
     * @param selection     An optional restriction to apply to rows when deleting
     * @param selectionArgs Used in conjunction with the selection statement
     *
     * @return The number of rows deleted
     */
Deletes data at a given URI with optional arguments.
@param uri           The full URI to query
@param selection     An optional restriction to apply to rows when deleting
@param selectionArgs Used in conjunction with the selection statement

@return The number of rows deleted
Deletes data at a given URI with optional arguments . @param uri The full URI to query @param selection An optional restriction to apply to rows when deleting @param selectionArgs Used in conjunction with the selection statement @return The number of rows deleted
@Override
    public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
        int rowsDeleted;
        /*
         * If selection is null, entire table will be deleted. However, in this case we won't know
         * how many rows were deleted. According to the documentation for SQLiteDatabase, passing
         * "1" for the selection will delete all rows and return the number of rows deleted.
         */
        if (selection == null) selection = "1";
        switch (sUriMatcher.match(uri)) {
            case CODE_TOP_RATED_MOVIE:
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.MovieEntry.TABLE_NAME_TOP_RATED,
                        selection,
                        selectionArgs);
                break;
            case CODE_MOST_POPULAR_MOVIE:
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.MovieEntry.TABLE_NAME_MOST_POPULAR,
                        selection,
                        selectionArgs);
                break;
            case CODE_FAVORITE_MOVIE:
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.MovieEntry.TABLE_NAME_FAVORITE,
                        selection,
                        selectionArgs);
                break;
            case CODE_FAVORITE_MOVIE_WITH_TMDB_ID:
                String id = uri.getLastPathSegment();
                selection = MoviesContract.MovieEntry.COLUMN_MOVIE_ID + " = ?";
                selectionArgs = new String[] {id};
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.MovieEntry.TABLE_NAME_FAVORITE,
                        selection,
                        selectionArgs);
                break;
            case CODE_MOVIE_VIDEO: {
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.VideoEntry.TABLE_NAME,
                        selection,
                        selectionArgs);
                break;
            }
            case CODE_MOVIE_VIDEO_WITH_MOVIE_TMDB_ID: {
                String movieId = uri.getLastPathSegment();
                selection = MoviesContract.VideoEntry.COLUMN_MOVIE_TMDB_ID + " = ?";
                selectionArgs = new String[] { movieId };
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.VideoEntry.TABLE_NAME,
                        selection,
                        selectionArgs);
                break;
            }
            case CODE_MOVIE_REVIEW: {
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.ReviewEntry.TABLE_NAME,
                        selection,
                        selectionArgs);
                break;
            }
            case CODE_MOVIE_REVIEW_WITH_MOVIE_TMDB_ID: {
                String movieId = uri.getLastPathSegment();
                selection = MoviesContract.ReviewEntry.COLUMN_MOVIE_TMDB_ID + " = ?";
                selectionArgs = new String[] { movieId };
                rowsDeleted = mOpenHelper.getWritableDatabase().delete(
                        MoviesContract.ReviewEntry.TABLE_NAME,
                        selection,
                        selectionArgs);
                break;
            }
            default:
                throw new UnsupportedOperationException("Unknown uri: " + uri);
        }
        if (rowsDeleted != 0) {
            getContext().getContentResolver().notifyChange(uri, null);
        }
        return rowsDeleted;
    }
@ Override public int delete ( @ NonNull Uri uri , @ Nullable String selection , @ Nullable String [ ] selectionArgs ) { int rowsDeleted ; /*
         * If selection is null, entire table will be deleted. However, in this case we won't know
         * how many rows were deleted. According to the documentation for SQLiteDatabase, passing
         * "1" for the selection will delete all rows and return the number of rows deleted.
         */ if ( selection == null ) selection = "1" ; switch ( sUriMatcher . match ( uri ) ) { case CODE_TOP_RATED_MOVIE : rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . MovieEntry . TABLE_NAME_TOP_RATED , selection , selectionArgs ) ; break ; case CODE_MOST_POPULAR_MOVIE : rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . MovieEntry . TABLE_NAME_MOST_POPULAR , selection , selectionArgs ) ; break ; case CODE_FAVORITE_MOVIE : rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . MovieEntry . TABLE_NAME_FAVORITE , selection , selectionArgs ) ; break ; case CODE_FAVORITE_MOVIE_WITH_TMDB_ID : String id = uri . getLastPathSegment ( ) ; selection = MoviesContract . MovieEntry . COLUMN_MOVIE_ID + " = ?" ; selectionArgs = new String [ ] { id } ; rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . MovieEntry . TABLE_NAME_FAVORITE , selection , selectionArgs ) ; break ; case CODE_MOVIE_VIDEO : { rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . VideoEntry . TABLE_NAME , selection , selectionArgs ) ; break ; } case CODE_MOVIE_VIDEO_WITH_MOVIE_TMDB_ID : { String movieId = uri . getLastPathSegment ( ) ; selection = MoviesContract . VideoEntry . COLUMN_MOVIE_TMDB_ID + " = ?" ; selectionArgs = new String [ ] { movieId } ; rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . VideoEntry . TABLE_NAME , selection , selectionArgs ) ; break ; } case CODE_MOVIE_REVIEW : { rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . ReviewEntry . TABLE_NAME , selection , selectionArgs ) ; break ; } case CODE_MOVIE_REVIEW_WITH_MOVIE_TMDB_ID : { String movieId = uri . getLastPathSegment ( ) ; selection = MoviesContract . ReviewEntry . COLUMN_MOVIE_TMDB_ID + " = ?" ; selectionArgs = new String [ ] { movieId } ; rowsDeleted = mOpenHelper . getWritableDatabase ( ) . delete ( MoviesContract . ReviewEntry . TABLE_NAME , selection , selectionArgs ) ; break ; } default : throw new UnsupportedOperationException ( "Unknown uri: " + uri ) ; } if ( rowsDeleted != 0 ) { getContext ( ) . getContentResolver ( ) . notifyChange ( uri , null ) ; } return rowsDeleted ; }
Deletes data at a given URI with optional arguments.
Deletes data at a given URI with optional arguments .