From 055941814c5d52ee9690347febb4f1c8cd6a962e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 17 Oct 2012 19:15:53 -0700 Subject: Fix background downloading when now playing list is empty --- .../dsub/service/DownloadServiceImpl.java | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'subsonic-android/src') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 87ffb629..ac989a68 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -886,6 +886,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } protected synchronized void checkDownloads() { + Log.d(TAG, "Start"); if (!Util.isExternalStoragePresent() || !lifecycleSupport.isExternalStorageAvailable()) { return; } @@ -901,6 +902,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { if (downloadList.isEmpty() && backgroundDownloadList.isEmpty()) { return; } + Log.d(TAG, "Past Check"); // Need to download current playing? if (currentPlaying != null && currentPlaying != currentDownloading && !currentPlaying.isCompleteFileAvailable()) { @@ -917,32 +919,31 @@ public class DownloadServiceImpl extends Service implements DownloadService { // Find a suitable target for download. else if (currentDownloading == null || currentDownloading.isWorkDone() || currentDownloading.isFailed() && (!downloadList.isEmpty() || !backgroundDownloadList.isEmpty())) { int n = size(); - if (n == 0) { - return; - } int preloaded = 0; - int start = currentPlaying == null ? 0 : getCurrentPlayingIndex(); - int i = start; - do { - DownloadFile downloadFile = downloadList.get(i); - if (!downloadFile.isWorkDone()) { - if (downloadFile.shouldSave() || preloaded < Util.getPreloadCount(this)) { - currentDownloading = downloadFile; - currentDownloading.download(); - cleanupCandidates.add(currentDownloading); - break; - } - } else if (currentPlaying != downloadFile) { - preloaded++; - } + if(n != 0) { + int start = currentPlaying == null ? 0 : getCurrentPlayingIndex(); + int i = start; + do { + DownloadFile downloadFile = downloadList.get(i); + if (!downloadFile.isWorkDone()) { + if (downloadFile.shouldSave() || preloaded < Util.getPreloadCount(this)) { + currentDownloading = downloadFile; + currentDownloading.download(); + cleanupCandidates.add(currentDownloading); + break; + } + } else if (currentPlaying != downloadFile) { + preloaded++; + } - i = (i + 1) % n; - } while (i != start); + i = (i + 1) % n; + } while (i != start); + } - if((preloaded + 1 == n || preloaded >= Util.getPreloadCount(this)) && !backgroundDownloadList.isEmpty()) { - for(i = 0; i < backgroundDownloadList.size(); i++) { + if((preloaded + 1 == n || preloaded >= Util.getPreloadCount(this) || downloadList.isEmpty()) && !backgroundDownloadList.isEmpty()) { + for(int i = 0; i < backgroundDownloadList.size(); i++) { DownloadFile downloadFile = backgroundDownloadList.get(i); if(downloadFile.isWorkDone()) { // Don't need to keep list like active song list -- cgit v1.2.3