コード例 #1
0
  public void updateFavourite(View v) {
    if (movieDetailsModified.get()) {
      Uri detailUri = MovieContract.MovieEntry.buildUri(mMovieId);
      Cursor movieCursor =
          getContext().getContentResolver().query(detailUri, null, null, null, null);
      if (movieCursor.moveToFirst()) {
        int chkFavourite;
        if (movieCursor.getInt(MovieQuery.COL_MOVIE_FAVOURITE) == 0) {
          chkFavourite = 1;
        } else {
          chkFavourite = 0;
        }
        String selection = MovieContract.MovieEntry.COLUMN_MOVIE_ID + "=?";
        String[] selectionArgs = new String[] {mMovieId.toString()};
        ContentValues cv = new ContentValues();
        cv.put(MovieContract.MovieEntry.COLUMN_FAVOURITE, chkFavourite);
        getActivity()
            .getContentResolver()
            .update(MovieContract.MovieEntry.buildUri(mMovieId), cv, selection, selectionArgs);

        if (chkFavourite == 0) {
          btnToggle.setText("Mark as Favorite");
          Toast.makeText(getActivity(), title + " is removed from Favorites", Toast.LENGTH_SHORT)
              .show();
        } else {
          btnToggle.setText("Favourite");
          Toast.makeText(getActivity(), title + " is added to Favorites", Toast.LENGTH_SHORT)
              .show();
        }
      }
      movieCursor.close();
    } else {
      Toast.makeText(getActivity(), "Please Wait... still loading", Toast.LENGTH_SHORT).show();
    }
  }
コード例 #2
0
 @Override
 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
   Log.v(LOG_TAG, "In onCreateLoader");
   long mid = args.getLong(sMovieIdKey);
   if (mid > 0L)
     switch (id) {
       case 0:
         return new CursorLoader(
             getActivity(), MovieContract.MovieEntry.buildUri(mid), null, null, null, null);
       case 1:
         return new CursorLoader(
             getActivity(),
             MovieContract.MovieEntry.buildUriTrailers(mid),
             null,
             null,
             null,
             null);
       case 2:
         return new CursorLoader(
             getActivity(), MovieContract.MovieEntry.buildUriReviews(mid), null, null, null, null);
       default:
         return null;
     }
   else return null;
 }
コード例 #3
0
 private void updateMinutesDataInternal(String minutes) {
   String selection = MovieContract.MovieEntry.COLUMN_MOVIE_ID + "=?";
   String[] selectionArgs = new String[] {mMovieId.toString()};
   ContentValues cv = new ContentValues();
   cv.put(MovieContract.MovieEntry.COLUMN_MOVIE_MINUTES, Double.valueOf(minutes).intValue());
   getActivity()
       .getContentResolver()
       .update(MovieContract.MovieEntry.buildUri(mMovieId), cv, selection, selectionArgs);
 }