From de6e2b66b476b8d8b3e16c2859e4ec8aee7f8625 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 16 Mar 2015 08:34:55 -0700 Subject: Fix trying to popup confirm in background thread, clear and add instead of restore --- .../dsub/activity/SubsonicFragmentActivity.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 68666b84..54db1b91 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -547,6 +547,8 @@ public class SubsonicFragmentActivity extends SubsonicActivity { private void loadRemotePlayQueue() { final Context context = this; new SilentBackgroundTask(this) { + private PlayerQueue playerQueue; + @Override protected Void doInBackground() throws Throwable { try { @@ -564,7 +566,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { if(remoteState != null) { Date localChange = downloadService.getLastStateChanged(); if(localChange == null || localChange.after(remoteState.changed)) { - promptRestoreFromRemoteQueue(remoteState); + playerQueue = remoteState; } } } catch (Exception e) { @@ -573,13 +575,28 @@ public class SubsonicFragmentActivity extends SubsonicActivity { return null; } + + @Override + protected void done(Void arg) { + if(playerQueue != null) { + promptRestoreFromRemoteQueue(playerQueue); + } + } }.execute(); } private void promptRestoreFromRemoteQueue(final PlayerQueue remoteState) { Util.confirmDialog(this, R.string.download_restore_play_queue, new SimpleDateFormat("MMM dd hh:mm").format(remoteState.changed), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - getDownloadService().restore(remoteState.songs, null, remoteState.currentPlayingIndex, remoteState.currentPlayingPosition); + new SilentBackgroundTask(SubsonicFragmentActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + DownloadService downloadService = getDownloadService(); + downloadService.clear(); + downloadService.download(remoteState.songs, false, false, false, false, remoteState.currentPlayingIndex, remoteState.currentPlayingPosition); + return null; + } + }.execute(); } }); } -- cgit v1.2.3