Instead of specialized methods, use the global 'getEpisodes' method with a filter (#6358)

This commit is contained in:
ByteHamster 2023-03-01 20:52:23 +01:00 committed by GitHub
parent 581e71b306
commit 24d1a06662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 73 additions and 210 deletions

View File

@ -235,7 +235,7 @@ public class PlaybackTest {
openNavDrawer();
onDrawerItem(withText(R.string.episodes_label)).perform(click());
final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(0, 10,
final List<FeedItem> episodes = DBReader.getEpisodes(0, 10,
FeedItemFilter.unfiltered(), SortOrder.DATE_NEW_OLD);
Matcher<View> allEpisodesMatcher = allOf(withId(R.id.recyclerView), isDisplayed(), hasMinimumChildCount(2));
onView(isRoot()).perform(waitForView(allEpisodesMatcher, 1000));
@ -271,7 +271,7 @@ public class PlaybackTest {
uiTestUtils.addLocalFeedData(true);
DBWriter.clearQueue().get();
activityTestRule.launchActivity(new Intent());
final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(0, 10,
final List<FeedItem> episodes = DBReader.getEpisodes(0, 10,
FeedItemFilter.unfiltered(), SortOrder.DATE_NEW_OLD);
startLocalPlayback();

View File

@ -61,15 +61,13 @@ public class AllEpisodesFragment extends EpisodesListFragment {
@NonNull
@Override
protected List<FeedItem> loadData() {
return DBReader.getRecentlyPublishedEpisodes(0, page * EPISODES_PER_PAGE,
getFilter(), getSortOrder());
return DBReader.getEpisodes(0, page * EPISODES_PER_PAGE, getFilter(), getSortOrder());
}
@NonNull
@Override
protected List<FeedItem> loadMoreData(int page) {
return DBReader.getRecentlyPublishedEpisodes((page - 1) * EPISODES_PER_PAGE,
EPISODES_PER_PAGE, getFilter(), getSortOrder());
return DBReader.getEpisodes((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE, getFilter(), getSortOrder());
}
@Override

View File

@ -315,7 +315,8 @@ public class CompletedDownloadsFragment extends Fragment
emptyView.hide();
disposable = Observable.fromCallable(() -> {
SortOrder sortOrder = UserPreferences.getDownloadsSortedOrder();
List<FeedItem> downloadedItems = DBReader.getDownloadedItems(sortOrder);
List<FeedItem> downloadedItems = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.DOWNLOADED), sortOrder);
List<Long> mediaIds = new ArrayList<>();
if (runningDownloads == null) {

View File

@ -97,14 +97,15 @@ public class InboxFragment extends EpisodesListFragment {
@NonNull
@Override
protected List<FeedItem> loadData() {
return DBReader.getNewItemsList(0, page * EPISODES_PER_PAGE, UserPreferences.getInboxSortedOrder());
return DBReader.getEpisodes(0, page * EPISODES_PER_PAGE,
new FeedItemFilter(FeedItemFilter.NEW), UserPreferences.getInboxSortedOrder());
}
@NonNull
@Override
protected List<FeedItem> loadMoreData(int page) {
return DBReader.getNewItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE,
UserPreferences.getInboxSortedOrder());
return DBReader.getEpisodes((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE,
new FeedItemFilter(FeedItemFilter.NEW), UserPreferences.getInboxSortedOrder());
}
@Override

View File

@ -124,7 +124,8 @@ public class DownloadsSection extends HomeSection {
disposable.dispose();
}
SortOrder sortOrder = UserPreferences.getDownloadsSortedOrder();
disposable = Observable.fromCallable(() -> DBReader.getDownloadedItems(sortOrder))
disposable = Observable.fromCallable(() -> DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.DOWNLOADED), sortOrder))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(downloads -> {

View File

@ -26,7 +26,6 @@ import de.danoeh.antennapod.fragment.InboxFragment;
import de.danoeh.antennapod.fragment.swipeactions.SwipeActions;
import de.danoeh.antennapod.model.feed.FeedItem;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.storage.database.PodDBAdapter;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.home.HomeSection;
import io.reactivex.Observable;
@ -126,8 +125,9 @@ public class InboxSection extends HomeSection {
disposable.dispose();
}
disposable = Observable.fromCallable(() ->
new Pair<>(DBReader.getNewItemsList(0, NUM_EPISODES, UserPreferences.getInboxSortedOrder()),
PodDBAdapter.getInstance().getNumberOfNewItems()))
new Pair<>(DBReader.getEpisodes(0, NUM_EPISODES,
new FeedItemFilter(FeedItemFilter.NEW), UserPreferences.getInboxSortedOrder()),
DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.NEW))))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(data -> {

View File

@ -43,7 +43,7 @@ public class FavoritesWriter implements ExportWriter {
InputStream feedTemplateStream = context.getAssets().open(FEED_TEMPLATE);
String feedTemplate = IOUtils.toString(feedTemplateStream, UTF_8);
List<FeedItem> allFavorites = DBReader.getRecentlyPublishedEpisodes(0, Integer.MAX_VALUE,
List<FeedItem> allFavorites = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.IS_FAVORITE), SortOrder.DATE_NEW_OLD);
Map<Long, List<FeedItem>> favoriteByFeed = getFeedMap(allFavorites);

View File

@ -402,9 +402,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
if (parentId.equals(getResources().getString(R.string.app_name))) {
mediaItems.add(createBrowsableMediaItem(R.string.queue_label, R.drawable.ic_playlist_play_black,
DBReader.getQueue().size()));
DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.QUEUED))));
mediaItems.add(createBrowsableMediaItem(R.string.downloads_label, R.drawable.ic_download_black,
DBReader.getDownloadedItems(UserPreferences.getDownloadsSortedOrder()).size()));
DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.DOWNLOADED))));
mediaItems.add(createBrowsableMediaItem(R.string.episodes_label, R.drawable.ic_feed_black,
DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.UNPLAYED))));
List<Feed> feeds = DBReader.getFeedList();
@ -418,10 +418,10 @@ 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(UserPreferences.getDownloadsSortedOrder());
feedItems = DBReader.getEpisodes(0, MAX_ANDROID_AUTO_EPISODES_PER_FEED,
new FeedItemFilter(FeedItemFilter.DOWNLOADED), UserPreferences.getDownloadsSortedOrder());
} else if (parentId.equals(getResources().getString(R.string.episodes_label))) {
feedItems = DBReader.getRecentlyPublishedEpisodes(0,
MAX_ANDROID_AUTO_EPISODES_PER_FEED,
feedItems = DBReader.getEpisodes(0, MAX_ANDROID_AUTO_EPISODES_PER_FEED,
new FeedItemFilter(FeedItemFilter.UNPLAYED), SortOrder.DATE_NEW_OLD);
} else if (parentId.startsWith("FeedId:")) {
long feedId = Long.parseLong(parentId.split(":")[1]);

View File

@ -14,6 +14,7 @@ import java.util.Locale;
import java.util.concurrent.ExecutionException;
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.SortOrder;
@ -89,7 +90,8 @@ public class APCleanupAlgorithm extends EpisodeCleanupAlgorithm {
@NonNull
private List<FeedItem> getCandidates() {
List<FeedItem> candidates = new ArrayList<>();
List<FeedItem> downloadedItems = DBReader.getDownloadedItems(SortOrder.DATE_NEW_OLD);
List<FeedItem> downloadedItems = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.DOWNLOADED), SortOrder.DATE_NEW_OLD);
Date mostRecentDateForDeletion = calcMostRecentDateForDeletion(new Date());
for (FeedItem item : downloadedItems) {

View File

@ -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.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
/**
@ -76,7 +77,8 @@ public class APQueueCleanupAlgorithm extends EpisodeCleanupAlgorithm {
@NonNull
private List<FeedItem> getCandidates() {
List<FeedItem> candidates = new ArrayList<>();
List<FeedItem> downloadedItems = DBReader.getDownloadedItems(SortOrder.DATE_NEW_OLD);
List<FeedItem> downloadedItems = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.DOWNLOADED), SortOrder.DATE_NEW_OLD);
for (FeedItem item : downloadedItems) {
if (item.hasMedia()
&& item.getMedia().isDownloaded()

View File

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest;
import de.danoeh.antennapod.core.service.download.DownloadRequestCreator;
@ -53,7 +54,8 @@ public class AutomaticDownloadAlgorithm {
List<FeedItem> candidates;
final List<FeedItem> queue = DBReader.getQueue();
final List<FeedItem> newItems = DBReader.getNewItemsList(0, Integer.MAX_VALUE, SortOrder.DATE_NEW_OLD);
final List<FeedItem> newItems = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.NEW), SortOrder.DATE_NEW_OLD);
candidates = new ArrayList<>(queue.size() + newItems.size());
candidates.addAll(queue);
for (FeedItem newItem : newItems) {
@ -77,7 +79,7 @@ public class AutomaticDownloadAlgorithm {
}
int autoDownloadableEpisodes = candidates.size();
int downloadedEpisodes = DBReader.getNumberOfDownloadedEpisodes();
int downloadedEpisodes = DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.DOWNLOADED));
int deletedEpisodes = EpisodeCleanupAlgorithmFactory.build()
.makeRoomForEpisodes(context, autoDownloadableEpisodes);
boolean cacheIsUnlimited =

View File

@ -275,73 +275,6 @@ public final class DBReader {
}
}
/**
* Loads a list of FeedItems whose episode has been downloaded.
*
* @return A list of FeedItems whose episdoe has been downloaded.
*/
@NonNull
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(sortOrder)) {
List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
loadAdditionalFeedItemListData(items);
return items;
} finally {
adapter.close();
}
}
/**
* Loads a list of FeedItems whose episode has been played.
*
* @return A list of FeedItems whose episdoe has been played.
*/
@NonNull
public static List<FeedItem> getPlayedItems() {
Log.d(TAG, "getPlayedItems() called");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try (Cursor cursor = adapter.getPlayedItemsCursor()) {
List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
loadAdditionalFeedItemListData(items);
return items;
} finally {
adapter.close();
}
}
/**
* 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(int offset, int limit, SortOrder sortOrder) {
Log.d(TAG, "getNewItemsList() called");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try (Cursor cursor = adapter.getNewItemsCursor(offset, limit, sortOrder)) {
List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
loadAdditionalFeedItemListData(items);
return items;
} finally {
adapter.close();
}
}
private static LongList getFavoriteIDList() {
Log.d(TAG, "getFavoriteIDList() called");
@ -359,19 +292,17 @@ public final class DBReader {
}
/**
* Loads a filtered list of FeedItems sorted by pubDate in descending order.
*
* @param offset The first episode that should be loaded.
* @param limit The maximum number of episodes that should be loaded.
* @param filter The filter describing which episodes to filter out.
*/
@NonNull
public static List<FeedItem> getRecentlyPublishedEpisodes(int offset, int limit,
FeedItemFilter filter, SortOrder sortOrder) {
public static List<FeedItem> getEpisodes(int offset, int limit, FeedItemFilter filter, SortOrder sortOrder) {
Log.d(TAG, "getRecentlyPublishedEpisodes() called with: offset=" + offset + ", limit=" + limit);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try (Cursor cursor = adapter.getRecentlyPublishedItemsCursor(offset, limit, filter, sortOrder)) {
try (Cursor cursor = adapter.getEpisodesCursor(offset, limit, filter, sortOrder)) {
List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
loadAdditionalFeedItemListData(items);
return items;
@ -380,6 +311,19 @@ public final class DBReader {
}
}
public static int getTotalEpisodeCount(FeedItemFilter filter) {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try (Cursor cursor = adapter.getEpisodeCountCursor(filter)) {
if (cursor.moveToFirst()) {
return cursor.getInt(0);
}
return -1;
} finally {
adapter.close();
}
}
public static List<FeedItem> getRandomEpisodes(int limit, int seed) {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
@ -392,19 +336,6 @@ public final class DBReader {
}
}
public static int getTotalEpisodeCount(FeedItemFilter filter) {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try (Cursor cursor = adapter.getTotalEpisodeCountCursor(filter)) {
if (cursor.moveToFirst()) {
return cursor.getInt(0);
}
return -1;
} finally {
adapter.close();
}
}
/**
* Loads the playback history from the database. A FeedItem is in the playback history if playback of the correpsonding episode
* has been completed at least once.
@ -755,24 +686,6 @@ public final class DBReader {
}
}
/**
* Returns the number of downloaded episodes.
*
* @return The number of downloaded episodes.
*/
public static int getNumberOfDownloadedEpisodes() {
Log.d(TAG, "getNumberOfDownloadedEpisodes() called with: " + "");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try {
return adapter.getNumberOfDownloadedEpisodes();
} finally {
adapter.close();
}
}
/**
* Searches the DB for a FeedMedia of the given id.
*
@ -959,9 +872,9 @@ public final class DBReader {
}
Collections.sort(feeds, comparator);
int queueSize = adapter.getQueueSize();
int numNewItems = adapter.getNumberOfNewItems();
int numDownloadedItems = adapter.getNumberOfDownloadedEpisodes();
final int queueSize = adapter.getQueueSize();
final int numNewItems = getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.NEW));
final int numDownloadedItems = getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.DOWNLOADED));
List<NavDrawerData.DrawerItem> items = new ArrayList<>();
Map<String, NavDrawerData.TagDrawerItem> folders = new HashMap<>();

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.storage;
import android.content.Context;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
public abstract class EpisodeCleanupAlgorithm {
@ -51,8 +52,7 @@ public abstract class EpisodeCleanupAlgorithm {
int getNumEpisodesToCleanup(final int amountOfRoomNeeded) {
if (amountOfRoomNeeded >= 0
&& UserPreferences.getEpisodeCacheSize() != UserPreferences.EPISODE_CACHE_SIZE_UNLIMITED) {
int downloadedEpisodes = DBReader
.getNumberOfDownloadedEpisodes();
int downloadedEpisodes = DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.DOWNLOADED));
if (downloadedEpisodes + amountOfRoomNeeded >= UserPreferences
.getEpisodeCacheSize()) {

View File

@ -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.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
@ -75,7 +76,8 @@ public class ExceptFavoriteCleanupAlgorithm extends EpisodeCleanupAlgorithm {
@NonNull
private List<FeedItem> getCandidates() {
List<FeedItem> candidates = new ArrayList<>();
List<FeedItem> downloadedItems = DBReader.getDownloadedItems(SortOrder.DATE_NEW_OLD);
List<FeedItem> downloadedItems = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.DOWNLOADED), SortOrder.DATE_NEW_OLD);
for (FeedItem item : downloadedItems) {
if (item.hasMedia()
&& item.getMedia().isDownloaded()
@ -90,7 +92,7 @@ public class ExceptFavoriteCleanupAlgorithm extends EpisodeCleanupAlgorithm {
public int getDefaultCleanupParameter() {
int cacheSize = UserPreferences.getEpisodeCacheSize();
if (cacheSize != UserPreferences.EPISODE_CACHE_SIZE_UNLIMITED) {
int downloadedEpisodes = DBReader.getNumberOfDownloadedEpisodes();
int downloadedEpisodes = DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.DOWNLOADED));
if (downloadedEpisodes > cacheSize) {
return downloadedEpisodes - cacheSize;
}

View File

@ -20,6 +20,8 @@ import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import de.danoeh.antennapod.model.feed.FeedItemFilter;
import de.danoeh.antennapod.model.feed.SortOrder;
import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest;
import de.danoeh.antennapod.core.service.download.DownloadService;
import de.danoeh.antennapod.core.service.download.DownloadRequestCreator;
@ -213,7 +215,8 @@ public class SyncService extends Worker {
List<EpisodeAction> queuedEpisodeActions = synchronizationQueueStorage.getQueuedEpisodeActions();
if (lastSync == 0) {
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_upload_played));
List<FeedItem> readItems = DBReader.getPlayedItems();
List<FeedItem> readItems = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.PLAYED), SortOrder.DATE_NEW_OLD);
Log.d(TAG, "First sync. Upload state for all " + readItems.size() + " played episodes");
for (FeedItem item : readItems) {
FeedMedia media = item.getMedia();

View File

@ -13,6 +13,7 @@ import androidx.test.platform.app.InstrumentationRegistry;
import de.danoeh.antennapod.model.feed.Feed;
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.SortOrder;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
@ -239,7 +240,8 @@ public class DbReaderTest {
public void testGetDownloadedItems() {
final int numItems = 10;
List<FeedItem> downloaded = saveDownloadedItems(numItems);
List<FeedItem> downloadedSaved = DBReader.getDownloadedItems(null);
List<FeedItem> downloadedSaved = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.DOWNLOADED), SortOrder.DATE_NEW_OLD);
assertNotNull(downloadedSaved);
assertEquals(downloaded.size(), downloadedSaved.size());
for (FeedItem item : downloadedSaved) {
@ -283,7 +285,8 @@ public class DbReaderTest {
for (int i = 0; i < newItems.size(); i++) {
unreadIds[i] = newItems.get(i).getId();
}
List<FeedItem> newItemsSaved = DBReader.getNewItemsList(0, Integer.MAX_VALUE, SortOrder.DATE_NEW_OLD);
List<FeedItem> newItemsSaved = DBReader.getEpisodes(0, Integer.MAX_VALUE,
new FeedItemFilter(FeedItemFilter.NEW), SortOrder.DATE_NEW_OLD);
assertNotNull(newItemsSaved);
assertEquals(newItemsSaved.size(), newItems.size());
for (FeedItem feedItem : newItemsSaved) {

View File

@ -45,8 +45,6 @@ import org.apache.commons.io.FileUtils;
import static de.danoeh.antennapod.model.feed.FeedPreferences.SPEED_USE_GLOBAL;
import static de.danoeh.antennapod.model.feed.SortOrder.toCodeString;
import de.danoeh.antennapod.storage.database.mapper.FeedItemSortQuery;
/**
* Implements methods for accessing the database
*/
@ -1049,24 +1047,7 @@ public class PodDBAdapter {
db.execSQL(sql);
}
/**
* Returns a cursor which contains all feed items that are considered new.
* Excludes those feeds that do not have 'Keep Updated' enabled.
* The returned cursor uses the FEEDITEM_SEL_FI_SMALL selection.
*/
public final Cursor getNewItemsCursor(int offset, int limit, SortOrder sortOrder) {
String sortQuery = FeedItemSortQuery.generateFrom(sortOrder);
final String query = SELECT_FEED_ITEMS_AND_MEDIA
+ " INNER JOIN " + TABLE_NAME_FEEDS
+ " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID
+ " WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.NEW
+ " AND " + TABLE_NAME_FEEDS + "." + KEY_KEEP_UPDATED + " > 0"
+ " ORDER BY " + sortQuery + " LIMIT " + offset + ", " + limit;
return db.rawQuery(query, null);
}
public final Cursor getRecentlyPublishedItemsCursor(int offset, int limit,
FeedItemFilter filter, SortOrder sortOrder) {
public final Cursor getEpisodesCursor(int offset, int limit, FeedItemFilter filter, SortOrder sortOrder) {
String orderByQuery = FeedItemSortQuery.generateFrom(sortOrder);
String filterQuery = FeedItemFilterQuery.generateFrom(filter);
String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery;
@ -1075,6 +1056,14 @@ public class PodDBAdapter {
return db.rawQuery(query, null);
}
public final Cursor getEpisodeCountCursor(FeedItemFilter filter) {
String filterQuery = FeedItemFilterQuery.generateFrom(filter);
String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery;
final String query = "SELECT count(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ") FROM " + TABLE_NAME_FEED_ITEMS
+ JOIN_FEED_ITEM_AND_MEDIA + whereClause;
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 + ") "
@ -1097,28 +1086,6 @@ public class PodDBAdapter {
return "((" + SELECT_KEY_ITEM_ID + " * " + seed + ") % 46471)";
}
public final Cursor getTotalEpisodeCountCursor(FeedItemFilter filter) {
String filterQuery = FeedItemFilterQuery.generateFrom(filter);
String whereClause = "".equals(filterQuery) ? "" : " WHERE " + filterQuery;
final String query = "SELECT count(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ") FROM " + TABLE_NAME_FEED_ITEMS
+ JOIN_FEED_ITEM_AND_MEDIA + whereClause;
return db.rawQuery(query, null);
}
public Cursor getDownloadedItemsCursor(SortOrder sortOrder) {
String sortQuery = FeedItemSortQuery.generateFrom(sortOrder);
final String query = SELECT_FEED_ITEMS_AND_MEDIA
+ " WHERE " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " > 0"
+ " ORDER BY " + sortQuery;
return db.rawQuery(query, null);
}
public Cursor getPlayedItemsCursor() {
final String query = SELECT_FEED_ITEMS_AND_MEDIA
+ "WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + "=" + FeedItem.PLAYED;
return db.rawQuery(query, null);
}
/**
* Returns a cursor which contains feed media objects with a playback
* completion date in ascending order.
@ -1267,25 +1234,6 @@ public class PodDBAdapter {
return result;
}
public final int getNumberOfNewItems() {
Object[] args = new String[]{
TABLE_NAME_FEED_ITEMS + "." + KEY_ID,
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"
};
final String query = String.format("SELECT COUNT(%s) FROM %s INNER JOIN %s ON %s WHERE %s", args);
Cursor c = db.rawQuery(query, null);
int result = 0;
if (c.moveToFirst()) {
result = c.getInt(0);
}
c.close();
return result;
}
public final Map<Long, Integer> getFeedCounters(FeedCounter setting, long... feedIds) {
String whereRead;
switch (setting) {
@ -1371,19 +1319,6 @@ public class PodDBAdapter {
return result;
}
public final int getNumberOfDownloadedEpisodes() {
final String query = "SELECT COUNT(DISTINCT " + KEY_ID + ") AS count FROM " + TABLE_NAME_FEED_MEDIA +
" WHERE " + KEY_DOWNLOADED + " > 0";
Cursor c = db.rawQuery(query, null);
int result = 0;
if (c.moveToFirst()) {
result = c.getInt(0);
}
c.close();
return result;
}
/**
* Uses DatabaseUtils to escape a search query and removes ' at the
* beginning and the end of the string returned by the escape method.