Search in sources :

Example 36 with FeedItem

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

the class NSRSS20 method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (ITEM.equals(localName)) {
        state.setCurrentItem(new FeedItem());
        state.getItems().add(state.getCurrentItem());
        state.getCurrentItem().setFeed(state.getFeed());
    } else if (ENCLOSURE.equals(localName)) {
        String type = attributes.getValue(ENC_TYPE);
        String url = attributes.getValue(ENC_URL);
        boolean validType = SyndTypeUtils.enclosureTypeValid(type);
        if (!validType) {
            type = SyndTypeUtils.getMimeTypeFromUrl(url);
            validType = SyndTypeUtils.enclosureTypeValid(type);
        }
        boolean validUrl = !TextUtils.isEmpty(url);
        if (state.getCurrentItem() != null && state.getCurrentItem().getMedia() == null && validType && validUrl) {
            long size = 0;
            try {
                size = Long.parseLong(attributes.getValue(ENC_LEN));
                if (size < 16384) {
                    // less than 16kb is suspicious, check manually
                    size = 0;
                }
            } catch (NumberFormatException e) {
                Log.d(TAG, "Length attribute could not be parsed.");
            }
            FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type);
            state.getCurrentItem().setMedia(media);
        }
    } else if (IMAGE.equals(localName)) {
        if (state.getTagstack().size() >= 1) {
            String parent = state.getTagstack().peek().getName();
            if (CHANNEL.equals(parent)) {
                Feed feed = state.getFeed();
                if (feed != null && feed.getImage() == null) {
                    feed.setImage(new FeedImage());
                    feed.getImage().setOwner(state.getFeed());
                }
            }
        }
    }
    return new SyndElement(localName, this);
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 37 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 38 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 39 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 40 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)

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