aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-07 06:18:35 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-07 06:18:35 -0700
commit2cd841bcd2c3017a2d3ee865661eeab432ad382e (patch)
tree818a20f26c189d75cce1914bcc82637f3a94a42d /src/github
parenta3da272e3c83996f4c559fcc0b9b20c6ebea1c73 (diff)
downloaddsub-2cd841bcd2c3017a2d3ee865661eeab432ad382e.tar.gz
dsub-2cd841bcd2c3017a2d3ee865661eeab432ad382e.tar.bz2
dsub-2cd841bcd2c3017a2d3ee865661eeab432ad382e.zip
Fix ANR by moving service logic into doInBackground
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index 5a643daa..54709ec0 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -732,11 +732,11 @@ 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<List<MusicDirectory.Entry>> task = new LoadingTask<List<MusicDirectory.Entry>>(context) {
+ LoadingTask<Boolean> task = new LoadingTask<Boolean>(context) {
private static final int MAX_SONGS = 500;
@Override
- protected List<MusicDirectory.Entry> doInBackground() throws Throwable {
+ protected Boolean doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
MusicDirectory root;
if(share != null) {
@@ -755,7 +755,26 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
List<MusicDirectory.Entry> songs = new LinkedList<MusicDirectory.Entry>();
getSongsRecursively(root, songs);
- return songs;
+
+ DownloadService downloadService = getDownloadService();
+ boolean transition = false;
+ if (!songs.isEmpty() && downloadService != null) {
+ if (!append) {
+ downloadService.clear();
+ }
+ if(!background) {
+ downloadService.download(songs, save, autoplay, playNext, false);
+ if(!append) {
+ transition = true;
+ }
+ }
+ else {
+ downloadService.downloadBackground(songs, save);
+ }
+ }
+ artistOverride = false;
+
+ return transition;
}
private void getSongsRecursively(MusicDirectory parent, List<MusicDirectory.Entry> songs) throws Exception {
@@ -782,24 +801,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
@Override
- protected void done(List<MusicDirectory.Entry> songs) {
- DownloadService downloadService = getDownloadService();
- if (!songs.isEmpty() && downloadService != null) {
- if (!append) {
- downloadService.clear();
- }
- warnIfNetworkOrStorageUnavailable();
- if(!background) {
- downloadService.download(songs, save, autoplay, playNext, false);
- if(!append) {
- Util.startActivityWithoutTransition(context, DownloadActivity.class);
- }
- }
- else {
- downloadService.downloadBackground(songs, save);
- }
+ protected void done(Boolean result) {
+ warnIfNetworkOrStorageUnavailable();
+
+ if(result) {
+ Util.startActivityWithoutTransition(context, DownloadActivity.class);
}
- artistOverride = false;
}
};