From 0420bf47f48380f0b72fe245ac0990bb2cd7368d Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Thu, 16 Apr 2015 20:09:11 -0400 Subject: the most recent episode in new feeds is marked unplayed --- .../main/java/de/danoeh/antennapod/core/feed/Feed.java | 10 ++++++++++ .../java/de/danoeh/antennapod/core/storage/DBTasks.java | 16 ++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'core/src/main/java/de') 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 c0f71ed55..90edd50bc 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,6 +350,16 @@ 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); + } + return null; + } + @Override public int getTypeAsInt() { return FEEDFILETYPE_FEED; 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 e0e370b0d..0624b0396 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 @@ -560,7 +560,7 @@ public final class DBTasks { /** * Adds new Feeds to the database or updates the old versions if they already exists. If another Feed with the same * identifying value already exists, this method will add new FeedItems from the new Feed to the existing Feed. - * These FeedItems will be marked as unread. + * These FeedItems will be marked as unread with the exception of the most recent FeedItem. *

* This method can update multiple feeds at once. Submitting a feed twice in the same method call can result in undefined behavior. *

@@ -586,12 +586,16 @@ public final class DBTasks { final Feed savedFeed = searchFeedByIdentifyingValueOrID(context, adapter, newFeed); if (savedFeed == null) { - if (BuildConfig.DEBUG) - Log.d(TAG, - "Found no existing Feed with title " - + newFeed.getTitle() + ". Adding as new one." - ); + Log.d(TAG, "Found no existing Feed with title " + + newFeed.getTitle() + ". Adding as new one."); + // Add a new Feed + // all new feeds will have the most recent item marked as unplayed + FeedItem mostRecent = newFeed.getMostRecentItem(false); + if (mostRecent != null) { + mostRecent.setRead(false); + } + newFeedsList.add(newFeed); resultFeeds[feedIdx] = newFeed; } else { -- cgit v1.2.3