summaryrefslogtreecommitdiff
path: root/core/src/main/java/de/danoeh
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/de/danoeh')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java9
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/ItemEnqueuePositionCalculator.java15
2 files changed, 10 insertions, 14 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
index d6571f60a..aff88ed80 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
@@ -329,13 +329,13 @@ public class DBWriter {
ItemEnqueuePositionCalculator positionCalculator =
new ItemEnqueuePositionCalculator(UserPreferences.getEnqueueLocation());
Playable currentlyPlaying = Playable.PlayableUtils.createInstanceFromPreferences(context);
- for (int i = 0; i < itemIds.length; i++) {
- if (!itemListContains(queue, itemIds[i])) {
- final FeedItem item = DBReader.getFeedItem(itemIds[i]);
+ int insertPosition = positionCalculator.calcPosition(queue, currentlyPlaying);
+ for (long itemId : itemIds) {
+ if (!itemListContains(queue, itemId)) {
+ final FeedItem item = DBReader.getFeedItem(itemId);
if (item != null) {
- int insertPosition = positionCalculator.calcPosition(i, item, queue, currentlyPlaying);
queue.add(insertPosition, item);
events.add(QueueEvent.added(item, insertPosition));
@@ -345,6 +345,7 @@ public class DBWriter {
if (item.isNew()) {
markAsUnplayedIds.add(item.getId());
}
+ insertPosition++;
}
}
}
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 f87a60203..700c15eb6 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
@@ -30,28 +30,23 @@ class ItemEnqueuePositionCalculator {
}
/**
- * @param positionAmongToAdd Typically, the callers has a list of items to be inserted to
- * the queue. This parameter indicates the position (0-based) of
- * the item among the one to inserted. E.g., it is needed for
- * enqueue at front option.
- * @param item the item to be inserted
+ * Determine the position (0-based) that the item(s) should be inserted to the named queue.
+ *
* @param curQueue the queue to which the item is to be inserted
* @param currentPlaying the currently playing media
- * @return the position (0-based) the item should be inserted to the named queue
*/
- public int calcPosition(int positionAmongToAdd, @NonNull FeedItem item,
- @NonNull List<FeedItem> curQueue, @Nullable Playable currentPlaying) {
+ public int calcPosition(@NonNull List<FeedItem> curQueue, @Nullable Playable currentPlaying) {
switch (enqueueLocation) {
case BACK:
return curQueue.size();
case FRONT:
// return NOT 0, so that when a list of items are inserted, the items inserted
// keep the same order. Returning 0 will reverse the order
- return getPositionOfFirstNonDownloadingItem(positionAmongToAdd, curQueue);
+ return getPositionOfFirstNonDownloadingItem(0, curQueue);
case AFTER_CURRENTLY_PLAYING:
int currentlyPlayingPosition = getCurrentlyPlayingPosition(curQueue, currentPlaying);
return getPositionOfFirstNonDownloadingItem(
- currentlyPlayingPosition + (1 + positionAmongToAdd), curQueue);
+ currentlyPlayingPosition + 1, curQueue);
default:
throw new AssertionError("calcPosition() : unrecognized enqueueLocation option: " + enqueueLocation);
}