diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-09-24 23:12:37 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-09-24 23:12:37 -0700 |
commit | 5a3c6afdc830a51775dfc9020d54aa9334fb6b97 (patch) | |
tree | 7c3dbc9f4a79862bae5730413afebf37869b51b2 /subsonic-android/src | |
parent | d2ef30d252b8af7dd955f1d6c21d2f8f7475ec0c (diff) | |
download | dsub-5a3c6afdc830a51775dfc9020d54aa9334fb6b97.tar.gz dsub-5a3c6afdc830a51775dfc9020d54aa9334fb6b97.tar.bz2 dsub-5a3c6afdc830a51775dfc9020d54aa9334fb6b97.zip |
Added getSongs to DownloadService which gets actively playing songs + fixed up background downloading so its partially working now
Diffstat (limited to 'subsonic-android/src')
3 files changed, 30 insertions, 19 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index baee66fa..69496e98 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -616,7 +616,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi @Override protected Void doInBackground() throws Throwable { List<MusicDirectory.Entry> entries = new LinkedList<MusicDirectory.Entry>(); - for (DownloadFile downloadFile : getDownloadService().getDownloads()) { + for (DownloadFile downloadFile : getDownloadService().getSongs()) { entries.add(downloadFile.getSong()); } MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this); @@ -681,7 +681,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi return; } - List<DownloadFile> list = downloadService.getDownloads(); + List<DownloadFile> list = downloadService.getSongs(); playlistView.setAdapter(new SongListAdapter(list)); emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java index d9d1ed0d..556765f2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java @@ -61,6 +61,8 @@ public interface DownloadService { void remove(DownloadFile downloadFile); + List<DownloadFile> getSongs(); + List<DownloadFile> getDownloads(); int getCurrentPlayingIndex(); diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index bec6c727..69bd766d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -490,6 +490,13 @@ public class DownloadServiceImpl extends Service implements DownloadService { public DownloadFile getCurrentDownloading() { return currentDownloading; } + + @Override + public synchronized List<DownloadFile> getSongs() { + List<DownloadFile> temp = new ArrayList<DownloadFile>(); + temp.addAll(downloadList); + return temp; + } @Override public synchronized List<DownloadFile> getDownloads() { @@ -844,7 +851,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } protected synchronized void checkDownloads() { - + Log.d(TAG, "Check Download"); if (!Util.isExternalStoragePresent() || !lifecycleSupport.isExternalStorageAvailable()) { return; } @@ -862,10 +869,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { } // Need to download current playing? - if (currentPlaying != null && - currentPlaying != currentDownloading && - !currentPlaying.isCompleteFileAvailable()) { - + if (currentPlaying != null && currentPlaying != currentDownloading && !currentPlaying.isCompleteFileAvailable()) { // Cancel current download, if necessary. if (currentDownloading != null) { currentDownloading.cancelDownload(); @@ -878,7 +882,7 @@ public class DownloadServiceImpl extends Service implements DownloadService { // Find a suitable target for download. else if (currentDownloading == null || currentDownloading.isWorkDone() || currentDownloading.isFailed() && !downloadList.isEmpty()) { - + Log.d(TAG, "Download Foreground"); int n = size(); if (n == 0) { return; @@ -903,18 +907,23 @@ public class DownloadServiceImpl extends Service implements DownloadService { i = (i + 1) % n; } while (i != start); - } - else if(!backgroundDownloadList.isEmpty()) { - for(int i = 0; i < backgroundDownloadList.size(); i++) { - DownloadFile downloadFile = backgroundDownloadList.get(i); - if (!downloadFile.isWorkDone() && downloadFile.shouldSave()) { - currentDownloading = downloadFile; - currentDownloading.download(); - cleanupCandidates.add(currentDownloading); - break; - } + + // Log.d(TAG, "i: " + i + "\nPreloaded: " + preloaded + "\nSize: " + n); + if((i + 1 + preloaded == n) && !backgroundDownloadList.isEmpty()) { + Log.d(TAG, "Download Background"); + for(DownloadFile downloadFile : backgroundDownloadList) { + if(downloadFile.isWorkDone()) { + // Don't need to keep list like active song list + backgroundDownloadList.remove(downloadFile); + } else if(downloadFile.shouldSave()) { + currentDownloading = downloadFile; + currentDownloading.download(); + cleanupCandidates.add(currentDownloading); + break; + } + } } - } + } // Delete obsolete .partial and .complete files. cleanup(); |