Search in sources :

Example 66 with NonNull

use of androidx.annotation.NonNull 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)

Example 67 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class DBReader method extractItemlistFromCursor.

@NonNull
private static List<FeedItem> extractItemlistFromCursor(PodDBAdapter adapter, Cursor cursor) {
    List<FeedItem> result = new ArrayList<>(cursor.getCount());
    if (cursor.moveToFirst()) {
        int indexMediaId = cursor.getColumnIndexOrThrow(PodDBAdapter.SELECT_KEY_MEDIA_ID);
        do {
            FeedItem item = FeedItemCursorMapper.convert(cursor);
            result.add(item);
            if (!cursor.isNull(indexMediaId)) {
                item.setMedia(FeedMediaCursorMapper.convert(cursor));
            }
        } while (cursor.moveToNext());
    }
    return result;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull)

Example 68 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class DBReader method getDownloadedItems.

/**
 * 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() {
    Log.d(TAG, "getDownloadedItems() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    try (Cursor cursor = adapter.getDownloadedItemsCursor()) {
        List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
        loadAdditionalFeedItemListData(items);
        Collections.sort(items, new FeedItemPubdateComparator());
        return items;
    } finally {
        adapter.close();
    }
}
Also used : FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Cursor(android.database.Cursor) NonNull(androidx.annotation.NonNull)

Example 69 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class DBReader method getQueue.

@NonNull
static List<FeedItem> getQueue(PodDBAdapter adapter) {
    Log.d(TAG, "getQueue()");
    try (Cursor cursor = adapter.getQueueCursor()) {
        List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
        loadAdditionalFeedItemListData(items);
        return items;
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Cursor(android.database.Cursor) NonNull(androidx.annotation.NonNull)

Example 70 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class DBReader method getNavDrawerData.

/**
 * Returns data necessary for displaying the navigation drawer. This includes
 * the list of subscriptions, the number of items in the queue and the number of unread
 * items.
 */
@NonNull
public static NavDrawerData getNavDrawerData() {
    Log.d(TAG, "getNavDrawerData() called with: " + "");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    final LongIntMap feedCounters = adapter.getFeedCounters();
    SubscriptionsFilter subscriptionsFilter = UserPreferences.getSubscriptionsFilter();
    List<Feed> feeds = subscriptionsFilter.filter(getFeedList(adapter), feedCounters);
    Comparator<Feed> comparator;
    int feedOrder = UserPreferences.getFeedOrder();
    if (feedOrder == UserPreferences.FEED_ORDER_COUNTER) {
        comparator = (lhs, rhs) -> {
            long counterLhs = feedCounters.get(lhs.getId());
            long counterRhs = feedCounters.get(rhs.getId());
            if (counterLhs > counterRhs) {
                // reverse natural order: podcast with most unplayed episodes first
                return -1;
            } else if (counterLhs == counterRhs) {
                return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
            } else {
                return 1;
            }
        };
    } else if (feedOrder == UserPreferences.FEED_ORDER_ALPHABETICAL) {
        comparator = (lhs, rhs) -> {
            String t1 = lhs.getTitle();
            String t2 = rhs.getTitle();
            if (t1 == null) {
                return 1;
            } else if (t2 == null) {
                return -1;
            } else {
                return t1.compareToIgnoreCase(t2);
            }
        };
    } else if (feedOrder == UserPreferences.FEED_ORDER_MOST_PLAYED) {
        final LongIntMap playedCounters = adapter.getPlayedEpisodesCounters();
        comparator = (lhs, rhs) -> {
            long counterLhs = playedCounters.get(lhs.getId());
            long counterRhs = playedCounters.get(rhs.getId());
            if (counterLhs > counterRhs) {
                // podcast with most played episodes first
                return -1;
            } else if (counterLhs == counterRhs) {
                return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
            } else {
                return 1;
            }
        };
    } else {
        final Map<Long, Long> recentPubDates = adapter.getMostRecentItemDates();
        comparator = (lhs, rhs) -> {
            long dateLhs = recentPubDates.containsKey(lhs.getId()) ? recentPubDates.get(lhs.getId()) : 0;
            long dateRhs = recentPubDates.containsKey(rhs.getId()) ? recentPubDates.get(rhs.getId()) : 0;
            return Long.compare(dateRhs, dateLhs);
        };
    }
    Collections.sort(feeds, comparator);
    int queueSize = adapter.getQueueSize();
    int numNewItems = adapter.getNumberOfNewItems();
    int numDownloadedItems = adapter.getNumberOfDownloadedEpisodes();
    List<NavDrawerData.DrawerItem> items = new ArrayList<>();
    Map<String, NavDrawerData.TagDrawerItem> folders = new HashMap<>();
    for (Feed feed : feeds) {
        for (String tag : feed.getPreferences().getTags()) {
            NavDrawerData.FeedDrawerItem drawerItem = new NavDrawerData.FeedDrawerItem(feed, feed.getId(), feedCounters.get(feed.getId()));
            if (FeedPreferences.TAG_ROOT.equals(tag)) {
                items.add(drawerItem);
                continue;
            }
            NavDrawerData.TagDrawerItem folder;
            if (folders.containsKey(tag)) {
                folder = folders.get(tag);
            } else {
                folder = new NavDrawerData.TagDrawerItem(tag);
                folders.put(tag, folder);
            }
            drawerItem.id |= folder.id;
            folder.children.add(drawerItem);
        }
    }
    List<NavDrawerData.TagDrawerItem> foldersSorted = new ArrayList<>(folders.values());
    Collections.sort(foldersSorted, (o1, o2) -> o1.getTitle().compareToIgnoreCase(o2.getTitle()));
    items.addAll(foldersSorted);
    NavDrawerData result = new NavDrawerData(items, queueSize, numNewItems, numDownloadedItems, feedCounters, UserPreferences.getEpisodeCleanupAlgorithm().getReclaimableItems());
    adapter.close();
    return result;
}
Also used : FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) NonNull(androidx.annotation.NonNull) DownloadStatusComparator(de.danoeh.antennapod.core.util.comparator.DownloadStatusComparator) HashMap(java.util.HashMap) LongList(de.danoeh.antennapod.core.util.LongList) FeedPreferencesCursorMapper(de.danoeh.antennapod.core.storage.mapper.FeedPreferencesCursorMapper) ArrayList(java.util.ArrayList) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) FeedItemCursorMapper(de.danoeh.antennapod.core.storage.mapper.FeedItemCursorMapper) FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) FeedItemFilter(de.danoeh.antennapod.model.feed.FeedItemFilter) Map(java.util.Map) Chapter(de.danoeh.antennapod.model.feed.Chapter) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Log(android.util.Log) Feed(de.danoeh.antennapod.model.feed.Feed) PlaybackCompletionDateComparator(de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator) Cursor(android.database.Cursor) ArrayMap(androidx.collection.ArrayMap) FeedMediaCursorMapper(de.danoeh.antennapod.core.storage.mapper.FeedMediaCursorMapper) LongIntMap(de.danoeh.antennapod.core.util.LongIntMap) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) TextUtils(android.text.TextUtils) File(java.io.File) SubscriptionsFilter(de.danoeh.antennapod.core.feed.SubscriptionsFilter) List(java.util.List) Nullable(androidx.annotation.Nullable) ChapterCursorMapper(de.danoeh.antennapod.core.storage.mapper.ChapterCursorMapper) FeedCursorMapper(de.danoeh.antennapod.core.storage.mapper.FeedCursorMapper) Comparator(java.util.Comparator) Collections(java.util.Collections) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LongIntMap(de.danoeh.antennapod.core.util.LongIntMap) SubscriptionsFilter(de.danoeh.antennapod.core.feed.SubscriptionsFilter) Feed(de.danoeh.antennapod.model.feed.Feed) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1197 View (android.view.View)191 ArrayList (java.util.ArrayList)154 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)117 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)76 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62