From ae8759869dad5feb134aa4d5d598d9e58ee2287a Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Sat, 6 Feb 2021 21:43:34 +0100 Subject: [PATCH] Fixed default number of items to clean up Not sure why this worked before TBH - but default value should naturally be to reduce to desired cache size. Probably makes no difference in actual use - but it is how the tests are constructed. --- .../core/storage/ExceptFavoriteCleanupAlgorithm.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithm.java index d2920db9c..f0788db33 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/ExceptFavoriteCleanupAlgorithm.java @@ -13,6 +13,7 @@ import java.util.Locale; import java.util.concurrent.ExecutionException; import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.preferences.UserPreferences; /** * A cleanup algorithm that removes any item that isn't a favorite but only if space is needed. @@ -86,6 +87,13 @@ public class ExceptFavoriteCleanupAlgorithm extends EpisodeCleanupAlgorithm { @Override public int getDefaultCleanupParameter() { + int cacheSize = UserPreferences.getEpisodeCacheSize(); + if (cacheSize != UserPreferences.getEpisodeCacheSizeUnlimited()) { + int downloadedEpisodes = DBReader.getNumberOfDownloadedEpisodes(); + if (downloadedEpisodes > cacheSize) { + return downloadedEpisodes - cacheSize; + } + } return 0; } }