diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java index 7465b5b38..901c2a4ac 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java @@ -77,6 +77,9 @@ public class MediaDownloadedHandler implements Runnable { // we've received the media, we don't want to autodownload it again if (item != null) { item.setAutoDownload(false); + if (item.isNew()) { + item.setPlayed(false); + } // setFeedItem() signals (via EventBus) that the item has been updated, // so we do it after the enclosing media has been updated above, // to ensure subscribers will get the updated FeedMedia as well @@ -90,7 +93,6 @@ public class MediaDownloadedHandler implements Runnable { DownloadError.ERROR_DB_ACCESS_ERROR, false, e.getMessage()); } - if (GpodnetPreferences.loggedIn() && item != null) { GpodnetEpisodeAction action = new GpodnetEpisodeAction.Builder(item, GpodnetEpisodeAction.Action.DOWNLOAD) .currentDeviceId() diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index 826fe48b5..6e72a762a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -308,8 +308,7 @@ public final class DBTasks { @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) public static List enqueueFeedItemsToDownload(final Context context, - List items) - throws InterruptedException, ExecutionException { + List items) throws InterruptedException, ExecutionException { List itemsToEnqueue = new ArrayList<>(); if (UserPreferences.enqueueDownloadedEpisodes()) { LongList queueIDList = DBReader.getQueueIDList(); @@ -318,9 +317,7 @@ public final class DBTasks { itemsToEnqueue.add(item); } } - DBWriter.addQueueItem(context, - itemsToEnqueue.toArray(new FeedItem[0])) - .get(); + DBWriter.addQueueItem(context, false, itemsToEnqueue.toArray(new FeedItem[0])).get(); } return itemsToEnqueue; } 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 cb80db625..bbd7bbcf1 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 @@ -294,14 +294,17 @@ public class DBWriter { } - public static Future addQueueItem(final Context context, - final FeedItem... items) { + public static Future addQueueItem(final Context context, final FeedItem... items) { + return addQueueItem(context, true, items); + } + + public static Future addQueueItem(final Context context, boolean markAsUnplayed, final FeedItem... items) { LongList itemIds = new LongList(items.length); for (FeedItem item : items) { itemIds.add(item.getId()); item.addTag(FeedItem.TAG_QUEUE); } - return addQueueItem(context, false, itemIds.toArray()); + return addQueueItem(context, false, markAsUnplayed, itemIds.toArray()); } /** @@ -314,6 +317,20 @@ public class DBWriter { */ public static Future addQueueItem(final Context context, final boolean performAutoDownload, final long... itemIds) { + return addQueueItem(context, performAutoDownload, true, itemIds); + } + + /** + * Appends FeedItem objects to the end of the queue. The 'read'-attribute of all items will be set to true. + * If a FeedItem is already in the queue, the FeedItem will not change its position in the queue. + * + * @param context A context that is used for opening a database connection. + * @param performAutoDownload true if an auto-download process should be started after the operation. + * @param markAsUnplayed true if the items should be marked as unplayed when enqueueing + * @param itemIds IDs of the FeedItem objects that should be added to the queue. + */ + public static Future addQueueItem(final Context context, final boolean performAutoDownload, + final boolean markAsUnplayed, final long... itemIds) { return dbExec.submit(() -> { if (itemIds.length < 1) { return; @@ -355,7 +372,7 @@ public class DBWriter { EventBus.getDefault().post(event); } EventBus.getDefault().post(FeedItemEvent.updated(updatedItems)); - if (markAsUnplayedIds.size() > 0) { + if (markAsUnplayed && markAsUnplayedIds.size() > 0) { DBWriter.markItemPlayed(FeedItem.UNPLAYED, markAsUnplayedIds.toArray()); } }