From a5c45e631cbca4fd8e78d7ddc02ce1c19b973f50 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 1 Apr 2016 17:58:16 -0700 Subject: Fixes #672: Resume entire album when clicking bookmarks --- .../dsub/fragments/SelectBookmarkFragment.java | 37 +++++++++++++------- .../dsub/fragments/SubsonicFragment.java | 40 +++++++++++++++++----- 2 files changed, 55 insertions(+), 22 deletions(-) (limited to 'app') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java index 5f3ca38b..03c6663a 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectBookmarkFragment.java @@ -18,6 +18,7 @@ */ package github.daneren2005.dsub.fragments; +import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -28,6 +29,7 @@ import github.daneren2005.dsub.domain.Bookmark; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.MenuUtil; import github.daneren2005.dsub.util.ProgressListener; import github.daneren2005.dsub.util.SilentBackgroundTask; @@ -89,19 +91,28 @@ public class SelectBookmarkFragment extends SelectRecyclerFragment(context) { - @Override - protected Void doInBackground() throws Throwable { - downloadService.clear(); - downloadService.download(Arrays.asList(bookmark), false, true, false, false, 0, bookmark.getBookmark().getPosition()); - return null; - } - - @Override - protected void done(Void result) { - context.openNowPlaying(); - } - }.execute(); + if(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_PLAY_NOW_AFTER, true) && ((!Util.isTagBrowsing(context) && bookmark.getParent() != null) || (Util.isTagBrowsing(context) && bookmark.getAlbumId() != null)) && !bookmark.isPodcast()) { + new RecursiveLoader(context) { + @Override + protected Boolean doInBackground() throws Throwable { + getSiblingsRecursively(bookmark); + + if(songs.isEmpty() || !songs.contains(bookmark)) { + playNowInTask(Arrays.asList(bookmark), bookmark, bookmark.getBookmark().getPosition()); + } else { + playNowInTask(songs, bookmark, bookmark.getBookmark().getPosition()); + } + return null; + } + + @Override + protected void done(Boolean result) { + context.openNowPlaying(); + } + }.execute(); + } else { + playNow(Arrays.asList(bookmark), bookmark, bookmark.getBookmark().getPosition()); + } } private void displayBookmarkInfo(final MusicDirectory.Entry entry) { diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java index f552127e..9bbc6f85 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1675,15 +1675,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR new LoadingTask(context) { @Override protected Void doInBackground() throws Throwable { - DownloadService downloadService = getDownloadService(); - if(downloadService == null) { - return null; - } - - downloadService.clear(); - downloadService.download(entries, false, true, true, false, entries.indexOf(song), position); - downloadService.setSuggestedPlaylistName(playlistName, playlistId); - + playNowInTask(entries, song, position, playlistName, playlistId); return null; } @@ -1693,6 +1685,19 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR } }.execute(); } + protected void playNowInTask(final List entries, final Entry song, final int position) { + playNowInTask(entries, song, position, null, null); + } + protected void playNowInTask(final List entries, final Entry song, final int position, final String playlistName, final String playlistId) { + DownloadService downloadService = getDownloadService(); + if(downloadService == null) { + return; + } + + downloadService.clear(); + downloadService.download(entries, false, true, true, false, entries.indexOf(song), position); + downloadService.setSuggestedPlaylistName(playlistName, playlistId); + } protected void deleteBookmark(final MusicDirectory.Entry entry, final SectionAdapter adapter) { Util.confirmDialog(context, R.string.bookmark_delete_title, entry.getTitle(), new DialogInterface.OnClickListener() { @@ -1933,6 +1938,23 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR musicService = MusicServiceFactory.getMusicService(context); } + protected void getSiblingsRecursively(Entry entry) throws Exception { + MusicDirectory parent = new MusicDirectory(); + if(Util.isTagBrowsing(context) && !Util.isOffline(context)) { + parent.setId(entry.getAlbumId()); + } else { + parent.setId(entry.getParent()); + } + + if(parent.getId() == null) { + songs.add(entry); + } else { + MusicDirectory.Entry dir = new Entry(parent.getId()); + dir.setDirectory(true); + parent.addChild(dir); + getSongsRecursively(parent, songs); + } + } protected void getSongsRecursively(List entry) throws Exception { getSongsRecursively(entry, false); } -- cgit v1.2.3