@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); }
@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; }
@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)); } }
private void stopSyncPodcast(PodcastChannel podcast) { SyncUtil.removeSyncedPodcast(context, podcast.getId()); }