Search in sources :

Example 36 with FeedItem

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

the class DbTasksTest method testUpdateFeedRemoveUnlistedItems.

@Test
public void testUpdateFeedRemoveUnlistedItems() {
    final Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < 10; i++) {
        feed.getItems().add(new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.PLAYED, feed));
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    // delete some items
    feed.getItems().subList(0, 2).clear();
    Feed newFeed = DBTasks.updateFeed(context, feed, true);
    // 10 - 2 = 8 items
    assertEquals(8, newFeed.getItems().size());
    Feed feedFromDB = DBReader.getFeed(newFeed.getId());
    // 10 - 2 = 8 items
    assertEquals(8, feedFromDB.getItems().size());
}
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 37 with FeedItem

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

the class DbTasksTest method testUpdateFeedUpdatedFeed.

@Test
public void testUpdateFeedUpdatedFeed() {
    final int numItemsOld = 10;
    final int numItemsNew = 10;
    final Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < numItemsOld; i++) {
        feed.getItems().add(new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.PLAYED, feed));
    }
    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);
    final long feedID = feed.getId();
    feed.setId(0);
    List<Long> itemIDs = new ArrayList<>();
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
        itemIDs.add(item.getId());
        item.setId(0);
    }
    for (int i = numItemsOld; i < numItemsNew + numItemsOld; i++) {
        feed.getItems().add(0, new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.UNPLAYED, feed));
    }
    final Feed newFeed = DBTasks.updateFeed(context, feed, false);
    assertNotSame(newFeed, feed);
    updatedFeedTest(newFeed, feedID, itemIDs, numItemsOld, numItemsNew);
    final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
    assertNotNull(feedFromDB);
    assertEquals(newFeed.getId(), feedFromDB.getId());
    updatedFeedTest(feedFromDB, feedID, itemIDs, numItemsOld, numItemsNew);
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 38 with FeedItem

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

the class DbTasksTest method testUpdateFeedSetDuplicate.

@Test
public void testUpdateFeedSetDuplicate() {
    final Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < 10; i++) {
        FeedItem item = new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.PLAYED, feed);
        FeedMedia media = new FeedMedia(item, "download url " + i, 123, "media/mp3");
        item.setMedia(media);
        feed.getItems().add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    // change the guid of the first item, but leave the download url the same
    FeedItem item = feed.getItemAtIndex(0);
    item.setItemIdentifier("id 0-duplicate");
    item.setTitle("item 0 duplicate");
    Feed newFeed = DBTasks.updateFeed(context, feed, false);
    // id 1-duplicate replaces because the stream url is the same
    assertEquals(10, newFeed.getItems().size());
    Feed feedFromDB = DBReader.getFeed(newFeed.getId());
    // id1-duplicate should override id 1
    assertEquals(10, feedFromDB.getItems().size());
    FeedItem updatedItem = feedFromDB.getItemAtIndex(9);
    assertEquals("item 0 duplicate", updatedItem.getTitle());
    // Should use the new ID for sync etc
    assertEquals("id 0-duplicate", updatedItem.getItemIdentifier());
}
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) Test(org.junit.Test)

Example 39 with FeedItem

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

the class DbTasksTest method updatedFeedTest.

@SuppressWarnings("SameParameterValue")
private void updatedFeedTest(final Feed newFeed, long feedID, List<Long> itemIDs, int numItemsOld, int numItemsNew) {
    assertEquals(feedID, newFeed.getId());
    assertEquals(numItemsNew + numItemsOld, newFeed.getItems().size());
    Collections.reverse(newFeed.getItems());
    Date lastDate = new Date(0);
    for (int i = 0; i < numItemsOld; i++) {
        FeedItem item = newFeed.getItems().get(i);
        assertSame(newFeed, item.getFeed());
        assertEquals((long) itemIDs.get(i), item.getId());
        assertTrue(item.isPlayed());
        assertTrue(item.getPubDate().getTime() >= lastDate.getTime());
        lastDate = item.getPubDate();
    }
    for (int i = numItemsOld; i < numItemsNew + numItemsOld; i++) {
        FeedItem item = newFeed.getItems().get(i);
        assertSame(newFeed, item.getFeed());
        assertTrue(item.getId() != 0);
        assertFalse(item.isPlayed());
        assertTrue(item.getPubDate().getTime() >= lastDate.getTime());
        lastDate = item.getPubDate();
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Date(java.util.Date)

Example 40 with FeedItem

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

the class DbWriterTest method testAddQueueItemSingleItem.

@Test
public void testAddQueueItemSingleItem() 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();
}
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)

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