summaryrefslogtreecommitdiff
path: root/storage/database
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2022-08-27 11:19:34 +0200
committerGitHub <noreply@github.com>2022-08-27 11:19:34 +0200
commit77104c9038abf579bc5652fc0ec5f941c0f9799f (patch)
tree3e45eaf8f65b222b475e2ec340d0af175c11c23c /storage/database
parentec92722c043cd30bfe9c21171b2a3f62c44884d7 (diff)
downloadAntennaPod-77104c9038abf579bc5652fc0ec5f941c0f9799f.zip
Home Screen (#5864)
Co-authored-by: ueen <ueli.sarnighausen@online.de>
Diffstat (limited to 'storage/database')
-rw-r--r--storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java30
1 files changed, 30 insertions, 0 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 5ce75a2ae..42517e972 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
@@ -994,6 +994,17 @@ public class PodDBAdapter {
return db.rawQuery(query, null);
}
+ public final Cursor getPausedQueueCursor(int limit) {
+ //playback position > 0 (paused), rank by last played, then rest of queue
+ final String query = SELECT_FEED_ITEMS_AND_MEDIA
+ + " INNER JOIN " + TABLE_NAME_QUEUE
+ + " ON " + SELECT_KEY_ITEM_ID + " = " + TABLE_NAME_QUEUE + "." + KEY_FEEDITEM
+ + " ORDER BY " + TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + ">0 DESC , "
+ + TABLE_NAME_FEED_MEDIA + "." + KEY_LAST_PLAYED_TIME + " DESC , " + TABLE_NAME_QUEUE + "." + KEY_ID
+ + " LIMIT " + limit;
+ return db.rawQuery(query, null);
+ }
+
public final Cursor getFavoritesCursor(int offset, int limit) {
final String query = SELECT_FEED_ITEMS_AND_MEDIA
+ " INNER JOIN " + TABLE_NAME_FAVORITES
@@ -1051,6 +1062,25 @@ public class PodDBAdapter {
return db.rawQuery(query, null);
}
+ public Cursor getRandomEpisodesCursor(int limit, int seed) {
+ final String allItemsRandomOrder = SELECT_FEED_ITEMS_AND_MEDIA
+ + " WHERE (" + KEY_READ + " = " + FeedItem.NEW + " OR " + KEY_READ + " = " + FeedItem.UNPLAYED + ") "
+ // Only from the last two years. Older episodes frequently contain broken covers and stuff like that
+ + " AND " + KEY_PUBDATE + " > " + (System.currentTimeMillis() - 1000L * 3600L * 24L * 356L * 2)
+ + " ORDER BY " + randomEpisodeNumber(seed);
+ final String query = "SELECT * FROM (" + allItemsRandomOrder + ")"
+ + " GROUP BY " + KEY_FEED
+ + " ORDER BY " + randomEpisodeNumber(seed * 3) + " DESC LIMIT " + limit;
+ return db.rawQuery(query, null);
+ }
+
+ /**
+ * SQLite does not support random seeds. Create our own "random" number based on that seed and the item ID
+ */
+ private String randomEpisodeNumber(int seed) {
+ return "((" + SELECT_KEY_ITEM_ID + " * " + seed + ") % 46471)";
+ }
+
public final Cursor getTotalEpisodeCountCursor(FeedItemFilter filter) {
String filterQuery = FeedItemFilterQuery.generateFrom(filter);
String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery;