From c6d492a890edac8e0556340f8f20e519da3837f8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 16 Dec 2014 09:13:33 -0800 Subject: #429 Add ability to play/shuffle by album lists. Just plays/shuffles whatever is loaded so far. --- res/menu/select_album_list.xml | 19 ++++ .../dsub/fragments/SelectDirectoryFragment.java | 4 +- .../dsub/fragments/SubsonicFragment.java | 120 ++++++++++++++------- 3 files changed, 104 insertions(+), 39 deletions(-) create mode 100644 res/menu/select_album_list.xml diff --git a/res/menu/select_album_list.xml b/res/menu/select_album_list.xml new file mode 100644 index 00000000..3b86fbcd --- /dev/null +++ b/res/menu/select_album_list.xml @@ -0,0 +1,19 @@ + + + + + + + + diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index a71924cf..3fbb90cf 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -203,7 +203,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } else if(hideButtons && !showAll) { if(albumListType != null) { - menuInflater.inflate(R.menu.empty, menu); + menuInflater.inflate(R.menu.select_album_list, menu); } else { menuInflater.inflate(R.menu.select_album, menu); @@ -802,6 +802,8 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter if (hasSubFolders && (id != null || share != null || "starred".equals(albumListType))) { downloadRecursively(id, false, append, !append, shuffle, false); + } else if(hasSubFolders && albumListType != null) { + downloadRecursively(albums, shuffle, append); } else { selectAll(true, false); download(append, false, !append, false, shuffle); diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 5cb7c32f..6e588ec4 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -847,12 +847,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR downloadRecursively(id, name, isDirectory, save, append, autoplay, shuffle, background, false); } protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background, final boolean playNext) { - LoadingTask task = new LoadingTask(context) { - private MusicService musicService; - private static final int MAX_SONGS = 500; - private boolean playNowOverride = false; - private List songs; - + new RecursiveLoader(context) { @Override protected Boolean doInBackground() throws Throwable { musicService = MusicServiceFactory.getMusicService(context); @@ -904,48 +899,47 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR return transition; } + }.execute(); + } - private void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { - if (songs.size() > MAX_SONGS) { - return; - } + protected void downloadRecursively(final List albums, final boolean shuffle, final boolean append) { + new RecursiveLoader(context) { + @Override + protected Boolean doInBackground() throws Throwable { + musicService = MusicServiceFactory.getMusicService(context); - for (Entry song : parent.getChildren(false, true)) { - if (!song.isVideo() && song.getRating() != 1) { - songs.add(song); - } + if(shuffle) { + Collections.shuffle(albums); } - for (Entry dir : parent.getChildren(true, false)) { - if(dir.getRating() == 1) { - continue; - } - MusicDirectory musicDirectory; - if(Util.isTagBrowsing(context) && !Util.isOffline(context)) { - musicDirectory = musicService.getAlbum(dir.getId(), dir.getTitle(), false, context, this); - } else { - musicDirectory = musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this); + songs = new LinkedList(); + MusicDirectory root = new MusicDirectory(); + root.addChildren(albums); + getSongsRecursively(root, songs); + + DownloadService downloadService = getDownloadService(); + boolean transition = false; + if (!songs.isEmpty() && downloadService != null) { + // Conditions for a standard play now operation + if(!append && !shuffle) { + playNowOverride = true; + return false; } - getSongsRecursively(musicDirectory, songs); - } - } - @Override - protected void done(Boolean result) { - warnIfStorageUnavailable(); + if (!append) { + downloadService.clear(); + } - if(playNowOverride) { - playNow(songs); - return; + downloadService.download(songs, false, true, false, false); + if(!append) { + transition = true; + } } + artistOverride = false; - if(result) { - Util.startActivityWithoutTransition(context, DownloadActivity.class); - } + return transition; } - }; - - task.execute(); + }.execute(); } protected MusicDirectory getMusicDirectory(String id, String name, boolean refresh, MusicService service, ProgressListener listener) throws Exception { @@ -1732,4 +1726,54 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR public abstract class OnStarChange { abstract void starChange(boolean starred); } + + public abstract class RecursiveLoader extends LoadingTask { + protected MusicService musicService; + protected static final int MAX_SONGS = 500; + protected boolean playNowOverride = false; + protected List songs; + + public RecursiveLoader(Activity context) { + super(context); + } + + protected void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { + if (songs.size() > MAX_SONGS) { + return; + } + + for (Entry song : parent.getChildren(false, true)) { + if (!song.isVideo() && song.getRating() != 1) { + songs.add(song); + } + } + for (Entry dir : parent.getChildren(true, false)) { + if(dir.getRating() == 1) { + continue; + } + + MusicDirectory musicDirectory; + if(Util.isTagBrowsing(context) && !Util.isOffline(context)) { + musicDirectory = musicService.getAlbum(dir.getId(), dir.getTitle(), false, context, this); + } else { + musicDirectory = musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this); + } + getSongsRecursively(musicDirectory, songs); + } + } + + @Override + protected void done(Boolean result) { + warnIfStorageUnavailable(); + + if(playNowOverride) { + playNow(songs); + return; + } + + if(result) { + Util.startActivityWithoutTransition(context, DownloadActivity.class); + } + } + } } -- cgit v1.2.3