Search in sources :

Example 6 with FeedItem

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

the class NSAtom method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (ENTRY.equals(localName)) {
        state.setCurrentItem(new FeedItem());
        state.getItems().add(state.getCurrentItem());
        state.getCurrentItem().setFeed(state.getFeed());
    } else if (localName.matches(isText)) {
        String type = attributes.getValue(TEXT_TYPE);
        return new AtomText(localName, this, type);
    } else if (LINK.equals(localName)) {
        String href = attributes.getValue(LINK_HREF);
        String rel = attributes.getValue(LINK_REL);
        SyndElement parent = state.getTagstack().peek();
        if (parent.getName().matches(isFeedItem)) {
            if (LINK_REL_ALTERNATE.equals(rel)) {
                state.getCurrentItem().setLink(href);
            } else if (LINK_REL_ENCLOSURE.equals(rel)) {
                String strSize = attributes.getValue(LINK_LENGTH);
                long size = 0;
                try {
                    if (strSize != null) {
                        size = Long.parseLong(strSize);
                    }
                } catch (NumberFormatException e) {
                    Log.d(TAG, "Length attribute could not be parsed.");
                }
                String type = attributes.getValue(LINK_TYPE);
                if (type == null) {
                    type = SyndTypeUtils.getMimeTypeFromUrl(href);
                }
                if (SyndTypeUtils.enclosureTypeValid(type)) {
                    FeedItem currItem = state.getCurrentItem();
                    if (currItem != null && !currItem.hasMedia()) {
                        currItem.setMedia(new FeedMedia(currItem, href, size, type));
                    }
                }
            } else if (LINK_REL_PAYMENT.equals(rel)) {
                state.getCurrentItem().setPaymentLink(href);
            }
        } else if (parent.getName().matches(isFeed)) {
            if (LINK_REL_ALTERNATE.equals(rel)) {
                String type = attributes.getValue(LINK_TYPE);
                /*
                     * Use as link if a) no type-attribute is given and
					 * feed-object has no link yet b) type of link is
					 * LINK_TYPE_HTML or LINK_TYPE_XHTML
					 */
                if (state.getFeed() != null && ((type == null && state.getFeed().getLink() == null) || (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)))) {
                    state.getFeed().setLink(href);
                } else if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
                    // treat as podlove alternate feed
                    String title = attributes.getValue(LINK_TITLE);
                    if (TextUtils.isEmpty(title)) {
                        title = href;
                    }
                    state.addAlternateFeedUrl(title, href);
                }
            } else if (LINK_REL_ARCHIVES.equals(rel) && state.getFeed() != null) {
                String type = attributes.getValue(LINK_TYPE);
                if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
                    String title = attributes.getValue(LINK_TITLE);
                    if (TextUtils.isEmpty(title)) {
                        title = href;
                    }
                    state.addAlternateFeedUrl(title, href);
                } else if (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)) {
                //A Link such as to a directory such as iTunes
                }
            } else if (LINK_REL_PAYMENT.equals(rel) && state.getFeed() != null) {
                state.getFeed().setPaymentLink(href);
            } else if (LINK_REL_NEXT.equals(rel) && state.getFeed() != null) {
                state.getFeed().setPaged(true);
                state.getFeed().setNextPageLink(href);
            }
        }
    }
    return new SyndElement(localName, this);
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SyndElement(de.danoeh.antennapod.core.syndication.namespace.SyndElement) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 7 with FeedItem

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

the class DBReader method loadTagsOfFeedItemList.

public static void loadTagsOfFeedItemList(List<FeedItem> items) {
    LongList favoriteIds = getFavoriteIDList();
    LongList queueIds = getQueueIDList();
    for (FeedItem item : items) {
        if (favoriteIds.contains(item.getId())) {
            item.addTag(FeedItem.TAG_FAVORITE);
        }
        if (queueIds.contains(item.getId())) {
            item.addTag(FeedItem.TAG_QUEUE);
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) LongList(de.danoeh.antennapod.core.util.LongList)

Example 8 with FeedItem

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

the class DBReader method getRecentlyPublishedEpisodes.

/**
     * Loads a list of FeedItems sorted by pubDate in descending order.
     *
     * @param limit   The maximum number of episodes that should be loaded.
     */
public static List<FeedItem> getRecentlyPublishedEpisodes(int limit) {
    Log.d(TAG, "getRecentlyPublishedEpisodes() called with: " + "limit = [" + limit + "]");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor itemlistCursor = adapter.getRecentlyPublishedItemsCursor(limit);
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    loadAdditionalFeedItemListData(items);
    adapter.close();
    return items;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

Example 9 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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}.
     */
public static List<FeedItem> getPlaybackHistory() {
    Log.d(TAG, "getPlaybackHistory() called");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor 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));
    }
    mediaCursor.close();
    Cursor itemCursor = adapter.getFeedItemCursor(itemIds);
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemCursor);
    loadAdditionalFeedItemListData(items);
    itemCursor.close();
    adapter.close();
    Collections.sort(items, new PlaybackCompletionDateComparator());
    return items;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) PlaybackCompletionDateComparator(de.danoeh.antennapod.core.util.comparator.PlaybackCompletionDateComparator) Cursor(android.database.Cursor)

Example 10 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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.
     */
public static List<FeedItem> getDownloadedItems() {
    Log.d(TAG, "getDownloadedItems() called with: " + "");
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor itemlistCursor = adapter.getDownloadedItemsCursor();
    List<FeedItem> items = extractItemlistFromCursor(adapter, itemlistCursor);
    itemlistCursor.close();
    loadAdditionalFeedItemListData(items);
    adapter.close();
    Collections.sort(items, new FeedItemPubdateComparator());
    return items;
}
Also used : FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor)

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