only autodownload new items

This commit is contained in:
Tom Hennen 2015-08-04 22:09:53 -04:00
parent fe6796f102
commit 224832300f
2 changed files with 12 additions and 7 deletions

View File

@ -325,6 +325,11 @@ public class DownloadService extends Service {
cancelNotificationUpdater(); cancelNotificationUpdater();
unregisterReceiver(cancelDownloadReceiver); unregisterReceiver(cancelDownloadReceiver);
// TODO: I'm not sure this is actually needed.
// We could just invoke the autodownloadUndownloadeditems method
// and it would get everything it's supposed to. By sending it the
// items in newMediaFiles we're overriding the download algorithm,
// which is not something we should probably do.
if (!newMediaFiles.isEmpty()) { if (!newMediaFiles.isEmpty()) {
Log.d(TAG, "newMediaFiles exist, autodownload them"); Log.d(TAG, "newMediaFiles exist, autodownload them");
DBTasks.autodownloadUndownloadedItems(getApplicationContext(), DBTasks.autodownloadUndownloadedItems(getApplicationContext(),
@ -783,7 +788,7 @@ public class DownloadService extends Service {
if(item.getPubDate() == null) { if(item.getPubDate() == null) {
Log.d(TAG, item.toString()); Log.d(TAG, item.toString());
} }
if (!item.isPlayed() && item.hasMedia() && !item.getMedia().isDownloaded()) { if (item.isNew() && item.hasMedia() && !item.getMedia().isDownloaded()) {
newMediaFiles.add(item.getMedia().getId()); newMediaFiles.add(item.getMedia().getId());
} }
} }

View File

@ -22,7 +22,7 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
private final APCleanupAlgorithm cleanupAlgorithm = new APCleanupAlgorithm(); private final APCleanupAlgorithm cleanupAlgorithm = new APCleanupAlgorithm();
/** /**
* Looks for undownloaded episodes in the queue or list of unread items and request a download if * Looks for undownloaded episodes in the queue or list of new items and request a download if
* 1. Network is available * 1. Network is available
* 2. The device is charging or the user allows auto download on battery * 2. The device is charging or the user allows auto download on battery
* 3. There is free space in the episode cache * 3. There is free space in the episode cache
@ -57,12 +57,12 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm {
candidates = DBReader.getFeedItems(context, mediaIds); candidates = DBReader.getFeedItems(context, mediaIds);
} else { } else {
final List<FeedItem> queue = DBReader.getQueue(context); final List<FeedItem> queue = DBReader.getQueue(context);
final List<FeedItem> unreadItems = DBReader.getUnreadItemsList(context); final List<FeedItem> newItems = DBReader.getNewItemsList(context);
candidates = new ArrayList<FeedItem>(queue.size() + unreadItems.size()); candidates = new ArrayList<FeedItem>(queue.size() + newItems.size());
candidates.addAll(queue); candidates.addAll(queue);
for(FeedItem unreadItem : unreadItems) { for(FeedItem newItem : newItems) {
if(candidates.contains(unreadItem) == false) { if(candidates.contains(newItem) == false) {
candidates.add(unreadItem); candidates.add(newItem);
} }
} }
} }