From 49a2a6a29be4e5effdb7516e39b8d13d0d351bb7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 28 Sep 2015 16:52:28 -0700 Subject: Don't allow a random list size of less than 1 --- .../main/java/github/daneren2005/dsub/service/DownloadService.java | 4 ++-- app/src/main/java/github/daneren2005/dsub/util/ArtistRadioBuffer.java | 2 +- app/src/main/java/github/daneren2005/dsub/util/ShufflePlayBuffer.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/github') 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 6c73e8c1..f0e119bb 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -2103,7 +2103,7 @@ public class DownloadService extends Service { // Get users desired random playlist size SharedPreferences prefs = Util.getPreferences(this); - int listSize = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20")); + int listSize = Math.max(1, Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20"))); boolean wasEmpty = downloadList.isEmpty(); long revisionBefore = revision; @@ -2145,7 +2145,7 @@ public class DownloadService extends Service { private synchronized void checkArtistRadio() { // Get users desired random playlist size SharedPreferences prefs = Util.getPreferences(this); - int listSize = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20")); + int listSize = Math.max(1, Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20"))); boolean wasEmpty = downloadList.isEmpty(); long revisionBefore = revision; diff --git a/app/src/main/java/github/daneren2005/dsub/util/ArtistRadioBuffer.java b/app/src/main/java/github/daneren2005/dsub/util/ArtistRadioBuffer.java index 6e9b8309..2af468f6 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/ArtistRadioBuffer.java +++ b/app/src/main/java/github/daneren2005/dsub/util/ArtistRadioBuffer.java @@ -52,7 +52,7 @@ public class ArtistRadioBuffer { }; // Calculate out the capacity and refill threshold based on the user's random size preference - int shuffleListSize = Integer.parseInt(Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20")); + int shuffleListSize = Math.max(1, Integer.parseInt(Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20"))); // ex: default 20 -> 50 capacity = shuffleListSize * 5 / 2; capacity = Math.min(500, capacity); diff --git a/app/src/main/java/github/daneren2005/dsub/util/ShufflePlayBuffer.java b/app/src/main/java/github/daneren2005/dsub/util/ShufflePlayBuffer.java index 7da35f77..6996acaf 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/ShufflePlayBuffer.java +++ b/app/src/main/java/github/daneren2005/dsub/util/ShufflePlayBuffer.java @@ -73,7 +73,7 @@ public class ShufflePlayBuffer { executorService.scheduleWithFixedDelay(runnable, 1, 10, TimeUnit.SECONDS); // Calculate out the capacity and refill threshold based on the user's random size preference - int shuffleListSize = Integer.parseInt(Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20")); + int shuffleListSize = Math.max(1, Integer.parseInt(Util.getPreferences(context).getString(Constants.PREFERENCES_KEY_RANDOM_SIZE, "20"))); // ex: default 20 -> 50 capacity = shuffleListSize * 5 / 2; capacity = Math.min(500, capacity); -- cgit v1.2.3