aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java75
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java9
3 files changed, 85 insertions, 0 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
index e07b58b0..6e161bf0 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java
@@ -36,6 +36,8 @@ import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.Playlist;
+import github.daneren2005.dsub.domain.PodcastChannel;
+import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.SilentBackgroundTask;
@@ -50,7 +52,9 @@ public class AutoMediaBrowserService extends MediaBrowserService {
private static final String BROWSER_ALBUM_LISTS = "albumLists";
private static final String BROWSER_LIBRARY = "library";
private static final String BROWSER_PLAYLISTS = "playlists";
+ private static final String BROWSER_PODCASTS = "podcasts";
private static final String PLAYLIST_PREFIX = "pl-";
+ private static final String PODCAST_PREFIX = "po-";
private static final String ALBUM_TYPE_PREFIX = "ty-";
private static final String MUSIC_DIRECTORY_PREFIX = "md-";
@@ -89,6 +93,11 @@ public class AutoMediaBrowserService extends MediaBrowserService {
} else if(parentId.startsWith(PLAYLIST_PREFIX)) {
String id = parentId.substring(PLAYLIST_PREFIX.length());
getPlayOptions(result, id, Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
+ } else if(BROWSER_PODCASTS.equals(parentId)) {
+ getPodcasts(result);
+ } else if(parentId.startsWith(PODCAST_PREFIX)) {
+ String id = parentId.substring(PODCAST_PREFIX.length());
+ getPodcastEpisodes(result, id);
} else {
// No idea what it is, send empty result
result.sendResult(new ArrayList<MediaBrowser.MediaItem>());
@@ -113,6 +122,11 @@ public class AutoMediaBrowserService extends MediaBrowserService {
.setMediaId(BROWSER_PLAYLISTS);
mediaItems.add(new MediaBrowser.MediaItem(playlists.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE));
+ MediaDescription.Builder podcasts = new MediaDescription.Builder();
+ podcasts.setTitle(downloadService.getString(R.string.button_bar_podcasts))
+ .setMediaId(BROWSER_PODCASTS);
+ mediaItems.add(new MediaBrowser.MediaItem(podcasts.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE));
+
result.sendResult(mediaItems);
}
@@ -222,6 +236,67 @@ public class AutoMediaBrowserService extends MediaBrowserService {
result.detach();
}
+
+ private void getPodcasts(final Result<List<MediaBrowser.MediaItem>> result) {
+ new SilentServiceTask<List<PodcastChannel>>(downloadService) {
+ @Override
+ protected List<PodcastChannel> doInBackground(MusicService musicService) throws Throwable {
+ return musicService.getPodcastChannels(false, downloadService, null);
+ }
+
+ @Override
+ protected void done(List<PodcastChannel> podcasts) {
+ List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
+
+ for(PodcastChannel podcast: podcasts) {
+ MediaDescription description = new MediaDescription.Builder()
+ .setTitle(podcast.getName())
+ .setMediaId(PODCAST_PREFIX + podcast.getId())
+ .build();
+
+ mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_BROWSABLE));
+ }
+
+ result.sendResult(mediaItems);
+ }
+ }.execute();
+
+ result.detach();
+ }
+ private void getPodcastEpisodes(final Result<List<MediaBrowser.MediaItem>> result, final String podcastId) {
+ new SilentServiceTask<MusicDirectory>(downloadService) {
+ @Override
+ protected MusicDirectory doInBackground(MusicService musicService) throws Throwable {
+ return musicService.getPodcastEpisodes(false, podcastId, downloadService, null);
+ }
+
+ @Override
+ protected void done(MusicDirectory podcasts) {
+ List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
+
+ for(Entry entry: podcasts.getChildren(false, true)) {
+ PodcastEpisode podcast = (PodcastEpisode) entry;
+ Bundle podcastExtras = new Bundle();
+ podcastExtras.putSerializable(Constants.INTENT_EXTRA_ENTRY, podcast);
+ podcastExtras.putString(Constants.INTENT_EXTRA_NAME_PODCAST_ID, podcast.getId());
+
+ MediaDescription description = new MediaDescription.Builder()
+ .setTitle(podcast.getTitle())
+ .setSubtitle(Util.formatDate(downloadService, podcast.getDate()))
+ .setMediaId(PODCAST_PREFIX + podcast.getId())
+ .setExtras(podcastExtras)
+ .build();
+
+ mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_PLAYABLE));
+ }
+
+ result.sendResult(mediaItems);
+ }
+ }.execute();
+
+ result.detach();
+ }
+
private void getPlayOptions(Result<List<MediaBrowser.MediaItem>> result, String id, String idConstant) {
List<MediaBrowser.MediaItem> mediaItems = new ArrayList<>();
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
index 89e7de3b..bfb85492 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
@@ -67,6 +67,7 @@ public final class Constants {
public static final String INTENT_EXTRA_TOP_TRACKS = "topTracks";
public static final String INTENT_EXTRA_SHOW_ALL = "showAll";
public static final String INTENT_EXTRA_PLAY_LAST = "playLast";
+ public static final String INTENT_EXTRA_ENTRY = "passedEntry";
// Preferences keys.
public static final String PREFERENCES_KEY_SERVER_KEY = "server";
diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
index fb489705..bf025849 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
@@ -36,6 +36,7 @@ import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.media.MediaRouter;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -45,6 +46,7 @@ import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.Playlist;
+import github.daneren2005.dsub.domain.PodcastEpisode;
import github.daneren2005.dsub.domain.SearchCritera;
import github.daneren2005.dsub.domain.SearchResult;
import github.daneren2005.dsub.service.DownloadFile;
@@ -492,6 +494,8 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
boolean shuffle = extras.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false);
boolean playLast = extras.getBoolean(Constants.INTENT_EXTRA_PLAY_LAST, false);
+ Serializable entry = extras.getSerializable(Constants.INTENT_EXTRA_ENTRY);
+
String playlistId = extras.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, null);
if(playlistId != null) {
Playlist playlist = new Playlist(playlistId, null);
@@ -502,6 +506,11 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
Entry dir = new Entry(musicDirectoryId);
playMusicDirectory(dir, shuffle, playLast);
}
+
+ String podcastId = extras.getString(Constants.INTENT_EXTRA_NAME_PODCAST_ID, null);
+ if(podcastId != null) {
+ playSong((PodcastEpisode) entry);
+ }
}
@Override