Search in sources :

Example 46 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class DBWriter method addQueueItemAt.

/**
     * Inserts a FeedItem in the queue at the specified index. The 'read'-attribute of the FeedItem will be set to
     * true. If the FeedItem is already in the queue, the queue will not be modified.
     *
     * @param context             A context that is used for opening a database connection.
     * @param itemId              ID of the FeedItem that should be added to the queue.
     * @param index               Destination index. Must be in range 0..queue.size()
     * @param performAutoDownload True if an auto-download process should be started after the operation
     * @throws IndexOutOfBoundsException if index < 0 || index >= queue.size()
     */
public static Future<?> addQueueItemAt(final Context context, final long itemId, final int index, final boolean performAutoDownload) {
    return dbExec.submit(() -> {
        final PodDBAdapter adapter = PodDBAdapter.getInstance();
        adapter.open();
        final List<FeedItem> queue = DBReader.getQueue(adapter);
        FeedItem item;
        if (queue != null) {
            if (!itemListContains(queue, itemId)) {
                item = DBReader.getFeedItem(itemId);
                if (item != null) {
                    queue.add(index, item);
                    adapter.setQueue(queue);
                    item.addTag(FeedItem.TAG_QUEUE);
                    EventBus.getDefault().post(QueueEvent.added(item, index));
                    EventBus.getDefault().post(FeedItemEvent.updated(item));
                    if (item.isNew()) {
                        DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
                    }
                }
            }
        }
        adapter.close();
        if (performAutoDownload) {
            DBTasks.autodownloadUndownloadedItems(context);
        }
    });
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Example 47 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class DBReader method getQueue.

static List<FeedItem> getQueue(PodDBAdapter adapter) {
    Log.d(TAG, "getQueue()");
    Cursor itemlistCursor = adapter.getQueueCursor();
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    loadAdditionalFeedItemListData(items);
    return items;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 48 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class DBReader method getFeedItem.

static FeedItem getFeedItem(final String podcastUrl, final String episodeUrl, PodDBAdapter adapter) {
    Log.d(TAG, "Loading feeditem with podcast url " + podcastUrl + " and episode url " + episodeUrl);
    FeedItem item = null;
    Cursor itemCursor = adapter.getFeedItemCursor(podcastUrl, episodeUrl);
    if (itemCursor.moveToFirst()) {
        List<FeedItem> list = extractItemlistFromCursor(adapter, itemCursor);
        if (list.size() > 0) {
            item = list.get(0);
            loadAdditionalFeedItemListData(list);
            if (item.hasChapters()) {
                loadChaptersOfFeedItem(adapter, item);
            }
        }
    }
    itemCursor.close();
    return item;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 49 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class DBReader method extractItemlistFromCursor.

private static List<FeedItem> extractItemlistFromCursor(PodDBAdapter adapter, Cursor cursor) {
    List<FeedItem> result = new ArrayList<>(cursor.getCount());
    LongList imageIds = new LongList(cursor.getCount());
    LongList itemIds = new LongList(cursor.getCount());
    if (cursor.moveToFirst()) {
        do {
            int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE);
            long imageId = cursor.getLong(indexImage);
            imageIds.add(imageId);
            FeedItem item = FeedItem.fromCursor(cursor);
            result.add(item);
            itemIds.add(item.getId());
        } while (cursor.moveToNext());
        Map<Long, FeedImage> images = getFeedImages(adapter, imageIds.toArray());
        Map<Long, FeedMedia> medias = getFeedMedia(adapter, itemIds.toArray());
        for (int i = 0; i < result.size(); i++) {
            FeedItem item = result.get(i);
            long imageId = imageIds.get(i);
            FeedImage image = images.get(imageId);
            item.setImage(image);
            FeedMedia media = medias.get(item.getId());
            item.setMedia(media);
            if (media != null) {
                media.setItem(item);
            }
        }
    }
    return result;
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) LongList(de.danoeh.antennapod.core.util.LongList)

Example 50 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem in project AntennaPod by AntennaPod.

the class DBReader method getFeedItem.

/**
     * Loads a specific FeedItem from the database. This method should not be used for loading more
     * than one FeedItem because this method might query the database several times for each item.
     *
     * @param itemId  The ID of the FeedItem
     * @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
     * as well as chapter marks of the FeedItem will also be loaded from the database.
     */
public static FeedItem getFeedItem(final long itemId) {
    Log.d(TAG, "getFeedItem() called with: " + "itemId = [" + itemId + "]");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    FeedItem item = getFeedItem(itemId, adapter);
    adapter.close();
    return item;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4