Search in sources :

Example 46 with FeedItem

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

the class DbWriterTest method testSetFeedMediaPlaybackInformation.

@Test
public void testSetFeedMediaPlaybackInformation() throws Exception {
    final int position = 50;
    final long lastPlayedTime = 1000;
    final int playedDuration = 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(lastPlayedTime);
    media.setPlayedDuration(playedDuration);
    DBWriter.setFeedMediaPlaybackInformation(item.getMedia()).get(TIMEOUT, TimeUnit.SECONDS);
    FeedItem itemFromDb = DBReader.getFeedItem(item.getId());
    FeedMedia mediaFromDb = itemFromDb.getMedia();
    assertEquals(position, mediaFromDb.getPosition());
    assertEquals(lastPlayedTime, mediaFromDb.getLastPlayedTime());
    assertEquals(playedDuration, mediaFromDb.getPlayedDuration());
    assertEquals(duration, mediaFromDb.getDuration());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 47 with FeedItem

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

the class DbWriterTest method testDeleteFeedMediaOfItemFileExists.

@Test
public void testDeleteFeedMediaOfItemFileExists() throws Exception {
    File dest = new File(context.getExternalFilesDir(TEST_FOLDER), "testFile");
    assertTrue(dest.createNewFile());
    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);
    FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", dest.getAbsolutePath(), "download_url", true, null, 0, 0);
    item.setMedia(media);
    items.add(item);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(media.getId() != 0);
    assertTrue(item.getId() != 0);
    DBWriter.deleteFeedMediaOfItem(context, media.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    media = DBReader.getFeedMedia(media.getId());
    assertNotNull(media);
    assertFalse(dest.exists());
    assertFalse(media.isDownloaded());
    assertNull(media.getFile_url());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 48 with FeedItem

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

the class DbWriterTest method testMarkAllItemsReadSameFeed.

@Test
public void testMarkAllItemsReadSameFeed() throws Exception {
    final int numItems = 10;
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < numItems; i++) {
        FeedItem item = new FeedItem(0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.UNPLAYED, feed);
        feed.getItems().add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
    }
    DBWriter.markAllItemsRead().get(TIMEOUT, TimeUnit.SECONDS);
    List<FeedItem> loadedItems = DBReader.getFeedItemList(feed);
    for (FeedItem item : loadedItems) {
        assertTrue(item.isPlayed());
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 49 with FeedItem

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

the class DbWriterTest method testAddQueueItemSingleItemAlreadyInQueue.

@Test
public void testAddQueueItemSingleItemAlreadyInQueue() throws Exception {
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
    feed.getItems().add(item);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(item.getId() != 0);
    DBWriter.addQueueItem(context, item).get(TIMEOUT, TimeUnit.SECONDS);
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor cursor = adapter.getQueueIDCursor();
    assertTrue(cursor.moveToFirst());
    assertEquals(item.getId(), cursor.getLong(0));
    cursor.close();
    adapter.close();
    DBWriter.addQueueItem(context, item).get(TIMEOUT, TimeUnit.SECONDS);
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    cursor = adapter.getQueueIDCursor();
    assertTrue(cursor.moveToFirst());
    assertEquals(item.getId(), cursor.getLong(0));
    assertEquals(1, cursor.getCount());
    cursor.close();
    adapter.close();
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Cursor(android.database.Cursor) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 50 with FeedItem

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

the class DbWriterTest method playbackHistorySetup.

private FeedMedia playbackHistorySetup(Date playbackCompletionDate) {
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    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 : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

FeedItem (de.danoeh.antennapod.model.feed.FeedItem)178 Feed (de.danoeh.antennapod.model.feed.Feed)74 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)48 Date (java.util.Date)47 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)46 File (java.io.File)26 Cursor (android.database.Cursor)20 NonNull (androidx.annotation.NonNull)15 Nullable (androidx.annotation.Nullable)11 Subscribe (org.greenrobot.eventbus.Subscribe)9 Intent (android.content.Intent)7 FeedFilter (de.danoeh.antennapod.model.feed.FeedFilter)7 View (android.view.View)6 LongList (de.danoeh.antennapod.core.util.LongList)6 SQLException (android.database.SQLException)5 Playable (de.danoeh.antennapod.model.playback.Playable)5 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)5 ExecutionException (java.util.concurrent.ExecutionException)5 FeedItemPubdateComparator (de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator)4