content: package com.androidessence.recyclerviewcursoradapter.sample.data;
  
  import android.content.ContentProvider;
  import android.content.ContentUris;
  import android.content.ContentValues;
  import android.content.UriMatcher;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.net.Uri;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.util.Log;
  
  /**
   * ContentProvider for accessing the movie database.
   *
   * Created by adammcneilly on 12/8/15.
   */
  public class MovieProvider extends ContentProvider{
      private static final int MOVIE = 0;
      private static final int MOVIE_ID = 1;
  
      private MovieDatabaseHelper mOpenHelper;
      private static final UriMatcher sUriMatcher = buildUriMatcher();
  
      private static UriMatcher buildUriMatcher() {
          String content = MovieContract.CONTENT_AUTHORITY;
  
          UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
          matcher.addURI(content, MovieContract.PATH_MOVIE, MOVIE);
          matcher.addURI(content, MovieContract.PATH_MOVIE + "/#", MOVIE_ID);
          return matcher;
      }
  
      @Override
      public boolean onCreate() {
          mOpenHelper = new MovieDatabaseHelper(getContext());
          return true;
      }
  
      @Nullable
      @Override
      public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
          Cursor retCursor;
          SQLiteDatabase db = mOpenHelper.getReadableDatabase();
  
          switch(sUriMatcher.match(uri)) {
              case MOVIE:
                  retCursor = db.query(
                          MovieContract.MovieEntry.TABLE_NAME,
                          projection,
                          selection,
                          selectionArgs,
                          null,
                          null,
                          sortOrder
                  );
                  break;
              case MOVIE_ID:
                  long _id = ContentUris.parseId(uri);
                  retCursor = db.query(
                          MovieContract.MovieEntry.TABLE_NAME,
                          projection,
                          MovieContract.MovieEntry._ID + " = ?",
                          new String[]{String.valueOf(_id)},
                          null,
                          null,
                          sortOrder
                  );
                  break;
              default:
                  throw new UnsupportedOperationException("Unknown uri: " + uri);
          }
  
          // Set notification
          assert getContext() != null;
          retCursor.setNotificationUri(getContext().getContentResolver(), uri);
          return retCursor;
      }
  
      @Nullable
      @Override
      public String getType(@NonNull Uri uri) {
          switch(sUriMatcher.match(uri)) {
              case MOVIE:
                  return MovieContract.MovieEntry.CONTENT_TYPE;
              case MOVIE_ID:
                  return MovieContract.MovieEntry.CONTENT_ITEM_TYPE;
              default:
                  throw new UnsupportedOperationException("Unknown uri: " + uri);
          }
      }
  
      @Nullable
      @Override
      public Uri insert(@NonNull Uri uri, ContentValues values) {
          return null;
      }
  
      @Override
      public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
          return 0;
      }
  
      @Override
      public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
          return 0;
      }
  }
  