diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-02-22 19:25:19 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-02-22 19:25:19 -0800 |
commit | 8d6185dd174219f4058241b94c67451e9dfa29cd (patch) | |
tree | 9e68de19529db7821e2b8fc5fe1757a45b70185e /subsonic-android | |
parent | 9a87aa9c07ca165cc32680abbec7ae627e9f39fa (diff) | |
download | dsub-8d6185dd174219f4058241b94c67451e9dfa29cd.tar.gz dsub-8d6185dd174219f4058241b94c67451e9dfa29cd.tar.bz2 dsub-8d6185dd174219f4058241b94c67451e9dfa29cd.zip |
Async serializing playlist so it doesn't block main thread
Diffstat (limited to 'subsonic-android')
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 6ff45dee..e04fc00c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -30,6 +30,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.media.RemoteControlClient; +import android.os.AsyncTask; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; @@ -181,15 +182,7 @@ public class DownloadServiceLifecycleSupport { } public void serializeDownloadQueue() { - State state = new State(); - for (DownloadFile downloadFile : downloadService.getSongs()) { - 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); + new SerializeTask().execute(); } private void deserializeDownloadQueue() { @@ -277,4 +270,22 @@ public class DownloadServiceLifecycleSupport { private int currentPlayingIndex; private int currentPlayingPosition; } + + private class SerializeTask extends AsyncTask<Void, Void, Void> { + @Override + protected Void doInBackground(Void... params) { + List<DownloadFile> songs = new ArrayList<DownloadFile>(downloadService.getSongs()); + 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); + + return null; + } + } }
\ No newline at end of file |