app/src/main/java/io/github/ilya_lebedev/popularmovies/data/MoviesProvider.java
/**
     * Handles requests to insert a set of new rows.
     *
     * @param uri    The content:// URI of the insertion request.
     * @param values An array of sets of column_name/value pairs to add to the database.
     *
     * @return The number of values that were inserted.
     */
Handles requests to insert a set of new rows.
@param uri    The content:// URI of the insertion request.
@param values An array of sets of column_name/value pairs to add to the database.

@return The number of values that were inserted.
Handles requests to insert a set of new rows . @param uri The content : // URI of the insertion request . @param values An array of sets of column_name / value pairs to add to the database . @return The number of values that were inserted .
@Override
    public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
        final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        String tableName;
        switch (sUriMatcher.match(uri)) {
            case CODE_TOP_RATED_MOVIE:
                tableName = MoviesContract.MovieEntry.TABLE_NAME_TOP_RATED;
                break;
            case  CODE_MOST_POPULAR_MOVIE:
                tableName = MoviesContract.MovieEntry.TABLE_NAME_MOST_POPULAR;
                break;
            case CODE_FAVORITE_MOVIE:
                tableName = MoviesContract.MovieEntry.TABLE_NAME_FAVORITE;
                break;
            case CODE_MOVIE_VIDEO_WITH_MOVIE_TMDB_ID:
                tableName = MoviesContract.VideoEntry.TABLE_NAME;
                break;
            case CODE_MOVIE_REVIEW_WITH_MOVIE_TMDB_ID:
                tableName = MoviesContract.ReviewEntry.TABLE_NAME;
                break;
            default:
                return super.bulkInsert(uri, values);
        }
        db.beginTransaction();
        int rowInserted = 0;
        try {
            for (ContentValues value : values) {
                long _id = db.insert(tableName, null, value);
                if (_id != -1) {
                    rowInserted++;
                }
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
        if (rowInserted > 0) {
            getContext().getContentResolver().notifyChange(uri, null);
        }
        return rowInserted;
    }
@ Override public int bulkInsert ( @ NonNull Uri uri , @ NonNull ContentValues [ ] values ) { final SQLiteDatabase db = mOpenHelper . getWritableDatabase ( ) ; String tableName ; switch ( sUriMatcher . match ( uri ) ) { case CODE_TOP_RATED_MOVIE : tableName = MoviesContract . MovieEntry . TABLE_NAME_TOP_RATED ; break ; case CODE_MOST_POPULAR_MOVIE : tableName = MoviesContract . MovieEntry . TABLE_NAME_MOST_POPULAR ; break ; case CODE_FAVORITE_MOVIE : tableName = MoviesContract . MovieEntry . TABLE_NAME_FAVORITE ; break ; case CODE_MOVIE_VIDEO_WITH_MOVIE_TMDB_ID : tableName = MoviesContract . VideoEntry . TABLE_NAME ; break ; case CODE_MOVIE_REVIEW_WITH_MOVIE_TMDB_ID : tableName = MoviesContract . ReviewEntry . TABLE_NAME ; break ; default : return super . bulkInsert ( uri , values ) ; } db . beginTransaction ( ) ; int rowInserted = 0 ; try { for ( ContentValues value : values ) { long _id = db . insert ( tableName , null , value ) ; if ( _id != - 1 ) { rowInserted ++ ; } } db . setTransactionSuccessful ( ) ; } finally { db . endTransaction ( ) ; } if ( rowInserted > 0 ) { getContext ( ) . getContentResolver ( ) . notifyChange ( uri , null ) ; } return rowInserted ; }
Handles requests to insert a set of new rows.
Handles requests to insert a set of new rows .