diff options
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/fragments')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java | 39 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java | 50 |
2 files changed, 56 insertions, 33 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 370d1e51..2ab8316c 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -301,7 +301,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section entryGridAdapter.clearSelected(); return true; case R.id.menu_add_playlist: - List<Entry> songs = getSelectedSongs(); + List<Entry> songs = getSelectedEntries(); if(songs.isEmpty()) { songs = entries; } @@ -823,7 +823,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section playNow(shuffle, append, false); } private void playNow(final boolean shuffle, final boolean append, final boolean playNext) { - List<Entry> songs = getSelectedSongs(); + List<Entry> songs = getSelectedEntries(); if(!songs.isEmpty()) { download(songs, append, false, !append, playNext, shuffle); entryGridAdapter.clearSelected(); @@ -844,7 +844,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } } - private List<Entry> getSelectedSongs() { + private List<Entry> getSelectedEntries() { return entryGridAdapter.getSelected(); } @@ -859,7 +859,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section return indexes; } - private void download(final List<Entry> songs, final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) { + private void download(final List<Entry> entries, final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) { if (getDownloadService() == null) { return; } @@ -869,28 +869,30 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section // Conditions for using play now button if(!append && !save && autoplay && !playNext && !shuffle) { // Call playNow which goes through and tries to use bookmark information - playNow(songs, playlistName, playlistId); + playNow(entries, playlistName, playlistId); return; } - LoadingTask<Void> onValid = new LoadingTask<Void>(context) { + RecursiveLoader onValid = new RecursiveLoader(context) { @Override - protected Void doInBackground() throws Throwable { + protected Boolean doInBackground() throws Throwable { if (!append) { getDownloadService().clear(); } + getSongsRecursively(entries, songs); - getDownloadService().download(songs, save, autoplay, playNext, shuffle); + DownloadService downloadService = getDownloadService(); + downloadService.download(songs, save, autoplay, playNext, shuffle); if (playlistName != null) { - getDownloadService().setSuggestedPlaylistName(playlistName, playlistId); + downloadService.setSuggestedPlaylistName(playlistName, playlistId); } else { - getDownloadService().setSuggestedPlaylistName(null, null); + downloadService.setSuggestedPlaylistName(null, null); } return null; } @Override - protected void done(Void result) { + protected void done(Boolean result) { if (autoplay) { context.openNowPlaying(); } else if (save) { @@ -906,7 +908,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section checkLicenseAndTrialPeriod(onValid); } private void downloadBackground(final boolean save) { - List<Entry> songs = getSelectedSongs(); + List<Entry> songs = getSelectedEntries(); if(playlistId != null) { songs = entries; } @@ -918,21 +920,22 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section downloadBackground(save, songs); } } - private void downloadBackground(final boolean save, final List<Entry> songs) { + private void downloadBackground(final boolean save, final List<Entry> entries) { if (getDownloadService() == null) { return; } warnIfStorageUnavailable(); - LoadingTask<Void> onValid = new LoadingTask<Void>(context) { + RecursiveLoader onValid = new RecursiveLoader(context) { @Override - protected Void doInBackground() throws Throwable { + protected Boolean doInBackground() throws Throwable { + getSongsRecursively(entries, songs); getDownloadService().downloadBackground(songs, save); return null; } @Override - protected void done(Void result) { + protected void done(Boolean result) { Util.toast(context, context.getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); } }; @@ -941,7 +944,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } private void delete() { - List<Entry> songs = getSelectedSongs(); + List<Entry> songs = getSelectedEntries(); if(songs.isEmpty()) { for(Entry entry: entries) { if(entry.isDirectory()) { @@ -1068,7 +1071,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Section } public void unstarSelected() { - List<Entry> selected = getSelectedSongs(); + List<Entry> selected = getSelectedEntries(); if(selected.size() == 0) { selected = entries; } 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 c5c5a132..438649c3 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -1616,22 +1616,33 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected void playNow(List<Entry> entries) { playNow(entries, null, null); } - protected void playNow(List<Entry> entries, String playlistName, String playlistId) { - Entry bookmark = null; - for(Entry entry: entries) { - if(entry.getBookmark() != null) { - bookmark = entry; - break; + protected void playNow(final List<Entry> entries, final String playlistName, final String playlistId) { + new RecursiveLoader(context) { + @Override + protected Boolean doInBackground() throws Throwable { + getSongsRecursively(entries, songs); + return null; } - } - // If no bookmark found, just play from start - if(bookmark == null) { - playNow(entries, 0, playlistName, playlistId); - } else { - // If bookmark found, then give user choice to start from there or to start over - playBookmark(entries, bookmark, playlistName, playlistId); - } + @Override + protected void done(Boolean result) { + Entry bookmark = null; + for(Entry entry: songs) { + if(entry.getBookmark() != null) { + bookmark = entry; + break; + } + } + + // If no bookmark found, just play from start + if(bookmark == null) { + playNow(songs, 0, playlistName, playlistId); + } else { + // If bookmark found, then give user choice to start from there or to start over + playBookmark(songs, bookmark, playlistName, playlistId); + } + } + }.execute(); } protected void playNow(List<Entry> entries, int position) { playNow(entries, position, null, null); @@ -1834,12 +1845,21 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR protected MusicService musicService; protected static final int MAX_SONGS = 500; protected boolean playNowOverride = false; - protected List<Entry> songs; + protected List<Entry> songs = new ArrayList<>(); public RecursiveLoader(Activity context) { super(context); + musicService = MusicServiceFactory.getMusicService(context); } + protected void getSongsRecursively(List<Entry> entry) throws Exception { + getSongsRecursively(entry, songs); + } + protected void getSongsRecursively(List<Entry> entry, List<Entry> songs) throws Exception { + MusicDirectory dir = new MusicDirectory(); + dir.addChildren(entry); + getSongsRecursively(dir, songs); + } protected void getSongsRecursively(MusicDirectory parent, List<Entry> songs) throws Exception { if (songs.size() > MAX_SONGS) { return; |