Search in sources :

Example 11 with Chapter

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

the class PodDBAdapter method setChapters.

public void setChapters(FeedItem item) {
    ContentValues values = new ContentValues();
    for (Chapter chapter : item.getChapters()) {
        values.put(KEY_TITLE, chapter.getTitle());
        values.put(KEY_START, chapter.getStart());
        values.put(KEY_FEEDITEM, item.getId());
        values.put(KEY_LINK, chapter.getLink());
        values.put(KEY_CHAPTER_TYPE, chapter.getChapterType());
        if (chapter.getId() == 0) {
            chapter.setId(db.insert(TABLE_NAME_SIMPLECHAPTERS, null, values));
        } else {
            db.update(TABLE_NAME_SIMPLECHAPTERS, values, KEY_ID + "=?", new String[] { String.valueOf(chapter.getId()) });
        }
    }
}
Also used : ContentValues(android.content.ContentValues) Chapter(de.danoeh.antennapod.core.feed.Chapter)

Example 12 with Chapter

use of de.danoeh.antennapod.core.feed.Chapter 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)12 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)3 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)3 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)3 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)3 VorbisCommentChapterReader (de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)3 Cursor (android.database.Cursor)2 Feed (de.danoeh.antennapod.core.feed.Feed)2 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)2 VorbisCommentChapter (de.danoeh.antennapod.core.feed.VorbisCommentChapter)2 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)2 ChapterReader (de.danoeh.antennapod.core.util.id3reader.ChapterReader)2 ID3ReaderException (de.danoeh.antennapod.core.util.id3reader.ID3ReaderException)2 BufferedInputStream (java.io.BufferedInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2