Mark as seen after download completed

This commit is contained in:
ByteHamster 2019-12-10 22:25:21 +01:00
parent a99a41e3bb
commit 2c9f758f39
3 changed files with 26 additions and 10 deletions

View File

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

View File

@ -308,8 +308,7 @@ public final class DBTasks {
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public static List<? extends FeedItem> enqueueFeedItemsToDownload(final Context context,
List<? extends FeedItem> items)
throws InterruptedException, ExecutionException {
List<? extends FeedItem> items) throws InterruptedException, ExecutionException {
List<FeedItem> 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;
}

View File

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