summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java9
-rw-r--r--storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java22
2 files changed, 28 insertions, 3 deletions
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java
index 31d4c4d7f..fa27e6e5b 100644
--- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java
+++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleaner.java
@@ -10,7 +10,8 @@ import java.util.List;
public class NonSubscribedFeedsCleaner {
private static final String TAG = "NonSubscrFeedsCleaner";
- private static final long TIME_TO_KEEP = 1000L * 3600 * 24 * 30; // 30 days
+ private static final long TIME_TO_KEEP_UNTOUCHED = 1000L * 3600 * 24; // 1 day
+ private static final long TIME_TO_KEEP_PLAYED = 1000L * 3600 * 24 * 30; // 30 days
public static void deleteOldNonSubscribedFeeds(Context context) {
List<Feed> feeds = DBReader.getFeedList();
@@ -35,6 +36,10 @@ public class NonSubscribedFeedsCleaner {
} else if (feed.hasEpisodeInApp()) {
return false;
}
- return feed.getLastRefreshAttempt() < System.currentTimeMillis() - TIME_TO_KEEP;
+ long timeSinceLastRefresh = System.currentTimeMillis() - feed.getLastRefreshAttempt();
+ if (!feed.hasInteractedWithEpisode()) {
+ return timeSinceLastRefresh > TIME_TO_KEEP_UNTOUCHED;
+ }
+ return timeSinceLastRefresh > TIME_TO_KEEP_PLAYED;
}
}
diff --git a/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java b/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java
index 76bbfddc1..0bd6c82c5 100644
--- a/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java
+++ b/storage/database/src/test/java/de/danoeh/antennapod/storage/database/NonSubscribedFeedsCleanerTest.java
@@ -34,7 +34,7 @@ public class NonSubscribedFeedsCleanerTest {
feed.setLastRefreshAttempt(System.currentTimeMillis());
assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed));
- feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS));
+ feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(1, TimeUnit.HOURS));
assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed));
feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(200, TimeUnit.DAYS));
@@ -45,6 +45,26 @@ public class NonSubscribedFeedsCleanerTest {
}
@Test
+ public void testPlayedItem() {
+ Feed feed = createFeed();
+ feed.setState(Feed.STATE_NOT_SUBSCRIBED);
+ FeedItem item = createItem(feed);
+ feed.getItems().add(item);
+
+ item.setPlayed(false);
+ feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS));
+ assertTrue(NonSubscribedFeedsCleaner.shouldDelete(feed));
+
+ item.setPlayed(true);
+ feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS));
+ assertFalse(NonSubscribedFeedsCleaner.shouldDelete(feed));
+
+ item.setPlayed(true);
+ feed.setLastRefreshAttempt(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(100, TimeUnit.DAYS));
+ assertTrue(NonSubscribedFeedsCleaner.shouldDelete(feed));
+ }
+
+ @Test
public void testQueuedItem() {
Feed feed = createFeed();
feed.setState(Feed.STATE_NOT_SUBSCRIBED);