From 4c288ccf28d01bd4ff22ebf831074e94db1c917d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 18 Jul 2015 19:17:59 -0700 Subject: Make sure revision has changed since event was posted --- .../daneren2005/dsub/service/DownloadService.java | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index cd22fb69..ab757c59 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -603,10 +603,6 @@ public class DownloadService extends Service { return downloadFile; } - public synchronized void clear() { - clear(true); - } - public synchronized void clearBackground() { if(currentDownloading != null && backgroundDownloadList.contains(currentDownloading)) { currentDownloading.cancelDownload(); @@ -668,6 +664,9 @@ public class DownloadService extends Service { return downloadList.size(); } + public synchronized void clear() { + clear(true); + } public synchronized void clear(boolean serialize) { // Delete podcast if fully listened to int position = getPlayerPosition(); @@ -2375,43 +2374,55 @@ public class DownloadService extends Service { } private void onSongChanged() { + final long atRevision = revision; for(final OnSongChangedListener listener: onSongChangedListeners) { handler.post(new Runnable() { @Override public void run() { - listener.onSongChanged(currentPlaying, currentPlayingIndex); + if(revision == atRevision) { + listener.onSongChanged(currentPlaying, currentPlayingIndex); + } } }); } } private void onSongsChanged() { + final long atRevision = revision; for(final OnSongChangedListener listener: onSongChangedListeners) { handler.post(new Runnable() { @Override public void run() { - listener.onSongsChanged(downloadList, currentPlaying, currentPlayingIndex); + if(revision == atRevision) { + listener.onSongsChanged(downloadList, currentPlaying, currentPlayingIndex); + } } }); } } private void onSongProgress() { + final long atRevision = revision; final Integer duration = getPlayerDuration(); final boolean isSeekable = isSeekable(); for(final OnSongChangedListener listener: onSongChangedListeners) { handler.post(new Runnable() { @Override public void run() { - listener.onSongProgress(currentPlaying, cachedPosition, duration, isSeekable); + if(revision == atRevision) { + listener.onSongProgress(currentPlaying, cachedPosition, duration, isSeekable); + } } }); } } private void onStateUpdate() { + final long atRevision = revision; for(final OnSongChangedListener listener: onSongChangedListeners) { handler.post(new Runnable() { @Override public void run() { - listener.onStateUpdate(currentPlaying, playerState); + if(revision == atRevision) { + listener.onStateUpdate(currentPlaying, playerState); + } } }); } -- cgit v1.2.3