Random enqueue location (#6403)

This commit is contained in:
Andrzej Węgłowski 2023-03-31 22:16:59 +02:00 committed by GitHub
parent 214bf974cf
commit 548f9e021e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -161,6 +161,7 @@
<item>@string/enqueue_location_back</item>
<item>@string/enqueue_location_front</item>
<item>@string/enqueue_location_after_current</item>
<item>@string/enqueue_location_random</item>
</string-array>
<string-array name="enqueue_location_values">
@ -168,6 +169,7 @@
<item>BACK</item>
<item>FRONT</item>
<item>AFTER_CURRENTLY_PLAYING</item>
<item>RANDOM</item>
</string-array>
<string-array name="episode_cleanup_values">

View File

@ -345,7 +345,7 @@ public class UserPreferences {
}
public enum EnqueueLocation {
BACK, FRONT, AFTER_CURRENTLY_PLAYING
BACK, FRONT, AFTER_CURRENTLY_PLAYING, RANDOM
}
@NonNull

View File

@ -492,6 +492,7 @@
<string name="enqueue_location_back">Back</string>
<string name="enqueue_location_front">Front</string>
<string name="enqueue_location_after_current">After current episode</string>
<string name="enqueue_location_random">Random</string>
<string name="pref_smart_mark_as_played_disabled">Disabled</string>
<string name="documentation_support">Documentation &amp; Support</string>
<string name="visit_user_forum">User forum</string>