예제 #1
0
  @Override
  public void onCreateContextMenu(
      Menu menu,
      MenuInflater menuInflater,
      UpdateView<Serializable> updateView,
      Serializable item) {
    if (item instanceof PodcastChannel) {
      PodcastChannel channel = (PodcastChannel) item;
      if (!Util.isOffline(context) && UserUtil.canPodcast()) {
        menuInflater.inflate(R.menu.select_podcasts_context, menu);

        if (SyncUtil.isSyncedPodcast(context, channel.getId())) {
          menu.removeItem(R.id.podcast_menu_sync);
        } else {
          menu.removeItem(R.id.podcast_menu_stop_sync);
        }
      } else {
        menuInflater.inflate(R.menu.select_podcasts_context_offline, menu);
      }
    } else {
      onCreateContextMenuSupport(menu, menuInflater, updateView, item);
    }

    recreateContextMenu(menu);
  }
예제 #2
0
  @Override
  public List<Serializable> getObjects(
      MusicService musicService, boolean refresh, ProgressListener listener) throws Exception {
    List<PodcastChannel> channels = musicService.getPodcastChannels(refresh, context, listener);

    if (!Util.isOffline(context) && ServerInfo.hasNewestPodcastEpisodes(context)) {
      try {
        newestEpisodes = musicService.getNewestPodcastEpisodes(10, context, listener);

        for (MusicDirectory.Entry entry : newestEpisodes.getChildren()) {
          for (PodcastChannel channel : channels) {
            if (channel.getId().equals(entry.getParent())) {
              PodcastEpisode episode = (PodcastEpisode) entry;

              // Update with information normally done in PodcastEntryParser
              episode.setArtist(channel.getName());
              episode.setCoverArt(channel.getCoverArt());
              episode.setPath(FileUtil.getPodcastPath(context, episode));
              break;
            }
          }
        }
      } catch (Exception e) {
        Log.e(TAG, "Failed to download newest episodes", e);
        newestEpisodes = null;
      }
    } else {
      newestEpisodes = null;
    }

    List<Serializable> serializableList = new ArrayList<>();
    serializableList.addAll(channels);

    return serializableList;
  }
예제 #3
0
  private void displayPodcastInfo(final PodcastChannel channel) {
    List<Integer> headers = new ArrayList<>();
    List<String> details = new ArrayList<>();

    if (channel.getName() != null) {
      headers.add(R.string.details_title);
      details.add(channel.getName());
    }

    headers.add(R.string.details_url);
    details.add(channel.getUrl());
    headers.add(R.string.details_status);
    details.add(channel.getStatus());

    if (channel.getErrorMessage() != null) {
      headers.add(R.string.details_error);
      details.add(channel.getErrorMessage());
    }
    if (channel.getDescription() != null) {
      headers.add(R.string.details_description);
      details.add(channel.getDescription());
    }

    Util.showDetailsDialog(context, R.string.details_title_podcast, headers, details);
  }
예제 #4
0
  private void deletePodcast(final PodcastChannel channel) {
    Util.confirmDialog(
        context,
        R.string.common_delete,
        channel.getName(),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            new LoadingTask<Void>(context, false) {
              @Override
              protected Void doInBackground() throws Throwable {
                MusicService musicService = MusicServiceFactory.getMusicService(context);
                musicService.deletePodcastChannel(channel.getId(), context, null);
                stopSyncPodcast(channel);
                return null;
              }

              @Override
              protected void done(Void result) {
                adapter.removeItem(channel);
                Util.toast(
                    context,
                    context
                        .getResources()
                        .getString(R.string.select_podcasts_deleted, channel.getName()));
              }

              @Override
              protected void error(Throwable error) {
                String msg;
                if (error instanceof OfflineException || error instanceof ServerTooOldException) {
                  msg = getErrorMessage(error);
                } else {
                  msg =
                      context
                              .getResources()
                              .getString(R.string.select_podcasts_deleted_error, channel.getName())
                          + " "
                          + getErrorMessage(error);
                }

                Util.toast(context, msg, false);
              }
            }.execute();
          }
        });
  }
예제 #5
0
  @Override
  public void onItemClicked(UpdateView<Serializable> updateView, Serializable item) {
    if (item instanceof PodcastChannel) {
      PodcastChannel channel = (PodcastChannel) item;
      if ("error".equals(channel.getStatus())) {
        Util.toast(
            context,
            context
                .getResources()
                .getString(
                    R.string.select_podcasts_invalid_podcast_channel,
                    channel.getErrorMessage() == null ? "error" : channel.getErrorMessage()));
      } else if ("downloading".equals(channel.getStatus())) {
        Util.toast(context, R.string.select_podcasts_initializing);
      } else {
        SubsonicFragment fragment = new SelectDirectoryFragment();
        Bundle args = new Bundle();
        args.putString(Constants.INTENT_EXTRA_NAME_PODCAST_ID, channel.getId());
        args.putString(Constants.INTENT_EXTRA_NAME_PODCAST_NAME, channel.getName());
        args.putString(Constants.INTENT_EXTRA_NAME_PODCAST_DESCRIPTION, channel.getDescription());
        fragment.setArguments(args);

        replaceFragment(fragment);
      }
    } else {
      PodcastEpisode episode = (PodcastEpisode) item;

      String status = episode.getStatus();
      if ("error".equals(status)) {
        Util.toast(context, R.string.select_podcasts_error);
        return;
      } else if (!"completed".equals(status)) {
        Util.toast(context, R.string.select_podcasts_skipped);
        return;
      }

      playNow(Arrays.asList((MusicDirectory.Entry) episode));
    }
  }
예제 #6
0
 private void stopSyncPodcast(PodcastChannel podcast) {
   SyncUtil.removeSyncedPodcast(context, podcast.getId());
 }