From 2cd841bcd2c3017a2d3ee865661eeab432ad382e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 7 Jul 2014 06:18:35 -0700 Subject: Fix ANR by moving service logic into doInBackground --- .../dsub/fragments/SubsonicFragment.java | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src') 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> task = new LoadingTask>(context) { + LoadingTask task = new LoadingTask(context) { private static final int MAX_SONGS = 500; @Override - protected List 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 songs = new LinkedList(); 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 songs) throws Exception { @@ -782,24 +801,12 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR } @Override - protected void done(List 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; } }; -- cgit v1.2.3