Esempio n. 1
0
  @Override
  public Uri insert(Uri uri, ContentValues values) {
    if (values.size() == 0) return null;
    switch (_uriMatcher.match(uri)) {
      case SUBSCRIPTIONS:
        break;
      default:
        throw new IllegalArgumentException("Unknown URI");
    }

    if (Helper.isGPodderInstalled(getContext())) {
      ContentValues gpodderValues = new ContentValues();
      gpodderValues.put("url", values.getAsString(COLUMN_URL));
      getContext().getContentResolver().insert(Constants.GPODDER_URI, gpodderValues);
    }

    SQLiteDatabase db = _dbAdapter.getWritableDatabase();
    long id = db.insert("subscriptions", null, values);
    getContext().getContentResolver().notifyChange(URI, null);
    return ContentUris.withAppendedId(URI, id);
  }
Esempio n. 2
0
  @Override
  public int delete(Uri uri, String where, String[] whereArgs) {
    switch (_uriMatcher.match(uri)) {
      case SUBSCRIPTIONS:
        break;
      case SUBSCRIPTION_ID:
        String extraWhere = COLUMN_ID + " = " + uri.getLastPathSegment();
        if (where != null) where = extraWhere + " AND " + where;
        else where = extraWhere;
        getContext()
            .getContentResolver()
            .delete(
                PodcastProvider.URI, "subscriptionId = ?", new String[] {uri.getLastPathSegment()});
        break;
      default:
        throw new IllegalArgumentException("Unknown URI");
    }

    SQLiteDatabase db = _dbAdapter.getWritableDatabase();

    if (Helper.isGPodderInstalled(getContext())) {
      // delete from gpodder
      Cursor c =
          db.query("subscriptions", new String[] {"url"}, where, whereArgs, null, null, null);
      while (c.moveToNext())
        getContext()
            .getContentResolver()
            .delete(Constants.GPODDER_URI, "url = ?", new String[] {c.getString(0)});
      c.close();
    }

    int count = db.delete("subscriptions", where, whereArgs);
    getContext().getContentResolver().notifyChange(URI, null);

    db.close();

    return count;
  }
Esempio n. 3
0
  private void showNotification() {
    String[] projection =
        new String[] {
          PodcastProvider.COLUMN_ID,
          PodcastProvider.COLUMN_TITLE,
          PodcastProvider.COLUMN_SUBSCRIPTION_ID,
          PodcastProvider.COLUMN_SUBSCRIPTION_TITLE,
          PodcastProvider.COLUMN_SUBSCRIPTION_THUMBNAIL,
        };
    Cursor c =
        getContentResolver()
            .query(PodcastProvider.ACTIVE_PODCAST_URI, projection, null, null, null);
    if (c == null) return;
    if (c.isAfterLast()) {
      c.close();
      return;
    }
    PodcastCursor podcast = new PodcastCursor(c);

    // both paths use the pendingintent
    Intent showIntent = new Intent(this, MainActivity.class);
    PendingIntent showPendingIntent = PendingIntent.getActivity(this, 0, showIntent, 0);

    NotificationCompat.Builder builder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setWhen(0)
            .setContentTitle(podcast.getTitle())
            .setContentText(podcast.getSubscriptionTitle())
            .setContentIntent(showPendingIntent)
            .setOngoing(true)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);

    // set up pause intent
    Intent pauseIntent = new Intent(this, PlayerService.class);
    // use data to make intent unique
    pauseIntent.setData(Uri.parse("podax://playercommand/playpause"));
    pauseIntent.putExtra(Constants.EXTRA_PLAYER_COMMAND, Constants.PLAYER_COMMAND_PLAYPAUSE);
    pauseIntent.putExtra(Constants.EXTRA_PLAYER_COMMAND_ARG, Constants.PAUSE_MEDIABUTTON);
    PendingIntent pausePendingIntent = PendingIntent.getService(this, 0, pauseIntent, 0);

    // set up forward intent
    Intent forwardIntent = new Intent(this, ActivePodcastReceiver.class);
    forwardIntent.setData(Constants.ACTIVE_PODCAST_DATA_FORWARD);
    PendingIntent forwardPendingIntent = PendingIntent.getService(this, 0, forwardIntent, 0);

    Bitmap subscriptionBitmap =
        Helper.getCachedImage(this, podcast.getSubscriptionThumbnailUrl(), 128, 128);
    if (subscriptionBitmap != null) builder.setLargeIcon(subscriptionBitmap);

    if (PlayerStatus.getPlayerState(this) == PlayerStates.PLAYING)
      builder.addAction(
          R.drawable.ic_media_pause_normal, getString(R.string.pause), pausePendingIntent);
    else
      builder.addAction(
          R.drawable.ic_media_play_normal, getString(R.string.play), pausePendingIntent);
    builder.addAction(
        R.drawable.ic_media_ff_normal, getString(R.string.fast_forward), forwardPendingIntent);

    Notification notification = builder.build();
    startForeground(Constants.NOTIFICATION_PLAYING, notification);

    c.close();
  }
Esempio n. 4
0
 @Override
 protected void onResume() {
   super.onResume();
   Helper.registerMediaButtons(this);
 }