From fd8fe0b59f21763f8335a4750198cb8068d1600e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 9 Apr 2013 20:28:59 -0700 Subject: AsyncTask the deserilization of now playing list --- .../service/DownloadServiceLifecycleSupport.java | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'subsonic-android/src') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index de2e40a1..a8600252 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -182,23 +182,26 @@ public class DownloadServiceLifecycleSupport { } public void serializeDownloadQueue() { - new SerializeTask().execute(); + new SerializeTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void serializeDownloadQueueNow() { List songs = new ArrayList(downloadService.getSongs()); - State state = new State(); - for (DownloadFile downloadFile : songs) { - state.songs.add(downloadFile.getSong()); - } - state.currentPlayingIndex = downloadService.getCurrentPlayingIndex(); - state.currentPlayingPosition = downloadService.getPlayerPosition(); + State state = new State(); + for (DownloadFile downloadFile : songs) { + state.songs.add(downloadFile.getSong()); + } + state.currentPlayingIndex = downloadService.getCurrentPlayingIndex(); + state.currentPlayingPosition = downloadService.getPlayerPosition(); - Log.i(TAG, "Serialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition); - FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER); + Log.i(TAG, "Serialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition); + FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER); } - private void deserializeDownloadQueue() { + private void deserializeDownloadQueue() { + new DeserializeTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + private void deserializeDownloadQueueNow() { State state = FileUtil.deserialize(downloadService, FILENAME_DOWNLOADS_SER); if (state == null) { return; @@ -293,4 +296,11 @@ public class DownloadServiceLifecycleSupport { return null; } } + private class DeserializeTask extends AsyncTask { + @Override + protected Void doInBackground(Void... params) { + deserializeDownloadQueueNow(); + return null; + } + } } -- cgit v1.2.3