From a80a31f2f8790f0d24357dd356da469fea271aaf Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 10 Jan 2016 13:26:49 -0800 Subject: #618 Resume podcasts/album lists from Bookmarks --- .../dsub/util/compat/RemoteControlClientLP.java | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'app') 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 bf025849..907f80ac 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 @@ -43,6 +43,7 @@ import java.util.List; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.activity.SubsonicFragmentActivity; +import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.MusicDirectory.Entry; import github.daneren2005.dsub.domain.Playlist; @@ -352,7 +353,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase { } }.execute(); } - private void playMusicDirectory(final Entry dir, final boolean shuffle, final boolean append) { + private void playMusicDirectory(final Entry dir, final boolean shuffle, final boolean append, final boolean playFromBookmark) { new SilentServiceTask(downloadService) { @Override protected Void doInBackground(MusicService musicService) throws Throwable { @@ -362,7 +363,7 @@ public class RemoteControlClientLP extends RemoteControlClientBase { } else { musicDirectory = musicService.getMusicDirectory(dir.getId(), "dir", false, downloadService, null); } - playSongs(musicDirectory.getChildren(false, true), shuffle, append); + playSongs(musicDirectory.getChildren(false, true), shuffle, append, playFromBookmark); return null; } @@ -370,18 +371,40 @@ public class RemoteControlClientLP extends RemoteControlClientBase { } private void playSong(Entry entry) { + + } + private void playSong(Entry entry, boolean resumeFromBookmark) { List entries = new ArrayList<>(); entries.add(entry); - playSongs(entries); + playSongs(entries, false, false, resumeFromBookmark); } private void playSongs(List entries) { playSongs(entries, false, false); } private void playSongs(List entries, boolean shuffle, boolean append) { + playSongs(entries, shuffle, append, false); + } + private void playSongs(List entries, boolean shuffle, boolean append, boolean resumeFromBookmark) { if(!append) { downloadService.clear(); } - downloadService.download(entries, false, true, false, shuffle); + + int startIndex = 0; + int startPosition = 0; + if(resumeFromBookmark) { + int bookmarkIndex = 0; + for(Entry entry: entries) { + if(entry.getBookmark() != null) { + Bookmark bookmark = entry.getBookmark(); + startIndex = bookmarkIndex; + startPosition = bookmark.getPosition(); + break; + } + bookmarkIndex++; + } + } + + downloadService.download(entries, false, true, false, shuffle, startIndex, startPosition); } private void noResults() { @@ -504,12 +527,12 @@ public class RemoteControlClientLP extends RemoteControlClientBase { String musicDirectoryId = extras.getString(Constants.INTENT_EXTRA_NAME_ID); if(musicDirectoryId != null) { Entry dir = new Entry(musicDirectoryId); - playMusicDirectory(dir, shuffle, playLast); + playMusicDirectory(dir, shuffle, playLast, true); } String podcastId = extras.getString(Constants.INTENT_EXTRA_NAME_PODCAST_ID, null); if(podcastId != null) { - playSong((PodcastEpisode) entry); + playSong((PodcastEpisode) entry, true); } } -- cgit v1.2.3