From 5f91cd3038577351752d25daadbdfdc16d595bc2 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 18 Mar 2015 18:16:25 -0700 Subject: Serialize queue when user presses cancel so they don't keep getting the prompt if they don't play anything else --- .../dsub/activity/SubsonicFragmentActivity.java | 16 ++++++++++++++-- src/github/daneren2005/dsub/service/DownloadService.java | 5 ++++- .../dsub/service/DownloadServiceLifecycleSupport.java | 9 ++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 54db1b91..7f267f28 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -563,9 +563,9 @@ public class SubsonicFragmentActivity extends SubsonicActivity { } // If we had a remote state and it's changed is more recent than our existing state - if(remoteState != null) { + if(remoteState != null && remoteState.changed != null) { Date localChange = downloadService.getLastStateChanged(); - if(localChange == null || localChange.after(remoteState.changed)) { + if(localChange == null || localChange.before(remoteState.changed)) { playerQueue = remoteState; } } @@ -598,6 +598,18 @@ public class SubsonicFragmentActivity extends SubsonicActivity { } }.execute(); } + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new SilentBackgroundTask(SubsonicFragmentActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + DownloadService downloadService = getDownloadService(); + downloadService.serializeQueue(false); + return null; + } + }.execute(); + } }); } diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index fb899ee8..6767e95e 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -1818,8 +1818,11 @@ public class DownloadService extends Service { } public synchronized void serializeQueue() { + serializeQueue(true); + } + public synchronized void serializeQueue(boolean serializeRemote) { if(playerState == PlayerState.PAUSED) { - lifecycleSupport.serializeDownloadQueue(); + lifecycleSupport.serializeDownloadQueue(serializeRemote); } } diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index 31844210..ca103332 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -259,6 +259,9 @@ public class DownloadServiceLifecycleSupport { } public void serializeDownloadQueue() { + serializeDownloadQueue(true); + } + public void serializeDownloadQueue(final boolean serializeRemote) { if(!setup.get()) { return; } @@ -269,7 +272,7 @@ public class DownloadServiceLifecycleSupport { public void run() { if(lock.tryLock()) { try { - serializeDownloadQueueNow(songs); + serializeDownloadQueueNow(songs, serializeRemote); } finally { lock.unlock(); } @@ -278,7 +281,7 @@ public class DownloadServiceLifecycleSupport { }); } - public void serializeDownloadQueueNow(List songs) { + public void serializeDownloadQueueNow(List songs, boolean serializeRemote) { final PlayerQueue state = new PlayerQueue(); for (DownloadFile downloadFile : songs) { state.songs.add(downloadFile.getSong()); @@ -299,7 +302,7 @@ public class DownloadServiceLifecycleSupport { FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER); // If we are on Subsonic 5.2+, save play queue - if(ServerInfo.canSavePlayQueue(downloadService) && !Util.isOffline(downloadService) && state.songs.size() > 0) { + if(serializeRemote && ServerInfo.canSavePlayQueue(downloadService) && !Util.isOffline(downloadService) && state.songs.size() > 0) { // Cancel any currently running tasks if(currentSavePlayQueueTask != null) { currentSavePlayQueueTask.cancel(); -- cgit v1.2.3