From 2d63cbdd166da2dc7d96dbde95c37cf78b985871 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 11 Jan 2016 18:06:47 -0800 Subject: Fixes #618: add bookmarks to Auto --- .../dsub/service/AutoMediaBrowserService.java | 53 ++++++++++++++++++++-- .../dsub/util/compat/RemoteControlClientLP.java | 23 ++++++++-- 2 files changed, 67 insertions(+), 9 deletions(-) (limited to 'app/src/main/java') 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 6e161bf0..aa353def 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java @@ -53,6 +53,7 @@ public class AutoMediaBrowserService extends MediaBrowserService { 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 BROWSER_BOOKMARKS = "bookmarks"; private static final String PLAYLIST_PREFIX = "pl-"; private static final String PODCAST_PREFIX = "po-"; private static final String ALBUM_TYPE_PREFIX = "ty-"; @@ -98,6 +99,8 @@ public class AutoMediaBrowserService extends MediaBrowserService { } else if(parentId.startsWith(PODCAST_PREFIX)) { String id = parentId.substring(PODCAST_PREFIX.length()); getPodcastEpisodes(result, id); + } else if(BROWSER_BOOKMARKS.equals(parentId)) { + getBookmarks(result); } else { // No idea what it is, send empty result result.sendResult(new ArrayList()); @@ -122,10 +125,19 @@ 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)); + if(Util.getPreferences(downloadService).getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true)) { + 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)); + } + + if(Util.getPreferences(downloadService).getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true)) { + MediaDescription.Builder podcasts = new MediaDescription.Builder(); + podcasts.setTitle(downloadService.getString(R.string.button_bar_bookmarks)) + .setMediaId(BROWSER_BOOKMARKS); + mediaItems.add(new MediaBrowser.MediaItem(podcasts.build(), MediaBrowser.MediaItem.FLAG_BROWSABLE)); + } result.sendResult(mediaItems); } @@ -296,6 +308,39 @@ public class AutoMediaBrowserService extends MediaBrowserService { result.detach(); } + + private void getBookmarks(final Result> result) { + new SilentServiceTask(downloadService) { + @Override + protected MusicDirectory doInBackground(MusicService musicService) throws Throwable { + return musicService.getBookmarks(false, downloadService, null); + } + + @Override + protected void done(MusicDirectory bookmarkList) { + List mediaItems = new ArrayList<>(); + + for(Entry entry: bookmarkList.getChildren(false, true)) { + Bundle extras = new Bundle(); + extras.putSerializable(Constants.INTENT_EXTRA_ENTRY, entry); + extras.putString(Constants.INTENT_EXTRA_NAME_CHILD_ID, entry.getId()); + + MediaDescription description = new MediaDescription.Builder() + .setTitle(entry.getTitle()) + .setSubtitle(Util.formatDuration(entry.getBookmark().getPosition() / 1000)) + .setMediaId(entry.getId()) + .setExtras(extras) + .build(); + + mediaItems.add(new MediaBrowser.MediaItem(description, MediaBrowser.MediaItem.FLAG_PLAYABLE)); + } + + result.sendResult(mediaItems); + } + }.execute(); + + result.detach(); + } private void getPlayOptions(Result> result, String id, String idConstant) { List mediaItems = new ArrayList<>(); 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 907f80ac..8185bf19 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 @@ -353,15 +353,18 @@ public class RemoteControlClientLP extends RemoteControlClientBase { } }.execute(); } - private void playMusicDirectory(final Entry dir, final boolean shuffle, final boolean append, final boolean playFromBookmark) { + private void playMusicDirectory(Entry dir, boolean shuffle, boolean append, boolean playFromBookmark) { + playMusicDirectory(dir.getId(), shuffle, append, playFromBookmark); + } + private void playMusicDirectory(final String dirId, final boolean shuffle, final boolean append, final boolean playFromBookmark) { new SilentServiceTask(downloadService) { @Override protected Void doInBackground(MusicService musicService) throws Throwable { MusicDirectory musicDirectory; if(Util.isTagBrowsing(downloadService) && !Util.isOffline(downloadService)) { - musicDirectory = musicService.getAlbum(dir.getId(), "dir", false, downloadService, null); + musicDirectory = musicService.getAlbum(dirId, "dir", false, downloadService, null); } else { - musicDirectory = musicService.getMusicDirectory(dir.getId(), "dir", false, downloadService, null); + musicDirectory = musicService.getMusicDirectory(dirId, "dir", false, downloadService, null); } playSongs(musicDirectory.getChildren(false, true), shuffle, append, playFromBookmark); @@ -517,7 +520,7 @@ 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); + Entry entry = (Entry) extras.getSerializable(Constants.INTENT_EXTRA_ENTRY); String playlistId = extras.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, null); if(playlistId != null) { @@ -532,7 +535,17 @@ public class RemoteControlClientLP extends RemoteControlClientBase { String podcastId = extras.getString(Constants.INTENT_EXTRA_NAME_PODCAST_ID, null); if(podcastId != null) { - playSong((PodcastEpisode) entry, true); + playSong(entry, true); + } + + // Currently only happens when playing bookmarks so we should be looking up parent + String childId = extras.getString(Constants.INTENT_EXTRA_NAME_CHILD_ID, null); + if(childId != null) { + if(Util.isTagBrowsing(downloadService) && !Util.isOffline(downloadService)) { + playMusicDirectory(entry.getAlbumId(), shuffle, playLast, true); + } else { + playMusicDirectory(entry.getParent(), shuffle, playLast, true); + } } } -- cgit v1.2.3