Search in sources :

Example 1 with PlaybackCompletionDateComparator

use of de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator in project AntennaPod by AntennaPod.

the class DBReader method getPlaybackHistory.

/**
 * 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.
 *
 * @return The playback history. The FeedItems are sorted by their media's playbackCompletionDate in descending order.
 * The size of the returned list is limited by {@link #PLAYBACK_HISTORY_SIZE}.
 */
@NonNull
public static List<FeedItem> getPlaybackHistory() {
    Log.d(TAG, "getPlaybackHistory() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor mediaCursor = null;
    Cursor itemCursor = null;
    try {
        mediaCursor = adapter.getCompletedMediaCursor(PLAYBACK_HISTORY_SIZE);
        String[] itemIds = new String[mediaCursor.getCount()];
        for (int i = 0; i < itemIds.length && mediaCursor.moveToPosition(i); i++) {
            int index = mediaCursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM);
            itemIds[i] = Long.toString(mediaCursor.getLong(index));
        }
        itemCursor = adapter.getFeedItemCursor(itemIds);
        List<FeedItem> items = extractItemlistFromCursor(adapter, itemCursor);
        loadAdditionalFeedItemListData(items);
        Collections.sort(items, new PlaybackCompletionDateComparator());
        return items;
    } finally {
        if (mediaCursor != null) {
            mediaCursor.close();
        }
        if (itemCursor != null) {
            itemCursor.close();
        }
        adapter.close();
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) PlaybackCompletionDateComparator(de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator) Cursor(android.database.Cursor) NonNull(androidx.annotation.NonNull)

Aggregations

Cursor (android.database.Cursor)1 NonNull (androidx.annotation.NonNull)1 PlaybackCompletionDateComparator (de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1