Search in sources :

Example 1 with DownloadStatusComparator

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

the class DBReader method getDownloadLog.

/**
     * Loads the download log from the database.
     *
     * @return A list with DownloadStatus objects that represent the download log.
     * The size of the returned list is limited by {@link #DOWNLOAD_LOG_SIZE}.
     */
public static List<DownloadStatus> getDownloadLog() {
    Log.d(TAG, "getDownloadLog() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor logCursor = adapter.getDownloadLogCursor(DOWNLOAD_LOG_SIZE);
    List<DownloadStatus> downloadLog = new ArrayList<>(logCursor.getCount());
    if (logCursor.moveToFirst()) {
        do {
            DownloadStatus status = DownloadStatus.fromCursor(logCursor);
            downloadLog.add(status);
        } while (logCursor.moveToNext());
    }
    logCursor.close();
    adapter.close();
    Collections.sort(downloadLog, new DownloadStatusComparator());
    return downloadLog;
}
Also used : DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) DownloadStatusComparator(de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator)

Example 2 with DownloadStatusComparator

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

the class DBReader method getFeedDownloadLog.

/**
     * Loads the download log for a particular feed from the database.
     *
     * @param feed Feed for which the download log is loaded
     * @return A list with DownloadStatus objects that represent the feed's download log,
     *         newest events first.
     */
public static List<DownloadStatus> getFeedDownloadLog(Feed feed) {
    Log.d(TAG, "getFeedDownloadLog() called with: " + "feed = [" + feed + "]");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor cursor = adapter.getDownloadLog(Feed.FEEDFILETYPE_FEED, feed.getId());
    List<DownloadStatus> downloadLog = new ArrayList<>(cursor.getCount());
    if (cursor.moveToFirst()) {
        do {
            DownloadStatus status = DownloadStatus.fromCursor(cursor);
            downloadLog.add(status);
        } while (cursor.moveToNext());
    }
    cursor.close();
    adapter.close();
    Collections.sort(downloadLog, new DownloadStatusComparator());
    return downloadLog;
}
Also used : DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) DownloadStatusComparator(de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator)

Aggregations

Cursor (android.database.Cursor)2 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)2 DownloadStatusComparator (de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator)2 ArrayList (java.util.ArrayList)2