Search in sources :

Example 1 with FeedFunding

use of de.danoeh.antennapod.model.feed.FeedFunding in project AntennaPod by AntennaPod.

the class FeedInfoFragment method showFeed.

private void showFeed() {
    Log.d(TAG, "Language is " + feed.getLanguage());
    Log.d(TAG, "Author is " + feed.getAuthor());
    Log.d(TAG, "URL is " + feed.getDownload_url());
    Glide.with(getContext()).load(feed.getImageUrl()).apply(new RequestOptions().placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate()).into(imgvCover);
    Glide.with(getContext()).load(feed.getImageUrl()).apply(new RequestOptions().placeholder(R.color.image_readability_tint).error(R.color.image_readability_tint).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).transform(new FastBlurTransformation()).dontAnimate()).into(imgvBackground);
    txtvTitle.setText(feed.getTitle());
    txtvTitle.setMaxLines(6);
    String description = HtmlToPlainText.getPlainText(feed.getDescription());
    txtvDescription.setText(description);
    if (!TextUtils.isEmpty(feed.getAuthor())) {
        txtvAuthorHeader.setText(feed.getAuthor());
    }
    txtvUrl.setText(feed.getDownload_url() + " {fa-paperclip}");
    if (feed.getPaymentLinks() == null || feed.getPaymentLinks().size() == 0) {
        lblSupport.setVisibility(View.GONE);
        txtvFundingUrl.setVisibility(View.GONE);
    } else {
        lblSupport.setVisibility(View.VISIBLE);
        ArrayList<FeedFunding> fundingList = feed.getPaymentLinks();
        StringBuilder str = new StringBuilder();
        HashSet<String> seen = new HashSet<String>();
        for (FeedFunding funding : fundingList) {
            if (seen.contains(funding.url)) {
                continue;
            }
            seen.add(funding.url);
            str.append(funding.content.isEmpty() ? getContext().getResources().getString(R.string.support_podcast) : funding.content).append(" ").append(funding.url);
            str.append("\n");
        }
        str = new StringBuilder(StringUtils.trim(str.toString()));
        txtvFundingUrl.setText(str.toString());
    }
    Iconify.addIcons(txtvUrl);
    refreshToolbarState();
}
Also used : FastBlurTransformation(de.danoeh.antennapod.core.glide.FastBlurTransformation) RequestOptions(com.bumptech.glide.request.RequestOptions) FeedFunding(de.danoeh.antennapod.model.feed.FeedFunding) HashSet(java.util.HashSet)

Example 2 with FeedFunding

use of de.danoeh.antennapod.model.feed.FeedFunding in project AntennaPod by AntennaPod.

the class Atom 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 (rel == null || 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);
                }
                FeedItem currItem = state.getCurrentItem();
                if (SyndTypeUtils.enclosureTypeValid(type) && 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 (rel == null || 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().addPayment(new FeedFunding(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.model.feed.FeedItem) SyndElement(de.danoeh.antennapod.parser.feed.element.SyndElement) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) AtomText(de.danoeh.antennapod.parser.feed.element.AtomText) FeedFunding(de.danoeh.antennapod.model.feed.FeedFunding)

Example 3 with FeedFunding

use of de.danoeh.antennapod.model.feed.FeedFunding in project AntennaPod by AntennaPod.

the class PodcastIndex method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (FUNDING.equals(localName)) {
        String href = attributes.getValue(URL);
        FeedFunding funding = new FeedFunding(href, "");
        state.setCurrentFunding(funding);
        state.getFeed().addPayment(state.getCurrentFunding());
    }
    return new SyndElement(localName, this);
}
Also used : SyndElement(de.danoeh.antennapod.parser.feed.element.SyndElement) FeedFunding(de.danoeh.antennapod.model.feed.FeedFunding)

Example 4 with FeedFunding

use of de.danoeh.antennapod.model.feed.FeedFunding in project AntennaPod by AntennaPod.

the class Rss2Generator method writeFeed.

@Override
public void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException {
    if (feed == null) {
        throw new IllegalArgumentException("feed = null");
    } else if (outputStream == null) {
        throw new IllegalArgumentException("outputStream = null");
    } else if (encoding == null) {
        throw new IllegalArgumentException("encoding = null");
    }
    XmlSerializer xml = Xml.newSerializer();
    xml.setOutput(outputStream, encoding);
    xml.startDocument(encoding, null);
    xml.setPrefix("atom", "http://www.w3.org/2005/Atom");
    xml.startTag(null, "rss");
    xml.attribute(null, "version", "2.0");
    xml.startTag(null, "channel");
    // Write Feed data
    if (feed.getTitle() != null) {
        xml.startTag(null, "title");
        xml.text(feed.getTitle());
        xml.endTag(null, "title");
    }
    if (feed.getDescription() != null) {
        xml.startTag(null, "description");
        xml.text(feed.getDescription());
        xml.endTag(null, "description");
    }
    if (feed.getLink() != null) {
        xml.startTag(null, "link");
        xml.text(feed.getLink());
        xml.endTag(null, "link");
    }
    if (feed.getLanguage() != null) {
        xml.startTag(null, "language");
        xml.text(feed.getLanguage());
        xml.endTag(null, "language");
    }
    if (feed.getImageUrl() != null) {
        xml.startTag(null, "image");
        xml.startTag(null, "url");
        xml.text(feed.getImageUrl());
        xml.endTag(null, "url");
        xml.endTag(null, "image");
    }
    ArrayList<FeedFunding> fundingList = feed.getPaymentLinks();
    if (fundingList != null) {
        for (FeedFunding funding : fundingList) {
            GeneratorUtil.addPaymentLink(xml, funding.url, true);
        }
    }
    // Write FeedItem data
    if (feed.getItems() != null) {
        for (FeedItem item : feed.getItems()) {
            xml.startTag(null, "item");
            if (item.getTitle() != null) {
                xml.startTag(null, "title");
                xml.text(item.getTitle());
                xml.endTag(null, "title");
            }
            if (item.getDescription() != null) {
                xml.startTag(null, "description");
                xml.text(item.getDescription());
                xml.endTag(null, "description");
            }
            if (item.getLink() != null) {
                xml.startTag(null, "link");
                xml.text(item.getLink());
                xml.endTag(null, "link");
            }
            if (item.getPubDate() != null) {
                xml.startTag(null, "pubDate");
                xml.text(DateFormatter.formatRfc822Date(item.getPubDate()));
                xml.endTag(null, "pubDate");
            }
            if ((flags & FEATURE_WRITE_GUID) != 0) {
                xml.startTag(null, "guid");
                xml.text(item.getItemIdentifier());
                xml.endTag(null, "guid");
            }
            if (item.getMedia() != null) {
                xml.startTag(null, "enclosure");
                xml.attribute(null, "url", item.getMedia().getDownload_url());
                xml.attribute(null, "length", String.valueOf(item.getMedia().getSize()));
                xml.attribute(null, "type", item.getMedia().getMime_type());
                xml.endTag(null, "enclosure");
            }
            if (fundingList != null) {
                for (FeedFunding funding : fundingList) {
                    xml.startTag(PodcastIndex.NSTAG, "funding");
                    xml.attribute(PodcastIndex.NSTAG, "url", funding.url);
                    xml.text(funding.content);
                    GeneratorUtil.addPaymentLink(xml, funding.url, true);
                    xml.endTag(PodcastIndex.NSTAG, "funding");
                }
            }
            xml.endTag(null, "item");
        }
    }
    writeAdditionalAttributes(xml);
    xml.endTag(null, "channel");
    xml.endTag(null, "rss");
    xml.endDocument();
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) XmlSerializer(org.xmlpull.v1.XmlSerializer) FeedFunding(de.danoeh.antennapod.model.feed.FeedFunding)

Aggregations

FeedFunding (de.danoeh.antennapod.model.feed.FeedFunding)4 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)2 SyndElement (de.danoeh.antennapod.parser.feed.element.SyndElement)2 RequestOptions (com.bumptech.glide.request.RequestOptions)1 FastBlurTransformation (de.danoeh.antennapod.core.glide.FastBlurTransformation)1 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)1 AtomText (de.danoeh.antennapod.parser.feed.element.AtomText)1 HashSet (java.util.HashSet)1 XmlSerializer (org.xmlpull.v1.XmlSerializer)1