diff options
author | Jared234 <jared@fantaye.de> | 2023-02-12 21:12:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-12 21:12:04 +0100 |
commit | 7a2f4771ecd327665497f21606ebc9d6c9415fd1 (patch) | |
tree | 6d26ea35891de0004ec04c7752c172c111cac85e /core/src/main | |
parent | 8248bc6bb1f5f71a1e6be3101e1b2173948bf516 (diff) | |
download | AntennaPod-7a2f4771ecd327665497f21606ebc9d6c9415fd1.zip |
Add sorting options to downloads screen (#6210)
Diffstat (limited to 'core/src/main')
5 files changed, 16 insertions, 8 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index bf8cf7778..14e11af23 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -387,7 +387,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { mediaItems.add(createBrowsableMediaItem(R.string.queue_label, R.drawable.ic_playlist_play_black, DBReader.getQueue().size())); mediaItems.add(createBrowsableMediaItem(R.string.downloads_label, R.drawable.ic_download_black, - DBReader.getDownloadedItems().size())); + DBReader.getDownloadedItems(UserPreferences.getDownloadsSortedOrder()).size())); mediaItems.add(createBrowsableMediaItem(R.string.episodes_label, R.drawable.ic_feed_black, DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.UNPLAYED)))); List<Feed> feeds = DBReader.getFeedList(); @@ -401,7 +401,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (parentId.equals(getResources().getString(R.string.queue_label))) { feedItems = DBReader.getQueue(); } else if (parentId.equals(getResources().getString(R.string.downloads_label))) { - feedItems = DBReader.getDownloadedItems(); + feedItems = DBReader.getDownloadedItems(UserPreferences.getDownloadsSortedOrder()); } else if (parentId.equals(getResources().getString(R.string.episodes_label))) { feedItems = DBReader.getRecentlyPublishedEpisodes(0, MAX_ANDROID_AUTO_EPISODES_PER_FEED, diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java index 2be330a3e..30c50b576 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APCleanupAlgorithm.java @@ -15,6 +15,7 @@ import java.util.concurrent.ExecutionException; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.model.feed.SortOrder; /** * Implementation of the EpisodeCleanupAlgorithm interface used by AntennaPod. @@ -88,7 +89,7 @@ public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm { @NonNull private List<FeedItem> getCandidates() { List<FeedItem> candidates = new ArrayList<>(); - List<FeedItem> downloadedItems = DBReader.getDownloadedItems(); + List<FeedItem> downloadedItems = DBReader.getDownloadedItems(SortOrder.DATE_NEW_OLD); Date mostRecentDateForDeletion = calcMostRecentDateForDeletion(new Date()); for (FeedItem item : downloadedItems) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java index 9fce34a44..3241f37ef 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APQueueCleanupAlgorithm.java @@ -12,6 +12,7 @@ import java.util.Locale; import java.util.concurrent.ExecutionException; import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.model.feed.SortOrder; /** * A cleanup algorithm that removes any item that isn't in the queue and isn't a favorite @@ -75,7 +76,7 @@ public class APQueueCleanupAlgorithm extends EpisodeCleanupAlgorithm { @NonNull private List<FeedItem> getCandidates() { List<FeedItem> candidates = new ArrayList<>(); - List<FeedItem> downloadedItems = DBReader.getDownloadedItems(); + List<FeedItem> downloadedItems = DBReader.getDownloadedItems(SortOrder.DATE_NEW_OLD); for (FeedItem item : downloadedItems) { if (item.hasMedia() && item.getMedia().isDownloaded() diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index 55acb8b92..4641e366c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -20,6 +20,7 @@ import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedItemFilter; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.feed.FeedPreferences; +import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.model.feed.SubscriptionsFilter; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.model.download.DownloadStatus; @@ -280,15 +281,19 @@ public final class DBReader { * @return A list of FeedItems whose episdoe has been downloaded. */ @NonNull - public static List<FeedItem> getDownloadedItems() { + public static List<FeedItem> getDownloadedItems(@Nullable SortOrder sortOrder) { Log.d(TAG, "getDownloadedItems() called"); + // Set a default sort order + if (sortOrder == null) { + sortOrder = SortOrder.DATE_NEW_OLD; + } + PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); - try (Cursor cursor = adapter.getDownloadedItemsCursor()) { + try (Cursor cursor = adapter.getDownloadedItemsCursor(sortOrder)) { List<FeedItem> items = extractItemlistFromCursor(adapter, cursor); loadAdditionalFeedItemListData(items); - Collections.sort(items, new FeedItemPubdateComparator()); return items; } finally { adapter.close(); 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 5d092da6d..448cffeb9 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.model.feed.FeedItem; +import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.storage.preferences.UserPreferences; /** @@ -74,7 +75,7 @@ public class ExceptFavoriteCleanupAlgorithm extends EpisodeCleanupAlgorithm { @NonNull private List<FeedItem> getCandidates() { List<FeedItem> candidates = new ArrayList<>(); - List<FeedItem> downloadedItems = DBReader.getDownloadedItems(); + List<FeedItem> downloadedItems = DBReader.getDownloadedItems(SortOrder.DATE_NEW_OLD); for (FeedItem item : downloadedItems) { if (item.hasMedia() && item.getMedia().isDownloaded() |