Search in sources :

Example 66 with FeedItem

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

the class DbReaderTest method testGetNavDrawerDataQueueNotEmptyWithUnreadItems.

@Test
public void testGetNavDrawerDataQueueNotEmptyWithUnreadItems() {
    final int numFeeds = 10;
    final int numItems = 10;
    final int numQueue = 1;
    final int numNew = 2;
    List<Feed> feeds = DbTestUtils.saveFeedlist(numFeeds, numItems, true);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int i = 0; i < numNew; i++) {
        FeedItem item = feeds.get(0).getItems().get(i);
        item.setNew();
        adapter.setSingleFeedItem(item);
    }
    List<FeedItem> queue = new ArrayList<>();
    for (int i = 0; i < numQueue; i++) {
        FeedItem item = feeds.get(1).getItems().get(i);
        queue.add(item);
    }
    adapter.setQueue(queue);
    adapter.close();
    NavDrawerData navDrawerData = DBReader.getNavDrawerData();
    assertEquals(numFeeds, navDrawerData.items.size());
    assertEquals(numNew, navDrawerData.numNewItems);
    assertEquals(numQueue, navDrawerData.queueSize);
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 67 with FeedItem

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

the class DbReaderTest method testGetPlaybackHistory.

@Test
public void testGetPlaybackHistory() {
    final int numItems = (DBReader.PLAYBACK_HISTORY_SIZE + 1) * 2;
    final int playedItems = DBReader.PLAYBACK_HISTORY_SIZE + 1;
    final int numReturnedItems = Math.min(playedItems, DBReader.PLAYBACK_HISTORY_SIZE);
    final int numFeeds = 1;
    Feed feed = DbTestUtils.saveFeedlist(numFeeds, numItems, true).get(0);
    long[] ids = new long[playedItems];
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int i = 0; i < playedItems; i++) {
        FeedMedia m = feed.getItems().get(i).getMedia();
        m.setPlaybackCompletionDate(new Date(i + 1));
        adapter.setFeedMediaPlaybackCompletionDate(m);
        ids[ids.length - 1 - i] = m.getItem().getId();
    }
    adapter.close();
    List<FeedItem> saved = DBReader.getPlaybackHistory();
    assertNotNull(saved);
    assertEquals("Wrong size: ", numReturnedItems, saved.size());
    for (int i = 0; i < numReturnedItems; i++) {
        FeedItem item = saved.get(i);
        assertNotNull(item.getMedia().getPlaybackCompletionDate());
        assertEquals("Wrong sort order: ", item.getId(), ids[i]);
    }
}
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 68 with FeedItem

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

the class DbReaderTest method testGetDownloadedItems.

@Test
public void testGetDownloadedItems() {
    final int numItems = 10;
    List<FeedItem> downloaded = saveDownloadedItems(numItems);
    List<FeedItem> downloadedSaved = DBReader.getDownloadedItems();
    assertNotNull(downloadedSaved);
    assertEquals(downloaded.size(), downloadedSaved.size());
    for (FeedItem item : downloadedSaved) {
        assertNotNull(item.getMedia());
        assertTrue(item.getMedia().isDownloaded());
        assertNotNull(item.getMedia().getDownload_url());
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Test(org.junit.Test)

Example 69 with FeedItem

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

the class DbReaderTest method saveNewItems.

@SuppressWarnings("SameParameterValue")
private List<FeedItem> saveNewItems(int numItems) {
    List<Feed> feeds = saveFeedlist(numItems, numItems, true);
    List<FeedItem> items = new ArrayList<>();
    for (Feed f : feeds) {
        items.addAll(f.getItems());
    }
    List<FeedItem> newItems = new ArrayList<>();
    Random random = new Random();
    while (newItems.size() < numItems) {
        int i = random.nextInt(numItems);
        if (!newItems.contains(items.get(i))) {
            FeedItem item = items.get(i);
            item.setNew();
            newItems.add(item);
        }
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.storeFeedItemlist(newItems);
    adapter.close();
    return newItems;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Random(java.util.Random) ArrayList(java.util.ArrayList) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 70 with FeedItem

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

the class DbReaderTest method testLoadChaptersOfFeedItemWithChapters.

@Test
public void testLoadChaptersOfFeedItemWithChapters() {
    final int numChapters = 3;
    DbTestUtils.saveFeedlist(1, 3, false, false, 0);
    List<Feed> feeds = saveFeedlist(1, 3, false, true, numChapters);
    for (Feed feed : feeds) {
        for (FeedItem item : feed.getItems()) {
            assertTrue(item.hasChapters());
            item.setChapters(DBReader.loadChaptersOfFeedItem(item));
            assertTrue(item.hasChapters());
            assertNotNull(item.getChapters());
            assertEquals(numChapters, item.getChapters().size());
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) 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