From b9c14b385ff81e602d90a6028a4ce6e6316f3a74 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Sat, 5 Sep 2015 12:25:11 -0400 Subject: [PATCH 1/2] remove ability to specify mediaIds when autodownloading --- .../core/storage/APDownloadAlgorithm.java | 22 +++++++------------ .../storage/AutomaticDownloadAlgorithm.java | 4 +--- .../antennapod/core/storage/DBTasks.java | 6 ++--- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java index c2e971dce..be9ae1157 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java @@ -29,12 +29,10 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm { * This method is executed on an internal single thread executor. * * @param context Used for accessing the DB. - * @param mediaIds If this list is not empty, the method will only download a candidate for automatic downloading if - * its media ID is in the mediaIds list. * @return A Runnable that will be submitted to an ExecutorService. */ @Override - public Runnable autoDownloadUndownloadedItems(final Context context, final long... mediaIds) { + public Runnable autoDownloadUndownloadedItems(final Context context) { return new Runnable() { @Override public void run() { @@ -53,17 +51,13 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm { Log.d(TAG, "Performing auto-dl of undownloaded episodes"); List candidates; - if(mediaIds.length > 0) { - candidates = DBReader.getFeedItems(context, mediaIds); - } else { - final List queue = DBReader.getQueue(context); - final List newItems = DBReader.getNewItemsList(context); - candidates = new ArrayList(queue.size() + newItems.size()); - candidates.addAll(queue); - for(FeedItem newItem : newItems) { - if(candidates.contains(newItem) == false) { - candidates.add(newItem); - } + final List queue = DBReader.getQueue(context); + final List newItems = DBReader.getNewItemsList(context); + candidates = new ArrayList(queue.size() + newItems.size()); + candidates.addAll(queue); + for(FeedItem newItem : newItems) { + if(candidates.contains(newItem) == false) { + candidates.add(newItem); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java index 9ca9620a7..72c68ddb6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java @@ -12,9 +12,7 @@ public interface AutomaticDownloadAlgorithm { * This method is executed on an internal single thread executor. * * @param context Used for accessing the DB. - * @param mediaIds If this list is not empty, the method will only download a candidate for automatic downloading if - * its media ID is in the mediaIds list. * @return A Runnable that will be submitted to an ExecutorService. */ - public Runnable autoDownloadUndownloadedItems(Context context, long... mediaIds); + public Runnable autoDownloadUndownloadedItems(Context context); } 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 5a3822a81..df9f3281a 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 @@ -374,14 +374,12 @@ public final class DBTasks { * This method is executed on an internal single thread executor. * * @param context Used for accessing the DB. - * @param mediaIds If this list is not empty, the method will only download a candidate for automatic downloading if - * its media ID is in the mediaIds list. * @return A Future that can be used for waiting for the methods completion. */ - public static Future autodownloadUndownloadedItems(final Context context, final long... mediaIds) { + public static Future autodownloadUndownloadedItems(final Context context) { Log.d(TAG, "autodownloadUndownloadedItems"); return autodownloadExec.submit(ClientConfig.dbTasksCallbacks.getAutomaticDownloadAlgorithm() - .autoDownloadUndownloadedItems(context, mediaIds)); + .autoDownloadUndownloadedItems(context)); } From e6202c57fcd47fd14203d9528a801673d1a433d1 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Sat, 5 Sep 2015 12:52:48 -0400 Subject: [PATCH 2/2] Resolve old episodes being marked as new. fixes AntennaPod/AntennaPod#1009 (I hope) --- .../antennapod/core/storage/DBTasks.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 df9f3281a..6ed99ec41 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 @@ -514,22 +514,27 @@ public final class DBTasks { Collections.sort(newFeed.getItems(), new FeedItemPubdateComparator()); - final boolean markNewItems; if (newFeed.getPageNr() == savedFeed.getPageNr()) { if (savedFeed.compareWithOther(newFeed)) { Log.d(TAG, "Feed has updated attribute values. Updating old feed's attributes"); savedFeed.updateFromOther(newFeed); } - markNewItems = true; } else { - Log.d(TAG, "New feed has a higher page number. Merging without marking as unread"); - markNewItems = false; + Log.d(TAG, "New feed has a higher page number."); savedFeed.setNextPageLink(newFeed.getNextPageLink()); } if (savedFeed.getPreferences().compareWithOther(newFeed.getPreferences())) { Log.d(TAG, "Feed has updated preferences. Updating old feed's preferences"); savedFeed.getPreferences().updateFromOther(newFeed.getPreferences()); } + + // get the most recent date now, before we start changing the list + FeedItem priorMostRecent = savedFeed.getMostRecentItem(); + Date priorMostRecentDate = null; + if (priorMostRecent != null) { + priorMostRecentDate = priorMostRecent.getPubDate(); + } + // Look for new or updated Items for (int idx = 0; idx < newFeed.getItems().size(); idx++) { final FeedItem item = newFeed.getItems().get(idx); @@ -540,7 +545,15 @@ public final class DBTasks { item.setFeed(savedFeed); item.setAutoDownload(savedFeed.getPreferences().getAutoDownload()); savedFeed.getItems().add(idx, item); - if (markNewItems) { + + // only mark the item new if it actually occurs + // before the most recent item (before we started adding things) + // (if the most recent date is null then we can assume there are no items + // and this is the first, hence 'new') + if (priorMostRecentDate == null || + priorMostRecentDate.before(item.getPubDate())) { + Log.d(TAG, "Marking item published on " + item.getPubDate() + + " new, prior most recent date = " + priorMostRecentDate); item.setNew(); } } else {