Ejemplo n.º 1
0
  public static boolean onMenuItemClicked(Context context, MenuItem item, FeedItem selectedItem)
      throws DownloadRequestException {
    DownloadRequester requester = DownloadRequester.getInstance();
    FeedManager manager = FeedManager.getInstance();
    switch (item.getItemId()) {
      case R.id.download_item:
        manager.downloadFeedItem(context, selectedItem);
        break;
      case R.id.play_item:
        manager.playMedia(context, selectedItem.getMedia(), true, true, false);
        break;
      case R.id.remove_item:
        manager.deleteFeedMedia(context, selectedItem.getMedia());
        break;
      case R.id.cancel_download_item:
        requester.cancelDownload(context, selectedItem.getMedia());
        break;
      case R.id.mark_read_item:
        manager.markItemRead(context, selectedItem, true, true);
        break;
      case R.id.mark_unread_item:
        manager.markItemRead(context, selectedItem, false, true);
        break;
      case R.id.add_to_queue_item:
        manager.addQueueItem(context, selectedItem);
        break;
      case R.id.remove_from_queue_item:
        manager.removeQueueItem(context, selectedItem);
        break;
      case R.id.stream_item:
        manager.playMedia(context, selectedItem.getMedia(), true, true, true);
        break;
      case R.id.visit_website_item:
        Uri uri = Uri.parse(selectedItem.getLink());
        context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
        break;
      case R.id.support_item:
        new FlattrClickWorker(context, selectedItem.getPaymentLink()).executeAsync();
        break;
      case R.id.share_link_item:
        ShareUtils.shareFeedItemLink(context, selectedItem);
        break;
      default:
        return false;
    }
    // Refresh menu state

    return true;
  }
Ejemplo n.º 2
0
 @Override
 public void onCreate() {
   super.onCreate();
   singleton = this;
   LOGICAL_DENSITY = getResources().getDisplayMetrics().density;
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
   displayOnlyEpisodes = prefs.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
   currentlyPlayingMediaId =
       prefs.getLong(
           PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA, PlaybackService.NO_MEDIA_PLAYING);
   readThemeValue();
   createImportDirectory();
   createNoMediaFile();
   prefs.registerOnSharedPreferenceChangeListener(this);
   FeedManager manager = FeedManager.getInstance();
   manager.loadDBData(getApplicationContext());
 }
Ejemplo n.º 3
0
 /**
  * Listens for changes in the 'update intervall'-preference and changes the alarm if necessary.
  */
 @Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   if (AppConfig.DEBUG) Log.d(TAG, "Registered change of application preferences");
   if (key.equals(PREF_UPDATE_INTERVALL)) {
     AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
     int hours = Integer.parseInt(sharedPreferences.getString(PREF_UPDATE_INTERVALL, "0"));
     PendingIntent updateIntent =
         PendingIntent.getBroadcast(
             this, 0, new Intent(FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0);
     alarmManager.cancel(updateIntent);
     if (hours != 0) {
       long newIntervall = TimeUnit.HOURS.toMillis(hours);
       alarmManager.setRepeating(
           AlarmManager.RTC_WAKEUP, newIntervall, newIntervall, updateIntent);
       if (AppConfig.DEBUG) Log.d(TAG, "Changed alarm to new intervall");
     } else {
       if (AppConfig.DEBUG) Log.d(TAG, "Automatic update was deactivated");
     }
   } else if (key.equals(PREF_DISPLAY_ONLY_EPISODES)) {
     if (AppConfig.DEBUG) Log.d(TAG, "PREF_DISPLAY_ONLY_EPISODES changed");
     displayOnlyEpisodes = sharedPreferences.getBoolean(PREF_DISPLAY_ONLY_EPISODES, false);
   } else if (key.equals(PlaybackService.PREF_LAST_PLAYED_ID)) {
     if (AppConfig.DEBUG) Log.d(TAG, "PREF_LAST_PLAYED_ID changed");
     long mediaId = sharedPreferences.getLong(PlaybackService.PREF_AUTODELETE_MEDIA_ID, -1);
     if (mediaId != -1) {
       FeedManager manager = FeedManager.getInstance();
       FeedMedia media = manager.getFeedMedia(mediaId);
       if (media != null) {
         manager.autoDeleteIfPossible(this, media);
       }
     }
   } else if (key.equals(PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA)) {
     long id =
         sharedPreferences.getLong(
             PlaybackService.PREF_CURRENTLY_PLAYING_MEDIA, PlaybackService.NO_MEDIA_PLAYING);
     if (AppConfig.DEBUG) Log.d(TAG, "Currently playing media set to " + id);
     if (id != currentlyPlayingMediaId) {
       currentlyPlayingMediaId = id;
     }
   } else if (key.equals(PREF_THEME)) {
     readThemeValue();
   }
 }
Ejemplo n.º 4
0
  public static boolean onPrepareMenu(Menu menu, FeedItem selectedItem) {
    FeedManager manager = FeedManager.getInstance();
    DownloadRequester requester = DownloadRequester.getInstance();
    boolean hasMedia = selectedItem.getMedia() != null;
    boolean downloaded = hasMedia && selectedItem.getMedia().isDownloaded();
    boolean downloading = hasMedia && requester.isDownloadingFile(selectedItem.getMedia());
    boolean notLoadedAndNotLoading = hasMedia && (!downloaded) && (!downloading);
    FeedItem.State state = selectedItem.getState();

    menu.findItem(R.id.play_item).setVisible(downloaded);
    menu.findItem(R.id.remove_item).setVisible(downloaded);
    menu.findItem(R.id.download_item).setVisible(notLoadedAndNotLoading);
    menu.findItem(R.id.stream_item).setVisible(notLoadedAndNotLoading | downloading);
    menu.findItem(R.id.cancel_download_item).setVisible(downloading);

    boolean isInQueue = manager.isInQueue(selectedItem);

    menu.findItem(R.id.remove_from_queue_item).setVisible(isInQueue);
    menu.findItem(R.id.add_to_queue_item).setVisible(!isInQueue && selectedItem.getMedia() != null);

    menu.findItem(R.id.share_link_item).setVisible(selectedItem.getLink() != null);

    menu.findItem(R.id.mark_unread_item)
        .setVisible(state == FeedItem.State.IN_PROGRESS || state == FeedItem.State.READ);
    menu.findItem(R.id.mark_read_item)
        .setVisible(state == FeedItem.State.NEW || state == FeedItem.State.IN_PROGRESS);

    if (selectedItem.getLink() != null) {
      menu.findItem(R.id.visit_website_item).setVisible(true);
    }

    if (selectedItem.getPaymentLink() != null) {
      menu.findItem(R.id.support_item).setVisible(true);
    }

    return true;
  }
Ejemplo n.º 5
0
    @Override
    protected Void doInBackground(Void... params) {
      File f = null;
      if (image.getFile_url() != null) {
        f = new File(image.getFile_url());
      }
      if (image.getFile_url() != null && f.exists()) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(image.getFile_url(), options);
        int sampleSize = calculateSampleSize(options.outWidth, options.outHeight);

        options.inJustDecodeBounds = false;
        options.inSampleSize = sampleSize;
        decodedBitmap = BitmapFactory.decodeFile(image.getFile_url(), options);
        if (decodedBitmap == null) {
          Log.i(
              TAG,
              "Bitmap could not be decoded in custom sample size. Trying default sample size (path was "
                  + image.getFile_url()
                  + ")");
          decodedBitmap = BitmapFactory.decodeFile(image.getFile_url());
        }
        if (decodedBitmap != null) {
          bitmap =
              Bitmap.createScaledBitmap(decodedBitmap, PREFERRED_LENGTH, PREFERRED_LENGTH, false);
          if (baseLength == LENGTH_BASE_COVER) {
            addBitmapToCoverCache(image.getId(), bitmap);
          } else if (baseLength == LENGTH_BASE_THUMBNAIL) {
            addBitmapToThumbnailCache(image.getId(), bitmap);
          }
        } else {
          Log.w(TAG, "Could not load bitmap. Using default image.");
          bitmap = BitmapFactory.decodeResource(target.getResources(), R.drawable.default_cover);
        }
        if (AppConfig.DEBUG) Log.d(TAG, "Finished loading bitmaps");
      } else {
        Log.e(TAG, "FeedImage has no valid file url. Using default image");
        bitmap = BitmapFactory.decodeResource(target.getResources(), R.drawable.default_cover);
        if (image.getFile_url() != null
            && !DownloadRequester.getInstance().isDownloadingFile(image)) {
          FeedManager.getInstance().notifyInvalidImageFile(PodcastApp.getInstance(), image);
        }
      }
      return null;
    }