Exemplo n.º 1
0
  @Override
  public Cursor query(
      Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // here's the switch statement that, given a URI, will determine what kind of request it is,
    // and query the database accordingly.
    Cursor retCursor;
    switch (sUriMatcher.match(uri)) {
        // "user/*/*"
      case USER_WITH_MOVIEID_AND_FAVORITE:
        {
          retCursor = getUserByMovieIDAndFavorite(uri, projection, sortOrder);
          break;
        }
        // "user/*"
      case USER_WITH_MOVIEID:
        {
          retCursor = getUserByMovieID(uri, projection, sortOrder);
          break;
        }
        // "user"
      case USER:
        retCursor =
            sSuperUserBuilder.query(
                mOpenHelper.getReadableDatabase(),
                projection,
                selection,
                selectionArgs,
                null,
                null,
                sortOrder);

        /*                retCursor = mOpenHelper.getReadableDatabase().query(
                //MovieContract.UserEntry.TABLE_NAME,
                projection,
                selection,
                selectionArgs,
                null,
                null,
                sortOrder
        );*/
        break;
      case MOVIEID:
        retCursor =
            mOpenHelper
                .getReadableDatabase()
                .query(
                    MovieContract.MovieEntry.TABLE_NAME,
                    projection,
                    selection,
                    selectionArgs,
                    null,
                    null,
                    sortOrder);
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
    retCursor.setNotificationUri(getContext().getContentResolver(), uri);
    return retCursor;
  }
Exemplo n.º 2
0
  private Cursor getUserByMovieIDAndFavorite(Uri uri, String[] projection, String sortOrder) {
    String movieID = MovieContract.UserEntry.getMovieIDFromUri(uri);
    boolean favorite = MovieContract.UserEntry.getFavoriteFromUri(uri);

    return sUserByMovieIDQueryBuilder.query(
        mOpenHelper.getReadableDatabase(),
        projection,
        sMovieIDWithFavoriteSelection,
        new String[] {movieID, Boolean.toString(favorite).toUpperCase()},
        null,
        null,
        sortOrder);
  }
Exemplo n.º 3
0
  private Cursor getUserByMovieID(Uri uri, String[] projection, String sortOrder) {
    String movieID = MovieContract.UserEntry.getMovieIDFromUri(uri);
    boolean favorite = MovieContract.UserEntry.getFavoriteFromUri(uri);

    String[] selectionArgs;
    String selection;

    if (favorite == false) {
      selection = sMovieIDSelection;
      selectionArgs = new String[] {movieID};
    } else {
      selectionArgs = new String[] {movieID, Boolean.toString(favorite).toUpperCase()};
      selection = sMovieIDWithFavoriteSelection;
    }

    return sUserByMovieIDQueryBuilder.query(
        mOpenHelper.getReadableDatabase(),
        projection,
        selection,
        selectionArgs,
        null,
        null,
        sortOrder);
  }