diff options
author | daneren2005 <daneren2005@gmail.com> | 2013-09-05 13:25:09 -0700 |
---|---|---|
committer | daneren2005 <daneren2005@gmail.com> | 2013-09-05 13:25:09 -0700 |
commit | 7d7ad14a6695157e2f88b8af2c2ec10d79d1f238 (patch) | |
tree | f00b1cca9ed0e0add7c7650504aa750c0552d2bd | |
parent | aceb2c6f9e2676fd7229a83ad63ffecdd480945c (diff) | |
download | dsub-7d7ad14a6695157e2f88b8af2c2ec10d79d1f238.tar.gz dsub-7d7ad14a6695157e2f88b8af2c2ec10d79d1f238.tar.bz2 dsub-7d7ad14a6695157e2f88b8af2c2ec10d79d1f238.zip |
Put onCurrentChange into background thread as well, masks service sync problem
-rw-r--r-- | src/github/daneren2005/dsub/fragments/DownloadFragment.java | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index f1f4b7c0..48b12765 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -104,6 +104,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe private ScheduledFuture<?> hideControlsFuture;
private SongListAdapter songListAdapter;
private SilentBackgroundTask<Void> onProgressChangedTask;
+ private SilentBackgroundTask<Void> onCurrentChangedTask;
private boolean seekInProgress = false;
private boolean startFlipped = false;
@@ -948,23 +949,40 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe private void onCurrentChanged() {
DownloadService downloadService = getDownloadService();
- if (downloadService == null) {
+ if (downloadService == null || onCurrentChangedTask != null) {
return;
}
+
+ onCurrentChangedTask = new SilentBackgroundTask<Void>(context) {
+ int currentPlayingIndex;
+ int currentPlayingSize;
- currentPlaying = downloadService.getCurrentPlaying();
- if (currentPlaying != null) {
- MusicDirectory.Entry song = currentPlaying.getSong();
- songTitleTextView.setText(song.getTitle());
- getImageLoader().loadImage(albumArtImageView, song, true, true);
- starButton.setImageResource(song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
- setSubtitle(context.getResources().getString(R.string.download_playing_out_of, downloadService.getCurrentPlayingIndex() + 1, downloadService.size()));
- } else {
- songTitleTextView.setText(null);
- getImageLoader().loadImage(albumArtImageView, null, true, false);
- starButton.setImageResource(android.R.drawable.btn_star_big_off);
- setSubtitle(null);
- }
+ @Override
+ protected Void doInBackground() throws Throwable {
+ currentPlaying = downloadService.getCurrentPlaying();
+ currentPlayingIndex = downloadService.getCurrentPlayingIndex() + 1;
+ currentPlayingSize = downloadService.size();
+ return null;
+ }
+
+ @Override
+ protected void done(Void result) {
+ if (currentPlaying != null) {
+ MusicDirectory.Entry song = currentPlaying.getSong();
+ songTitleTextView.setText(song.getTitle());
+ getImageLoader().loadImage(albumArtImageView, song, true, true);
+ starButton.setImageResource(song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off);
+ setSubtitle(context.getResources().getString(R.string.download_playing_out_of, currentPlayingIndex, currentPlayingSize));
+ } else {
+ songTitleTextView.setText(null);
+ getImageLoader().loadImage(albumArtImageView, null, true, false);
+ starButton.setImageResource(android.R.drawable.btn_star_big_off);
+ setSubtitle(null);
+ }
+ onCurrentChangedTask = null;
+ }
+ };
+ onCurrentChangedTask.execute();
}
private void onProgressChanged() {
|