Search in sources :

Example 86 with FeedItem

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

the class CastUtils method matches.

/**
     * Compares a {@link MediaInfo} instance with a {@link FeedMedia} one and evaluates whether they
     * represent the same podcast episode.
     *
     * @param info      the {@link MediaInfo} object to be compared.
     * @param media     the {@link FeedMedia} object to be compared.
     * @return <true>true</true> if there's a match, <code>false</code> otherwise.
     *
     * @see RemoteMedia#equals(Object)
     */
public static boolean matches(MediaInfo info, FeedMedia media) {
    if (info == null || media == null) {
        return false;
    }
    if (!TextUtils.equals(info.getContentId(), media.getStreamUrl())) {
        return false;
    }
    MediaMetadata metadata = info.getMetadata();
    FeedItem fi = media.getItem();
    if (fi == null || metadata == null || !TextUtils.equals(metadata.getString(KEY_EPISODE_IDENTIFIER), fi.getItemIdentifier())) {
        return false;
    }
    Feed feed = fi.getFeed();
    return feed != null && TextUtils.equals(metadata.getString(KEY_FEED_URL), feed.getDownload_url());
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) MediaMetadata(com.google.android.gms.cast.MediaMetadata) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 87 with FeedItem

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

the class NSDublinCore method handleElementEnd.

@Override
public void handleElementEnd(String localName, HandlerState state) {
    if (state.getCurrentItem() != null && state.getContentBuf() != null && state.getTagstack() != null && state.getTagstack().size() >= 2) {
        FeedItem currentItem = state.getCurrentItem();
        String top = state.getTagstack().peek().getName();
        String second = state.getSecondTag().getName();
        if (DATE.equals(top) && ITEM.equals(second)) {
            String content = state.getContentBuf().toString();
            currentItem.setPubDate(DateUtils.parse(content));
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Example 88 with FeedItem

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

the class NSRSS20 method handleElementEnd.

@Override
public void handleElementEnd(String localName, HandlerState state) {
    if (ITEM.equals(localName)) {
        if (state.getCurrentItem() != null) {
            FeedItem currentItem = state.getCurrentItem();
            // title if the item has no title-tag.
            if (currentItem.getTitle() == null) {
                currentItem.setTitle(currentItem.getDescription());
            }
            if (state.getTempObjects().containsKey(NSITunes.DURATION)) {
                if (currentItem.hasMedia()) {
                    Integer duration = (Integer) state.getTempObjects().get(NSITunes.DURATION);
                    currentItem.getMedia().setDuration(duration);
                }
                state.getTempObjects().remove(NSITunes.DURATION);
            }
        }
        state.setCurrentItem(null);
    } else if (state.getTagstack().size() >= 2 && state.getContentBuf() != null) {
        String content = state.getContentBuf().toString();
        SyndElement topElement = state.getTagstack().peek();
        String top = topElement.getName();
        SyndElement secondElement = state.getSecondTag();
        String second = secondElement.getName();
        String third = null;
        if (state.getTagstack().size() >= 3) {
            third = state.getThirdTag().getName();
        }
        if (GUID.equals(top) && ITEM.equals(second)) {
            // some feed creators include an empty or non-standard guid-element in their feed, which should be ignored
            if (!TextUtils.isEmpty(content) && state.getCurrentItem() != null) {
                state.getCurrentItem().setItemIdentifier(content);
            }
        } else if (TITLE.equals(top)) {
            String title = content.trim();
            if (ITEM.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setTitle(title);
            } else if (CHANNEL.equals(second) && state.getFeed() != null) {
                state.getFeed().setTitle(title);
            } else if (IMAGE.equals(second) && CHANNEL.equals(third)) {
                if (state.getFeed() != null && state.getFeed().getImage() != null && state.getFeed().getImage().getTitle() == null) {
                    state.getFeed().getImage().setTitle(title);
                }
            }
        } else if (LINK.equals(top)) {
            if (CHANNEL.equals(second) && state.getFeed() != null) {
                state.getFeed().setLink(content);
            } else if (ITEM.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setLink(content);
            }
        } else if (PUBDATE.equals(top) && ITEM.equals(second) && state.getCurrentItem() != null) {
            state.getCurrentItem().setPubDate(DateUtils.parse(content));
        } else if (URL.equals(top) && IMAGE.equals(second) && CHANNEL.equals(third)) {
            // prefer itunes:image
            if (state.getFeed() != null && state.getFeed().getImage() != null && state.getFeed().getImage().getDownload_url() == null) {
                state.getFeed().getImage().setDownload_url(content);
            }
        } else if (DESCR.equals(localName)) {
            if (CHANNEL.equals(second) && state.getFeed() != null) {
                state.getFeed().setDescription(content);
            } else if (ITEM.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setDescription(content);
            }
        } else if (LANGUAGE.equals(localName) && state.getFeed() != null) {
            state.getFeed().setLanguage(content.toLowerCase());
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem)

Example 89 with FeedItem

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

the class NSAtom method handleElementEnd.

@Override
public void handleElementEnd(String localName, HandlerState state) {
    if (ENTRY.equals(localName)) {
        if (state.getCurrentItem() != null && state.getTempObjects().containsKey(NSITunes.DURATION)) {
            FeedItem currentItem = state.getCurrentItem();
            if (currentItem.hasMedia()) {
                Integer duration = (Integer) state.getTempObjects().get(NSITunes.DURATION);
                currentItem.getMedia().setDuration(duration);
            }
            state.getTempObjects().remove(NSITunes.DURATION);
        }
        state.setCurrentItem(null);
    }
    if (state.getTagstack().size() >= 2) {
        AtomText textElement = null;
        String content;
        if (state.getContentBuf() != null) {
            content = state.getContentBuf().toString();
        } else {
            content = "";
        }
        SyndElement topElement = state.getTagstack().peek();
        String top = topElement.getName();
        SyndElement secondElement = state.getSecondTag();
        String second = secondElement.getName();
        if (top.matches(isText)) {
            textElement = (AtomText) topElement;
            textElement.setContent(content);
        }
        if (ID.equals(top)) {
            if (FEED.equals(second) && state.getFeed() != null) {
                state.getFeed().setFeedIdentifier(content);
            } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setItemIdentifier(content);
            }
        } else if (TITLE.equals(top) && textElement != null) {
            if (FEED.equals(second) && state.getFeed() != null) {
                state.getFeed().setTitle(textElement.getProcessedContent());
            } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setTitle(textElement.getProcessedContent());
            }
        } else if (SUBTITLE.equals(top) && FEED.equals(second) && textElement != null && state.getFeed() != null) {
            state.getFeed().setDescription(textElement.getProcessedContent());
        } else if (CONTENT.equals(top) && ENTRY.equals(second) && textElement != null && state.getCurrentItem() != null) {
            state.getCurrentItem().setDescription(textElement.getProcessedContent());
        } else if (SUMMARY.equals(top) && ENTRY.equals(second) && textElement != null && state.getCurrentItem() != null && state.getCurrentItem().getDescription() == null) {
            state.getCurrentItem().setDescription(textElement.getProcessedContent());
        } else if (UPDATED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null && state.getCurrentItem().getPubDate() == null) {
            state.getCurrentItem().setPubDate(DateUtils.parse(content));
        } else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
            state.getCurrentItem().setPubDate(DateUtils.parse(content));
        } else if (IMAGE_LOGO.equals(top) && state.getFeed() != null && state.getFeed().getImage() == null) {
            state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
        } else if (IMAGE_ICON.equals(top) && state.getFeed() != null) {
            state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
        } else if (AUTHOR_NAME.equals(top) && AUTHOR.equals(second) && state.getFeed() != null && state.getCurrentItem() == null) {
            String currentName = state.getFeed().getAuthor();
            if (currentName == null) {
                state.getFeed().setAuthor(content);
            } else {
                state.getFeed().setAuthor(currentName + ", " + content);
            }
        }
    }
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SyndElement(de.danoeh.antennapod.core.syndication.namespace.SyndElement)

Example 90 with FeedItem

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

the class PodDBAdapter method setFavorites.

public void setFavorites(List<FeedItem> favorites) {
    ContentValues values = new ContentValues();
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            db.beginTransactionNonExclusive();
        } else {
            db.beginTransaction();
        }
        db.delete(TABLE_NAME_FAVORITES, null, null);
        for (int i = 0; i < favorites.size(); i++) {
            FeedItem item = favorites.get(i);
            values.put(KEY_ID, i);
            values.put(KEY_FEEDITEM, item.getId());
            values.put(KEY_FEED, item.getFeed().getId());
            db.insertWithOnConflict(TABLE_NAME_FAVORITES, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        }
        db.setTransactionSuccessful();
    } catch (SQLException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    } finally {
        db.endTransaction();
    }
}
Also used : ContentValues(android.content.ContentValues) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SQLException(android.database.SQLException)

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