summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hennen <TomHennen@users.noreply.github.com>2015-09-07 14:27:36 -0400
committerTom Hennen <TomHennen@users.noreply.github.com>2015-09-07 14:27:36 -0400
commit6780980b1ca1eba5305a51fd077d867ac6b0bf4d (patch)
tree717433019f7c44ab1c6a003a17a7f1396d6bbc83
parent1ac58a34ebeaa144958cc248b59ffa3771b128cc (diff)
parente6202c57fcd47fd14203d9528a801673d1a433d1 (diff)
downloadAntennaPod-6780980b1ca1eba5305a51fd077d867ac6b0bf4d.zip
Merge pull request #1172 from TomHennen/fix_new_episodes
Fix new episodes
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java22
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java4
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java29
3 files changed, 29 insertions, 26 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<FeedItem> candidates;
- if(mediaIds.length > 0) {
- candidates = DBReader.getFeedItems(context, mediaIds);
- } else {
- final List<FeedItem> queue = DBReader.getQueue(context);
- final List<FeedItem> newItems = DBReader.getNewItemsList(context);
- candidates = new ArrayList<FeedItem>(queue.size() + newItems.size());
- candidates.addAll(queue);
- for(FeedItem newItem : newItems) {
- if(candidates.contains(newItem) == false) {
- candidates.add(newItem);
- }
+ final List<FeedItem> queue = DBReader.getQueue(context);
+ final List<FeedItem> newItems = DBReader.getNewItemsList(context);
+ candidates = new ArrayList<FeedItem>(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..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
@@ -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));
}
@@ -516,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);
@@ -542,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 {