mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-12-01 12:31:45 +00:00
Add option to automatically download queue (#7627)
We already added the queue to the auto-download candidates. Now that auto-download was rewritten to not be a "master switch", the code is called even if auto-download is turned off for all subscriptions. This lead to queued episodes being downloaded for users who had auto-download disabled. Convert the feature to an explicit setting to avoid behavior changes for users. Also, this implements a setting to auto-download the queue, which users have requested because they did not know that AntennaPod already does this. Finally, it should solve user confusion where they automatically add episodes to the queue but set the auto-download filter to ignore specific episodes.
This commit is contained in:
@ -334,84 +334,43 @@ public class DBWriter {
|
||||
* @param context A context that is used for opening a database connection.
|
||||
* @param itemId ID of the FeedItem that should be added to the queue.
|
||||
* @param index Destination index. Must be in range 0..queue.size()
|
||||
* @param performAutoDownload True if an auto-download process should be started after the operation
|
||||
* @throws IndexOutOfBoundsException if index < 0 || index >= queue.size()
|
||||
*/
|
||||
public static Future<?> addQueueItemAt(final Context context, final long itemId,
|
||||
final int index, final boolean performAutoDownload) {
|
||||
public static Future<?> addQueueItemAt(final Context context, final long itemId, final int index) {
|
||||
return runOnDbThread(() -> {
|
||||
final PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
final List<FeedItem> queue = DBReader.getQueue();
|
||||
FeedItem item;
|
||||
|
||||
if (queue != null) {
|
||||
if (!itemListContains(queue, itemId)) {
|
||||
item = DBReader.getFeedItem(itemId);
|
||||
if (item != null) {
|
||||
queue.add(index, item);
|
||||
adapter.setQueue(queue);
|
||||
item.addTag(FeedItem.TAG_QUEUE);
|
||||
EventBus.getDefault().post(QueueEvent.added(item, index));
|
||||
EventBus.getDefault().post(FeedItemEvent.updated(item));
|
||||
if (item.isNew()) {
|
||||
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
|
||||
}
|
||||
if (!itemListContains(queue, itemId)) {
|
||||
FeedItem item = DBReader.getFeedItem(itemId);
|
||||
if (item != null) {
|
||||
queue.add(index, item);
|
||||
adapter.setQueue(queue);
|
||||
item.addTag(FeedItem.TAG_QUEUE);
|
||||
EventBus.getDefault().post(QueueEvent.added(item, index));
|
||||
EventBus.getDefault().post(FeedItemEvent.updated(item));
|
||||
if (item.isNew()) {
|
||||
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
adapter.close();
|
||||
if (performAutoDownload) {
|
||||
AutoDownloadManager.getInstance().autodownloadUndownloadedItems(context);
|
||||
}
|
||||
|
||||
AutoDownloadManager.getInstance().autodownloadUndownloadedItems(context);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 items FeedItem objects that should be added to the queue.
|
||||
*/
|
||||
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) {
|
||||
if (!item.hasMedia()) {
|
||||
continue;
|
||||
}
|
||||
itemIds.add(item.getId());
|
||||
item.addTag(FeedItem.TAG_QUEUE);
|
||||
}
|
||||
return addQueueItem(context, false, markAsUnplayed, itemIds.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 itemIds IDs of the FeedItem objects that should be added to the queue.
|
||||
*/
|
||||
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 runOnDbThread(() -> {
|
||||
if (itemIds.length < 1) {
|
||||
if (items.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -419,7 +378,6 @@ public class DBWriter {
|
||||
adapter.open();
|
||||
final List<FeedItem> queue = DBReader.getQueue();
|
||||
|
||||
boolean queueModified = false;
|
||||
LongList markAsUnplayedIds = new LongList();
|
||||
List<QueueEvent> events = new ArrayList<>();
|
||||
List<FeedItem> updatedItems = new ArrayList<>();
|
||||
@ -427,38 +385,35 @@ public class DBWriter {
|
||||
new ItemEnqueuePositionCalculator(UserPreferences.getEnqueueLocation());
|
||||
Playable currentlyPlaying = DBReader.getFeedMedia(PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
|
||||
int insertPosition = positionCalculator.calcPosition(queue, currentlyPlaying);
|
||||
for (long itemId : itemIds) {
|
||||
if (!itemListContains(queue, itemId)) {
|
||||
final FeedItem item = DBReader.getFeedItem(itemId);
|
||||
if (item != null) {
|
||||
queue.add(insertPosition, item);
|
||||
events.add(QueueEvent.added(item, insertPosition));
|
||||
|
||||
item.addTag(FeedItem.TAG_QUEUE);
|
||||
updatedItems.add(item);
|
||||
queueModified = true;
|
||||
if (item.isNew()) {
|
||||
markAsUnplayedIds.add(item.getId());
|
||||
}
|
||||
insertPosition++;
|
||||
}
|
||||
for (FeedItem item : items) {
|
||||
if (itemListContains(queue, item.getId())) {
|
||||
continue;
|
||||
} else if (!item.hasMedia()) {
|
||||
continue;
|
||||
}
|
||||
queue.add(insertPosition, item);
|
||||
events.add(QueueEvent.added(item, insertPosition));
|
||||
|
||||
item.addTag(FeedItem.TAG_QUEUE);
|
||||
updatedItems.add(item);
|
||||
if (item.isNew()) {
|
||||
markAsUnplayedIds.add(item.getId());
|
||||
}
|
||||
insertPosition++;
|
||||
}
|
||||
if (queueModified) {
|
||||
if (!updatedItems.isEmpty()) {
|
||||
applySortOrder(queue, events);
|
||||
adapter.setQueue(queue);
|
||||
for (QueueEvent event : events) {
|
||||
EventBus.getDefault().post(event);
|
||||
}
|
||||
EventBus.getDefault().post(FeedItemEvent.updated(updatedItems));
|
||||
if (markAsUnplayed && markAsUnplayedIds.size() > 0) {
|
||||
if (markAsUnplayedIds.size() > 0) {
|
||||
DBWriter.markItemPlayed(FeedItem.UNPLAYED, markAsUnplayedIds.toArray());
|
||||
}
|
||||
}
|
||||
adapter.close();
|
||||
if (performAutoDownload) {
|
||||
AutoDownloadManager.getInstance().autodownloadUndownloadedItems(context);
|
||||
}
|
||||
AutoDownloadManager.getInstance().autodownloadUndownloadedItems(context);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -13,9 +13,7 @@ import de.danoeh.antennapod.storage.preferences.UserPreferences.EnqueueLocation;
|
||||
import de.danoeh.antennapod.model.playback.Playable;
|
||||
|
||||
/**
|
||||
* @see de.danoeh.antennapod.storage.database.DBWriter#addQueueItem(android.content.Context, boolean, long...)
|
||||
* it uses the class to determine
|
||||
* the positions of the {@link FeedItem} in the queue.
|
||||
* Determine the positions of the new {@link FeedItem} in the queue.
|
||||
*/
|
||||
public class ItemEnqueuePositionCalculator {
|
||||
|
||||
|
||||
@ -99,6 +99,7 @@ public abstract class UserPreferences {
|
||||
public static final String PREF_EPISODE_CLEANUP = "prefEpisodeCleanup";
|
||||
public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
|
||||
public static final String PREF_AUTODL_GLOBAL = "prefEnableAutoDl";
|
||||
public static final String PREF_AUTODL_QUEUE = "prefEnableAutoDlQueue";
|
||||
public static final String PREF_ENABLE_AUTODL_ON_BATTERY = "prefEnableAutoDownloadOnBattery";
|
||||
private static final String PREF_PROXY_TYPE = "prefProxyType";
|
||||
private static final String PREF_PROXY_HOST = "prefProxyHost";
|
||||
@ -539,6 +540,10 @@ public abstract class UserPreferences {
|
||||
return prefs.getBoolean(PREF_AUTODL_GLOBAL, false);
|
||||
}
|
||||
|
||||
public static boolean isEnableAutodownloadQueue() {
|
||||
return prefs.getBoolean(PREF_AUTODL_QUEUE, false);
|
||||
}
|
||||
|
||||
public static boolean isEnableAutodownloadOnBattery() {
|
||||
return prefs.getBoolean(PREF_ENABLE_AUTODL_ON_BATTERY, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user