Search in sources :

Example 46 with FeedMedia

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

the class DBTasksTest method testUpdateFeedMediaUrlResetState.

public void testUpdateFeedMediaUrlResetState() {
    final Feed feed = new Feed("url", null, "title");
    FeedItem item = new FeedItem(0, "item", "id", "link", new Date(), FeedItem.PLAYED, feed);
    feed.setItems(Arrays.asList(item));
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    // ensure that objects have been saved in db, then reset
    assertTrue(feed.getId() != 0);
    assertTrue(item.getId() != 0);
    FeedMedia media = new FeedMedia(item, "url", 1024, "mime/type");
    item.setMedia(media);
    feed.setItems(Arrays.asList(item));
    final Feed newFeed = DBTasks.updateFeed(context, feed)[0];
    assertTrue(feed != newFeed);
    final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
    final FeedItem feedItemFromDB = feedFromDB.getItems().get(0);
    assertTrue("state: " + feedItemFromDB.getState(), feedItemFromDB.isNew());
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 47 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia 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)

Example 48 with FeedMedia

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

the class DBWriterTest method testSetFeedMediaPlaybackInformation.

public void testSetFeedMediaPlaybackInformation() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    final int POSITION = 50;
    final long LAST_PLAYED_TIME = 1000;
    final int PLAYED_DURATION = 60;
    final int DURATION = 100;
    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, feed);
    items.add(item);
    FeedMedia media = new FeedMedia(0, item, DURATION, 1, 1, "mime_type", "dummy path", "download_url", true, null, 0, 0);
    item.setMedia(media);
    DBWriter.setFeedItem(item).get(TIMEOUT, TimeUnit.SECONDS);
    media.setPosition(POSITION);
    media.setLastPlayedTime(LAST_PLAYED_TIME);
    media.setPlayedDuration(PLAYED_DURATION);
    DBWriter.setFeedMediaPlaybackInformation(item.getMedia()).get(TIMEOUT, TimeUnit.SECONDS);
    FeedItem itemFromDb = DBReader.getFeedItem(item.getId());
    FeedMedia mediaFromDb = itemFromDb.getMedia();
    assertEquals(POSITION, mediaFromDb.getPosition());
    assertEquals(LAST_PLAYED_TIME, mediaFromDb.getLastPlayedTime());
    assertEquals(PLAYED_DURATION, mediaFromDb.getPlayedDuration());
    assertEquals(DURATION, mediaFromDb.getDuration());
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 49 with FeedMedia

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

the class DBWriterTest method playbackHistorySetup.

private FeedMedia playbackHistorySetup(Date playbackCompletionDate) {
    final Context context = getInstrumentation().getTargetContext();
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<FeedItem>());
    FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
    FeedMedia media = new FeedMedia(0, item, 10, 0, 1, "mime", null, "url", false, playbackCompletionDate, 0, 0);
    feed.getItems().add(item);
    item.setMedia(media);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(media.getId() != 0);
    return media;
}
Also used : Context(android.content.Context) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 50 with FeedMedia

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

the class TimelineTest method newTestPlayable.

private Playable newTestPlayable(List<Chapter> chapters, String shownotes) {
    FeedItem item = new FeedItem(0, "Item", "item-id", "http://example.com/item", new Date(), FeedItem.PLAYED, null);
    item.setChapters(chapters);
    item.setContentEncoded(shownotes);
    FeedMedia media = new FeedMedia(item, "http://example.com/episode", 100, "audio/mp3");
    media.setDuration(Integer.MAX_VALUE);
    item.setMedia(media);
    return media;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date)

Aggregations

FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)53 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)39 Feed (de.danoeh.antennapod.core.feed.Feed)20 Date (java.util.Date)19 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)16 ArrayList (java.util.ArrayList)13 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)10 File (java.io.File)9 Intent (android.content.Intent)7 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Cursor (android.database.Cursor)6 SharedPreferences (android.content.SharedPreferences)4 TypedArray (android.content.res.TypedArray)3 Uri (android.net.Uri)3 View (android.view.View)3 Chapter (de.danoeh.antennapod.core.feed.Chapter)3 GpodnetEpisodeAction (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)3 Context (android.content.Context)2 ArrayMap (android.support.v4.util.ArrayMap)2 FlakyTest (android.test.FlakyTest)2