Search in sources :

Example 1 with SimpleChapter

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

the class DBReader method loadChaptersOfFeedItem.

static void loadChaptersOfFeedItem(PodDBAdapter adapter, FeedItem item) {
    Cursor chapterCursor = adapter.getSimpleChaptersOfFeedItemCursor(item);
    if (chapterCursor.moveToFirst()) {
        item.setChapters(new ArrayList<>());
        do {
            int indexType = chapterCursor.getColumnIndex(PodDBAdapter.KEY_CHAPTER_TYPE);
            int indexStart = chapterCursor.getColumnIndex(PodDBAdapter.KEY_START);
            int indexTitle = chapterCursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
            int indexLink = chapterCursor.getColumnIndex(PodDBAdapter.KEY_LINK);
            int chapterType = chapterCursor.getInt(indexType);
            Chapter chapter = null;
            long start = chapterCursor.getLong(indexStart);
            String title = chapterCursor.getString(indexTitle);
            String link = chapterCursor.getString(indexLink);
            switch(chapterType) {
                case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER:
                    chapter = new SimpleChapter(start, title, item, link);
                    break;
                case ID3Chapter.CHAPTERTYPE_ID3CHAPTER:
                    chapter = new ID3Chapter(start, title, item, link);
                    break;
                case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
                    chapter = new VorbisCommentChapter(start, title, item, link);
                    break;
            }
            if (chapter != null) {
                int indexId = chapterCursor.getColumnIndex(PodDBAdapter.KEY_ID);
                chapter.setId(chapterCursor.getLong(indexId));
                item.getChapters().add(chapter);
            }
        } while (chapterCursor.moveToNext());
    } else {
        item.setChapters(null);
    }
    chapterCursor.close();
}
Also used : SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter) ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter) Chapter(de.danoeh.antennapod.core.feed.Chapter) ID3Chapter(de.danoeh.antennapod.core.feed.ID3Chapter) Cursor(android.database.Cursor) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) VorbisCommentChapter(de.danoeh.antennapod.core.feed.VorbisCommentChapter)

Example 2 with SimpleChapter

use of de.danoeh.antennapod.core.feed.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, null, "link" + i, "descr", null, null, null, null, "id" + i, null, null, "url" + i, false, new FlattrStatus(), false, null, null, 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, item, "http://example.com"));
                }
            }
            f.getItems().add(item);
        }
        Collections.sort(f.getItems(), new FeedItemPubdateComparator());
        adapter.setCompleteFeed(f);
        Assert.assertTrue(f.getId() != 0);
        for (FeedItem item : f.getItems()) {
            Assert.assertTrue(item.getId() != 0);
        }
        feeds.add(f);
    }
    adapter.close();
    return feeds;
}
Also used : ArrayList(java.util.ArrayList) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) Chapter(de.danoeh.antennapod.core.feed.Chapter) Date(java.util.Date) FlattrStatus(de.danoeh.antennapod.core.util.flattr.FlattrStatus) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 3 with SimpleChapter

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

the class DBWriterTest method testDeleteFeed.

public void testDeleteFeed() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    // create Feed image
    File imgFile = new File(destFolder, "image");
    assertTrue(imgFile.createNewFile());
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);
    List<File> itemFiles = new ArrayList<File>();
    // create items with downloaded media files
    for (int i = 0; i < 10; i++) {
        FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed, true);
        feed.getItems().add(item);
        File enc = new File(destFolder, "file " + i);
        assertTrue(enc.createNewFile());
        itemFiles.add(enc);
        FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", true, null, 0, 0);
        item.setMedia(media);
        item.setChapters(new ArrayList<Chapter>());
        item.getChapters().add(new SimpleChapter(0, "item " + i, item, "example.com"));
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
        assertTrue(item.getChapters().get(0).getId() != 0);
    }
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    // check if files still exist
    assertFalse(imgFile.exists());
    for (File f : itemFiles) {
        assertFalse(f.exists());
    }
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertEquals(0, c.getCount());
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertEquals(0, c.getCount());
    c.close();
    for (FeedItem item : feed.getItems()) {
        c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
        assertEquals(0, c.getCount());
        c.close();
        c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
        assertEquals(0, c.getCount());
        c.close();
        c = adapter.getSimpleChaptersOfFeedItemCursor(item);
        assertEquals(0, c.getCount());
        c.close();
    }
    adapter.close();
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) ArrayList(java.util.ArrayList) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) Chapter(de.danoeh.antennapod.core.feed.Chapter) Cursor(android.database.Cursor) Date(java.util.Date) SimpleChapter(de.danoeh.antennapod.core.feed.SimpleChapter) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed)

Aggregations

Chapter (de.danoeh.antennapod.core.feed.Chapter)3 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)3 Cursor (android.database.Cursor)2 Feed (de.danoeh.antennapod.core.feed.Feed)2 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)2 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)2 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)1 ID3Chapter (de.danoeh.antennapod.core.feed.ID3Chapter)1 VorbisCommentChapter (de.danoeh.antennapod.core.feed.VorbisCommentChapter)1 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)1 FlattrStatus (de.danoeh.antennapod.core.util.flattr.FlattrStatus)1 File (java.io.File)1