From 4e9597a95075e8384c6545b8d6c9a63be3c22e48 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Thu, 16 Apr 2015 20:17:09 -0400 Subject: [PATCH] now actually using the date to figure out what is omst recent rather than just assuming it's the first --- .../de/danoeh/antennapod/core/feed/Feed.java | 17 ++++++++++------- .../danoeh/antennapod/core/storage/DBTasks.java | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java index 90edd50bc..8860653a1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java @@ -350,14 +350,17 @@ public class Feed extends FeedFile implements FlattrThing, PicassoImageResource return false; } - public FeedItem getMostRecentItem(boolean enableEpisodeFilter) { - // we're going to assume the most recent item is the first one... - // we can sort later if needed - int numItems = getNumOfItems(enableEpisodeFilter); - if (numItems > 0) { - return getItemAtIndex(enableEpisodeFilter, 0); + public FeedItem getMostRecentItem() { + // we could sort, but we don't need to, a simple search is fine... + Date mostRecentDate = new Date(0); + FeedItem mostRecentItem = null; + for (FeedItem item : items) { + if (item.getPubDate().after(mostRecentDate)) { + mostRecentDate = item.getPubDate(); + mostRecentItem = item; + } } - return null; + return mostRecentItem; } @Override 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 0624b0396..8dd6ddea7 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 @@ -591,7 +591,7 @@ public final class DBTasks { // Add a new Feed // all new feeds will have the most recent item marked as unplayed - FeedItem mostRecent = newFeed.getMostRecentItem(false); + FeedItem mostRecent = newFeed.getMostRecentItem(); if (mostRecent != null) { mostRecent.setRead(false); }