From 548f9e021ebdcfb3c09d5175c48b580b20012bb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrzej=20W=C4=99g=C5=82owski?=
<30474752+andweg@users.noreply.github.com>
Date: Fri, 31 Mar 2023 22:16:59 +0200
Subject: Random enqueue location (#6403)
---
app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java | 1 +
.../danoeh/antennapod/core/storage/ItemEnqueuePositionCalculator.java | 4 ++++
core/src/main/res/values/arrays.xml | 2 ++
.../de/danoeh/antennapod/storage/preferences/UserPreferences.java | 2 +-
ui/i18n/src/main/res/values/strings.xml | 1 +
5 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
index 1b8100392..be947bc1e 100644
--- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java
@@ -123,6 +123,7 @@ public class PreferencesTest {
doTestEnqueueLocation(R.string.enqueue_location_after_current, EnqueueLocation.AFTER_CURRENTLY_PLAYING);
doTestEnqueueLocation(R.string.enqueue_location_front, EnqueueLocation.FRONT);
doTestEnqueueLocation(R.string.enqueue_location_back, EnqueueLocation.BACK);
+ doTestEnqueueLocation(R.string.enqueue_location_random, EnqueueLocation.RANDOM);
}
private void doTestEnqueueLocation(@StringRes int optionResId, EnqueueLocation expected) {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculator.java b/core/src/main/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculator.java
index 23d308c02..b81f281e8 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculator.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculator.java
@@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;
+import java.util.Random;
import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.model.feed.FeedItem;
@@ -46,6 +47,9 @@ class ItemEnqueuePositionCalculator {
int currentlyPlayingPosition = getCurrentlyPlayingPosition(curQueue, currentPlaying);
return getPositionOfFirstNonDownloadingItem(
currentlyPlayingPosition + 1, curQueue);
+ case RANDOM:
+ Random random = new Random();
+ return random.nextInt(curQueue.size() + 1);
default:
throw new AssertionError("calcPosition() : unrecognized enqueueLocation option: " + enqueueLocation);
}
diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml
index f3c0a0a3c..7749c6f3c 100644
--- a/core/src/main/res/values/arrays.xml
+++ b/core/src/main/res/values/arrays.xml
@@ -161,6 +161,7 @@
- @string/enqueue_location_back
- @string/enqueue_location_front
- @string/enqueue_location_after_current
+ - @string/enqueue_location_random
@@ -168,6 +169,7 @@
- BACK
- FRONT
- AFTER_CURRENTLY_PLAYING
+ - RANDOM
diff --git a/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
index 8a4d248ee..fda95ccd7 100644
--- a/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
+++ b/storage/preferences/src/main/java/de/danoeh/antennapod/storage/preferences/UserPreferences.java
@@ -345,7 +345,7 @@ public class UserPreferences {
}
public enum EnqueueLocation {
- BACK, FRONT, AFTER_CURRENTLY_PLAYING
+ BACK, FRONT, AFTER_CURRENTLY_PLAYING, RANDOM
}
@NonNull
diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml
index e45cfd481..2a2f7b6d1 100644
--- a/ui/i18n/src/main/res/values/strings.xml
+++ b/ui/i18n/src/main/res/values/strings.xml
@@ -492,6 +492,7 @@
Back
Front
After current episode
+ Random
Disabled
Documentation & Support
User forum
--
cgit v1.2.3