From 79a31e6f5cb7656b14b1cae71f7c29dcac1d2a7a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 17 Feb 2015 08:28:25 -0800 Subject: #435 Fix ArtistRadio not being restored properly --- src/github/daneren2005/dsub/service/DownloadService.java | 7 +++++-- src/github/daneren2005/dsub/util/ArtistRadioBuffer.java | 6 ++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 5726b696..5ab58bf6 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -435,8 +435,9 @@ public class DownloadService extends Service { if(startShufflePlay != SHUFFLE_MODE_NONE) { if(startShufflePlay == SHUFFLE_MODE_ALL) { shufflePlay = true; - } else { + } else if(startShufflePlay == SHUFFLE_MODE_ARTIST) { artistRadio = true; + Log.d(TAG, "Artist id: " + prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_MODE_EXTRA, null)); artistRadioBuffer.restoreArtist(prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_MODE_EXTRA, null)); } SharedPreferences.Editor editor = prefs.edit(); @@ -501,7 +502,9 @@ public class DownloadService extends Service { SharedPreferences.Editor editor = Util.getPreferences(this).edit(); editor.putInt(Constants.PREFERENCES_KEY_SHUFFLE_MODE, (artistId != null) ? SHUFFLE_MODE_ARTIST : SHUFFLE_MODE_NONE); - editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_MODE_EXTRA, artistId); + if(artistId != null) { + editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_MODE_EXTRA, artistId); + } editor.commit(); } diff --git a/src/github/daneren2005/dsub/util/ArtistRadioBuffer.java b/src/github/daneren2005/dsub/util/ArtistRadioBuffer.java index 829478f7..f3fc5904 100644 --- a/src/github/daneren2005/dsub/util/ArtistRadioBuffer.java +++ b/src/github/daneren2005/dsub/util/ArtistRadioBuffer.java @@ -44,8 +44,6 @@ public class ArtistRadioBuffer { public ArtistRadioBuffer(DownloadService context) { this.context = context; - - executorService = Executors.newSingleThreadScheduledExecutor(); runnable = new Runnable() { @Override public void run() { @@ -89,7 +87,7 @@ public class ArtistRadioBuffer { result.add(buffer.remove(buffer.size() - 1)); } } - Log.i(TAG, "Taking " + result.size() + " songs from shuffle play buffer. " + buffer.size() + " remaining."); + Log.i(TAG, "Taking " + result.size() + " songs from artist radio buffer. " + buffer.size() + " remaining."); if(result.isEmpty()) { awaitingResults = true; } @@ -102,7 +100,7 @@ public class ArtistRadioBuffer { private void restart() { synchronized(buffer) { - if(buffer.size() <= refillThreshold && lastCount != 0 && executorService.isShutdown()) { + if(buffer.size() <= refillThreshold && lastCount != 0 && (executorService == null || executorService.isShutdown())) { executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleWithFixedDelay(runnable, 0, 10, TimeUnit.SECONDS); } -- cgit v1.2.3