From 5d4d0d4d6da34b810e59aa55f9fab0ad3445db9d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 2 Jul 2013 22:51:24 -0700 Subject: Added download/delete menus to podcasts episodes, podcast refresh button --- .../res/menu/select_podcast_episode.xml | 5 ++ .../res/menu/select_podcast_episode_context.xml | 7 +++ .../res/menu/select_podcast_episode_offline.xml | 9 +--- subsonic-android/res/menu/select_podcasts.xml | 5 ++ subsonic-android/res/values/strings.xml | 8 ++- .../dsub/fragments/SelectDirectoryFragment.java | 62 +++++++++++++++++++++- .../dsub/fragments/SelectPodcastsFragment.java | 29 ++++++++++ .../dsub/service/CachedMusicService.java | 25 +++++++++ .../daneren2005/dsub/service/MusicService.java | 10 ++++ .../dsub/service/OfflineMusicService.java | 25 +++++++++ .../daneren2005/dsub/service/RESTMusicService.java | 50 +++++++++++++++++ .../src/github/daneren2005/dsub/view/SongView.java | 2 + 12 files changed, 227 insertions(+), 10 deletions(-) diff --git a/subsonic-android/res/menu/select_podcast_episode.xml b/subsonic-android/res/menu/select_podcast_episode.xml index b6db96aa..ff5898e2 100644 --- a/subsonic-android/res/menu/select_podcast_episode.xml +++ b/subsonic-android/res/menu/select_podcast_episode.xml @@ -5,4 +5,9 @@ android:icon="@drawable/action_refresh" android:title="@string/menu.refresh" android:showAsAction="always|withText"/> + + diff --git a/subsonic-android/res/menu/select_podcast_episode_context.xml b/subsonic-android/res/menu/select_podcast_episode_context.xml index 2c0d86ff..25c83989 100644 --- a/subsonic-android/res/menu/select_podcast_episode_context.xml +++ b/subsonic-android/res/menu/select_podcast_episode_context.xml @@ -25,4 +25,11 @@ android:id="@+id/song_menu_delete" android:title="@string/common.delete"/> + + + diff --git a/subsonic-android/res/menu/select_podcast_episode_offline.xml b/subsonic-android/res/menu/select_podcast_episode_offline.xml index ce414955..9bbc2d92 100644 --- a/subsonic-android/res/menu/select_podcast_episode_offline.xml +++ b/subsonic-android/res/menu/select_podcast_episode_offline.xml @@ -9,12 +9,5 @@ - - + android:title="@string/common.delete"/> diff --git a/subsonic-android/res/menu/select_podcasts.xml b/subsonic-android/res/menu/select_podcasts.xml index e0f9a718..eea03827 100644 --- a/subsonic-android/res/menu/select_podcasts.xml +++ b/subsonic-android/res/menu/select_podcasts.xml @@ -6,6 +6,11 @@ android:title="@string/menu.refresh" android:showAsAction="always|withText"/> + + Play Video Stream Video Confirm - Do you want to %1$s %2$s + Do you want to %1$s %2$s? Home Library @@ -71,6 +71,7 @@ Failed to delete playlist %s Send Log Set Timer + Request Server Refresh Playlists Update Information @@ -134,6 +135,10 @@ No podcasts found This podcast had an error while downloading on the server. The server must download it first. This podcast has not been downloaded on the server. The server must download it first. + Download on server + Delete from server + Now downloading %s on the server + The server is checking for new podcasts now No saved playlists on server @@ -191,6 +196,7 @@ %d kbps Error Skipped + Downloading No lyrics found diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 4d9ebafd..547eb0f3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -224,6 +224,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if(!entry.isVideo() && !Util.isOffline(context) && playlistId == null && podcastId != null) { menu.removeItem(R.id.song_menu_remove_playlist); } + if(podcastId != null) { + String status = ((PodcastEpisode)entry).getStatus(); + if("completed".equals(status)) { + menu.removeItem(R.id.song_menu_server_download); + } + } } @Override @@ -243,6 +249,12 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter case R.id.song_menu_remove_playlist: removeFromPlaylist(playlistId, playlistName, Arrays.asList(info.position - 1)); break; + case R.id.song_menu_server_download: + downloadPodcastEpisode((PodcastEpisode)selectedItem); + break; + case R.id.song_menu_server_delete: + deletePodcastEpisode((PodcastEpisode)selectedItem); + break; } return true; @@ -279,7 +291,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if("error".equals(status)) { Util.toast(context, R.string.select_podcasts_error); return; - } else if("skipped".equals(status)) { + } else if(!"completed".equals(status)) { Util.toast(context, R.string.select_podcasts_skipped); return; } @@ -633,6 +645,54 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } }.execute(); } + + public void downloadPodcastEpisode(final PodcastEpisode episode) { + new LoadingTask(context, true) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.downloadPodcastEpisode(episode.getEpisodeId(), context, null); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(context, context.getResources().getString(R.string.select_podcasts_downloading, episode.getTitle())); + } + + @Override + protected void error(Throwable error) { + Util.toast(context, getErrorMessage(error), false); + } + }.execute(); + } + + public void deletePodcastEpisode(final PodcastEpisode episode) { + Util.confirmDialog(context, R.string.common_delete, episode.getTitle(), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new LoadingTask(context, true) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.deletePodcastEpisode(episode.getEpisodeId(), context, null); + return null; + } + + @Override + protected void done(Void result) { + entries.remove(episode); + entryAdapter.notifyDataSetChanged(); + } + + @Override + protected void error(Throwable error) { + Util.toast(context, getErrorMessage(error), false); + } + }.execute(); + } + }); + } private void checkLicenseAndTrialPeriod(Runnable onValid) { if (licenseValid) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 3c9ba7c7..dc563135 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -34,7 +34,9 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.TabBackgroundTask; +import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PodcastChannelAdapter; import java.util.ArrayList; import java.util.List; @@ -80,6 +82,12 @@ public class SelectPodcastsFragment extends SubsonicFragment implements AdapterV if(super.onOptionsItemSelected(item)) { return true; } + + switch (item.getItemId()) { + case R.id.menu_check: + refreshPodcasts(); + break; + } return false; } @@ -130,4 +138,25 @@ public class SelectPodcastsFragment extends SubsonicFragment implements AdapterV replaceFragment(fragment, R.id.select_podcasts_layout); } + + public void refreshPodcasts() { + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.refreshPodcasts(context, null); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(context, R.string.select_podcasts_refreshing); + } + + @Override + protected void error(Throwable error) { + Util.toast(context, getErrorMessage(error), false); + } + }.execute(); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java index e06f3372..0074e29b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/CachedMusicService.java @@ -322,6 +322,31 @@ public class CachedMusicService implements MusicService { return musicService.getPodcastEpisodes(id, context, progressListener); } + @Override + public void refreshPodcasts(Context context, ProgressListener progressListener) throws Exception { + musicService.refreshPodcasts(context, progressListener); + } + + @Override + public void createPodcastChannel(String url, Context context, ProgressListener progressListener) throws Exception{ + musicService.createPodcastChannel(url, context, progressListener); + } + + @Override + public void deletePodcastChannel(String id, Context context, ProgressListener progressListener) throws Exception{ + musicService.deletePodcastChannel(id, context, progressListener); + } + + @Override + public void downloadPodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception{ + musicService.downloadPodcastEpisode(id, context, progressListener); + } + + @Override + public void deletePodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception{ + musicService.deletePodcastEpisode(id, context, progressListener); + } + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ return musicService.processOfflineSyncs(context, progressListener); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java index 57deff8f..537ee2c2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/MusicService.java @@ -124,5 +124,15 @@ public interface MusicService { MusicDirectory getPodcastEpisodes(String id, Context context, ProgressListener progressListener) throws Exception; + void refreshPodcasts(Context context, ProgressListener progressListener) throws Exception; + + void createPodcastChannel(String url, Context context, ProgressListener progressListener) throws Exception; + + void deletePodcastChannel(String id, Context context, ProgressListener progressListener) throws Exception; + + void downloadPodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception; + + void deletePodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception; + int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception; } \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java index 395ad6b6..f72f83c4 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java @@ -607,6 +607,31 @@ public class OfflineMusicService extends RESTMusicService { public MusicDirectory getPodcastEpisodes(String id, Context context, ProgressListener progressListener) throws Exception { throw new OfflineException("Getting Podcasts not available in offline mode"); } + + @Override + public void refreshPodcasts(Context context, ProgressListener progressListener) throws Exception { + throw new OfflineException("Getting Podcasts not available in offline mode"); + } + + @Override + public void createPodcastChannel(String url, Context context, ProgressListener progressListener) throws Exception{ + throw new OfflineException("Getting Podcasts not available in offline mode"); + } + + @Override + public void deletePodcastChannel(String id, Context context, ProgressListener progressListener) throws Exception{ + throw new OfflineException("Getting Podcasts not available in offline mode"); + } + + @Override + public void downloadPodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception{ + throw new OfflineException("Getting Podcasts not available in offline mode"); + } + + @Override + public void deletePodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception{ + throw new OfflineException("Getting Podcasts not available in offline mode"); + } @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ diff --git a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java index 22e7f8e9..2cd45335 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/RESTMusicService.java @@ -906,6 +906,56 @@ public class RESTMusicService implements MusicService { } } + @Override + public void refreshPodcasts(Context context, ProgressListener progressListener) throws Exception { + Reader reader = getReader(context, progressListener, "refreshPodcasts", null); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public void createPodcastChannel(String url, Context context, ProgressListener progressListener) throws Exception{ + Reader reader = getReader(context, progressListener, "createPodcastChannel", null, "url", url); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public void deletePodcastChannel(String id, Context context, ProgressListener progressListener) throws Exception{ + Reader reader = getReader(context, progressListener, "deletePodcastChannel", null, "id", id); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public void downloadPodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception{ + Reader reader = getReader(context, progressListener, "downloadPodcastEpisode", null, "id", id); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + + @Override + public void deletePodcastEpisode(String id, Context context, ProgressListener progressListener) throws Exception{ + Reader reader = getReader(context, progressListener, "deletePodcastEpisode", null, "id", id); + try { + new ErrorParser(context).parse(reader); + } finally { + Util.close(reader); + } + } + @Override public int processOfflineSyncs(final Context context, final ProgressListener progressListener) throws Exception{ return processOfflineScrobbles(context, progressListener) + processOfflineStars(context, progressListener); diff --git a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java index 130663b5..7c7f5ae6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/SongView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/SongView.java @@ -103,6 +103,8 @@ public class SongView extends UpdateView implements Checkable { artist.append(getContext().getString(R.string.song_details_error)); } else if("skipped".equals(status)) { artist.append(getContext().getString(R.string.song_details_skipped)); + } else if("downloading".equals(status)) { + artist.append(getContext().getString(R.string.song_details_downloading)); } else { artist.append(String.format(getContext().getString(R.string.song_details_all), bitRate == null ? "" : bitRate, fileFormat)); } -- cgit v1.2.3