diff options
author | ByteHamster <info@bytehamster.com> | 2019-12-31 14:32:52 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-01-09 20:41:50 +0100 |
commit | 128f80fe55575b9ee105d810bd2c2c70e8a25389 (patch) | |
tree | 61934b3061b541d773cd8325d037b4c2eaa67695 /core | |
parent | 6d0b16461d5567dae4b3dd6553d53acffb766359 (diff) | |
download | AntennaPod-128f80fe55575b9ee105d810bd2c2c70e8a25389.zip |
Added paged loading to 'new episodes' list
Diffstat (limited to 'core')
4 files changed, 28 insertions, 12 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java index d029e7bfb..6e4054009 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/APDownloadAlgorithm.java @@ -50,7 +50,7 @@ public class APDownloadAlgorithm implements AutomaticDownloadAlgorithm { List<FeedItem> candidates; final List<FeedItem> queue = DBReader.getQueue(); - final List<FeedItem> newItems = DBReader.getNewItemsList(); + final List<FeedItem> newItems = DBReader.getNewItemsList(0, Integer.MAX_VALUE); candidates = new ArrayList<>(queue.size() + newItems.size()); candidates.addAll(queue); for (FeedItem newItem : newItems) { 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 8b87d7c54..9fe9eae1f 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 @@ -353,16 +353,18 @@ public final class DBReader { * Loads a list of FeedItems that are considered new. * Excludes items from feeds that do not have keep updated enabled. * + * @param offset The first episode that should be loaded. + * @param limit The maximum number of episodes that should be loaded. * @return A list of FeedItems that are considered new. */ - public static List<FeedItem> getNewItemsList() { + public static List<FeedItem> getNewItemsList(int offset, int limit) { Log.d(TAG, "getNewItemsList() called"); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); Cursor cursor = null; try { - cursor = adapter.getNewItemsCursor(); + cursor = adapter.getNewItemsCursor(offset, limit); List<FeedItem> items = extractItemlistFromCursor(adapter, cursor); loadAdditionalFeedItemListData(items); return items; @@ -374,14 +376,21 @@ public final class DBReader { } } - public static List<FeedItem> getFavoriteItemsList() { + /** + * Loads a list of favorite items. + * + * @param offset The first episode that should be loaded. + * @param limit The maximum number of episodes that should be loaded. + * @return A list of FeedItems that are marked as favorite. + */ + public static List<FeedItem> getFavoriteItemsList(int offset, int limit) { Log.d(TAG, "getFavoriteItemsList() called"); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); Cursor cursor = null; try { - cursor = adapter.getFavoritesCursor(); + cursor = adapter.getFavoritesCursor(offset, limit); List<FeedItem> items = extractItemlistFromCursor(adapter, cursor); loadAdditionalFeedItemListData(items); return items; @@ -400,7 +409,7 @@ public final class DBReader { adapter.open(); Cursor cursor = null; try { - cursor = adapter.getFavoritesCursor(); + cursor = adapter.getFavoritesCursor(0, Integer.MAX_VALUE); LongList favoriteIDs = new LongList(cursor.getCount()); while (cursor.moveToNext()) { favoriteIDs.add(cursor.getLong(0)); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 96c3a46da..ab584df56 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -987,14 +987,17 @@ public class PodDBAdapter { } - public final Cursor getFavoritesCursor() { + public final Cursor getFavoritesCursor(int offset, int limit) { Object[] args = new String[]{ SEL_FI_SMALL_STR, TABLE_NAME_FEED_ITEMS, TABLE_NAME_FAVORITES, TABLE_NAME_FEED_ITEMS + "." + KEY_ID, TABLE_NAME_FAVORITES + "." + KEY_FEEDITEM, - TABLE_NAME_FEED_ITEMS + "." + KEY_PUBDATE}; - String query = String.format("SELECT %s FROM %s INNER JOIN %s ON %s=%s ORDER BY %s DESC", args); + TABLE_NAME_FEED_ITEMS + "." + KEY_PUBDATE, + String.valueOf(offset), + String.valueOf(limit) + }; + String query = String.format("SELECT %s FROM %s INNER JOIN %s ON %s=%s ORDER BY %s DESC LIMIT %s, %s", args); return db.rawQuery(query, null); } @@ -1027,16 +1030,19 @@ public class PodDBAdapter { * Excludes those feeds that do not have 'Keep Updated' enabled. * The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection. */ - public final Cursor getNewItemsCursor() { + public final Cursor getNewItemsCursor(int offset, int limit) { Object[] args = new String[]{ SEL_FI_SMALL_STR, TABLE_NAME_FEED_ITEMS, TABLE_NAME_FEEDS, TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID, TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW + " AND " + TABLE_NAME_FEEDS + "." + KEY_KEEP_UPDATED + " > 0", - KEY_PUBDATE + " DESC" + KEY_PUBDATE + " DESC", + String.valueOf(offset), + String.valueOf(limit) }; - final String query = String.format("SELECT %s FROM %s INNER JOIN %s ON %s WHERE %s ORDER BY %s", args); + final String query = String.format("SELECT %s FROM %s INNER JOIN %s ON %s WHERE %s " + + "ORDER BY %s LIMIT %s, %s", args); return db.rawQuery(query, null); } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index ce6a0e41d..e59eac331 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -108,6 +108,7 @@ <item quantity="other">%d days after finishing</item> </plurals> <string name="num_selected_label">%d selected</string> + <string name="loading_more">Loading moreā¦</string> <!-- 'Add Feed' Activity labels --> <string name="feedurl_label">Feed URL</string> |