Search in sources :

Example 1 with SimpleChapter

use of de.danoeh.antennapod.parser.feed.element.SimpleChapter in project AntennaPod by AntennaPod.

the class ChapterCursorMapper method convert.

/**
 * Create a {@link Chapter} instance from a database row (cursor).
 */
@NonNull
public static Chapter convert(@NonNull Cursor cursor) {
    int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
    int indexTitle = cursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
    int indexStart = cursor.getColumnIndex(PodDBAdapter.KEY_START);
    int indexLink = cursor.getColumnIndex(PodDBAdapter.KEY_LINK);
    int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE_URL);
    int indexChapterType = cursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
    long id = cursor.getLong(indexId);
    String title = cursor.getString(indexTitle);
    long start = cursor.getLong(indexStart);
    String link = cursor.getString(indexLink);
    String imageUrl = cursor.getString(indexImage);
    int chapterType = cursor.getInt(indexChapterType);
    Chapter chapter;
    switch(chapterType) {
        case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
            chapter = new SimpleChapter(start, title, link, imageUrl);
            break;
        case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
            chapter = new ID3Chapter(start, title, link, imageUrl);
            break;
        case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
            chapter = new VorbisCommentChapter(start, title, link, imageUrl);
            break;
        default:
            throw new IllegalArgumentException("Unknown chapter type");
    }
    chapter.setId(id);
    return chapter;
}
Also used : SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) VorbisCommentChapter(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter) ID3Chapter(de.danoeh.antennapod.parser.media.id3.ID3Chapter) ID3Chapter(de.danoeh.antennapod.parser.media.id3.ID3Chapter) SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter) NonNull(androidx.annotation.NonNull)

Example 2 with SimpleChapter

use of de.danoeh.antennapod.parser.feed.element.SimpleChapter in project AntennaPod by AntennaPod.

the class DbTestUtils method saveFeedlist.

/**
 * Use this method when tests involve chapters.
 */
public static List<Feed> saveFeedlist(int numFeeds, int numItems, boolean withMedia, boolean withChapters, int numChapters) {
    if (numFeeds <= 0) {
        throw new IllegalArgumentException("numFeeds<=0");
    }
    if (numItems < 0) {
        throw new IllegalArgumentException("numItems<0");
    }
    List<Feed> feeds = new ArrayList<>();
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int i = 0; i < numFeeds; i++) {
        Feed f = new Feed(0, null, "feed " + i, "link" + i, "descr", null, null, null, null, "id" + i, null, null, "url" + i, false);
        f.setItems(new ArrayList<>());
        for (int j = 0; j < numItems; j++) {
            FeedItem item = new FeedItem(0, "item " + j, "id" + j, "link" + j, new Date(), FeedItem.PLAYED, f, withChapters);
            if (withMedia) {
                FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3");
                item.setMedia(media);
            }
            if (withChapters) {
                List<Chapter> chapters = new ArrayList<>();
                item.setChapters(chapters);
                for (int k = 0; k < numChapters; k++) {
                    chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k, "http://example.com", "http://example.com/image.png"));
                }
            }
            f.getItems().add(item);
        }
        Collections.sort(f.getItems(), new FeedItemPubdateComparator());
        adapter.setCompleteFeed(f);
        assertTrue(f.getId() != 0);
        for (FeedItem item : f.getItems()) {
            assertTrue(item.getId() != 0);
        }
        feeds.add(f);
    }
    adapter.close();
    return feeds;
}
Also used : ArrayList(java.util.ArrayList) SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) Date(java.util.Date) SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

Chapter (de.danoeh.antennapod.model.feed.Chapter)2 SimpleChapter (de.danoeh.antennapod.parser.feed.element.SimpleChapter)2 NonNull (androidx.annotation.NonNull)1 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)1 Feed (de.danoeh.antennapod.model.feed.Feed)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)1 ID3Chapter (de.danoeh.antennapod.parser.media.id3.ID3Chapter)1 VorbisCommentChapter (de.danoeh.antennapod.parser.media.vorbis.VorbisCommentChapter)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1