diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-03-24 21:27:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-24 21:27:30 +0100 |
commit | 5c6000155cc8f2c6111301ceecae08bf41e0b735 (patch) | |
tree | f2433fb8c8f59e77b7ff25ac4296d82a3f318b07 /storage/database | |
parent | 4078b3475e5140e6f5f9ef924bc8ff8d9e345113 (diff) | |
download | AntennaPod-5c6000155cc8f2c6111301ceecae08bf41e0b735.zip |
Let the database do the sorting (#7025)
Diffstat (limited to 'storage/database')
3 files changed, 11 insertions, 25 deletions
diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java index 261a9dd45..9ae07d61e 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java @@ -983,7 +983,7 @@ public class PodDBAdapter { public final Cursor getDownloadLog(final int feedFileType, final long feedFileId) { final String query = "SELECT * FROM " + TABLE_NAME_DOWNLOAD_LOG + " WHERE " + KEY_FEEDFILE + "=" + feedFileId + " AND " + KEY_FEEDFILETYPE + "=" + feedFileType - + " ORDER BY " + KEY_ID + " DESC"; + + " ORDER BY " + KEY_COMPLETION_DATE + " DESC"; return db.rawQuery(query, null); } @@ -1107,29 +1107,6 @@ public class PodDBAdapter { return "((" + SELECT_KEY_ITEM_ID + " * " + seed + ") % 46471)"; } - /** - * Returns a cursor which contains feed media objects with a playback - * completion date in ascending order. - * - * @param offset The row to start at. - * @param limit The maximum row count of the returned cursor. Must be an - * integer >= 0. - * @throws IllegalArgumentException if limit < 0 - */ - public final Cursor getCompletedMediaCursor(int offset, int limit) { - if (limit < 0) { - throw new IllegalArgumentException("Limit must be >= 0"); - } - - return db.query(TABLE_NAME_FEED_MEDIA, null, - KEY_PLAYBACK_COMPLETION_DATE + " > 0", null, null, - null, String.format(Locale.US, "%s DESC LIMIT %d, %d", KEY_PLAYBACK_COMPLETION_DATE, offset, limit)); - } - - public final long getCompletedMediaLength() { - return DatabaseUtils.queryNumEntries(db, TABLE_NAME_FEED_MEDIA, KEY_PLAYBACK_COMPLETION_DATE + "> 0"); - } - public final Cursor getSingleFeedMediaCursor(long id) { final String query = "SELECT " + KEYS_FEED_MEDIA + " FROM " + TABLE_NAME_FEED_MEDIA + " WHERE " + KEY_ID + "=" + id; @@ -1168,7 +1145,8 @@ public class PodDBAdapter { urlsString.append(DatabaseUtils.sqlEscapeString(urls.get(i))); } final String query = SELECT_FEED_ITEMS_AND_MEDIA - + " WHERE " + KEY_DOWNLOAD_URL + " IN (" + urlsString + ")"; + + " WHERE " + KEY_DOWNLOAD_URL + " IN (" + urlsString + ")" + + " ORDER BY " + KEY_PLAYBACK_COMPLETION_DATE + " DESC"; return db.rawQuery(query, null); } diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemFilterQuery.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemFilterQuery.java index 6c78af50c..e3dbf496b 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemFilterQuery.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemFilterQuery.java @@ -22,6 +22,7 @@ public class FeedItemFilterQuery { // The keys used within this method, but explicitly combined with their table String keyRead = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_READ; String keyPosition = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_POSITION; + String keyCompletionDate = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_PLAYBACK_COMPLETION_DATE; String keyDownloaded = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_DOWNLOADED; String keyMediaId = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_ID; String keyItemId = PodDBAdapter.TABLE_NAME_FEED_ITEMS + "." + PodDBAdapter.KEY_ID; @@ -62,6 +63,9 @@ public class FeedItemFilterQuery { } else if (filter.showNotFavorite) { statements.add(keyItemId + " NOT IN (SELECT " + keyFeedItem + " FROM " + tableFavorites + ") "); } + if (filter.showInHistory) { + statements.add(keyCompletionDate + " > 0 "); + } if (statements.isEmpty()) { return ""; diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java index d4404a082..644402079 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/mapper/FeedItemSortQuery.java @@ -31,6 +31,10 @@ public class FeedItemSortQuery { case SIZE_LARGE_SMALL: sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + PodDBAdapter.KEY_SIZE + " " + "DESC"; break; + case COMPLETION_DATE_NEW_OLD: + sortQuery = PodDBAdapter.TABLE_NAME_FEED_MEDIA + "." + + PodDBAdapter.KEY_PLAYBACK_COMPLETION_DATE + " " + "DESC"; + break; default: sortQuery = ""; break; |