Search in sources :

Example 61 with FeedItem

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

the class PlaybackTest method testSmartMarkAsPlayed_Pause_WontAffectItem.

@Test
public void testSmartMarkAsPlayed_Pause_WontAffectItem() throws Exception {
    setSmartMarkAsPlayedPreference(60);
    uiTestUtils.addLocalFeedData(true);
    activityTestRule.launchActivity(new Intent());
    setupPlaybackController();
    final int fiIdx = 0;
    final FeedItem feedItem = DBReader.getQueue().get(fiIdx);
    playFromQueue(fiIdx);
    // let playback run a bit then pause
    Awaitility.await().atMost(1000, MILLISECONDS).until(() -> PlayerStatus.PLAYING == controller.getStatus());
    pauseEpisode();
    Awaitility.await().atMost(1000, MILLISECONDS).until(() -> PlayerStatus.PAUSED == controller.getStatus());
    assertThat("Ensure even with smart mark as play, after pause, the item remains in the queue.", DBReader.getQueue(), hasItems(feedItem));
    assertThat("Ensure even with smart mark as play, after pause, the item played status remains false.", DBReader.getFeedItem(feedItem.getId()).isPlayed(), is(false));
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Intent(android.content.Intent) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 62 with FeedItem

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

the class PlaybackTest method testContinuousPlaybackOnMultipleEpisodes.

@Test
public void testContinuousPlaybackOnMultipleEpisodes() throws Exception {
    setContinuousPlaybackPreference(true);
    uiTestUtils.addLocalFeedData(true);
    activityTestRule.launchActivity(new Intent());
    List<FeedItem> queue = DBReader.getQueue();
    final FeedItem first = queue.get(0);
    final FeedItem second = queue.get(1);
    playFromQueue(0);
    Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> first.getMedia().getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
    Awaitility.await().atMost(6, TimeUnit.SECONDS).until(() -> second.getMedia().getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Intent(android.content.Intent) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 63 with FeedItem

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

the class PlaybackTest method replayEpisodeCheck.

/**
 * Check if an episode can be played twice without problems.
 */
protected void replayEpisodeCheck(boolean followQueue) throws Exception {
    setContinuousPlaybackPreference(followQueue);
    uiTestUtils.addLocalFeedData(true);
    DBWriter.clearQueue().get();
    activityTestRule.launchActivity(new Intent());
    final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(0, 10, FeedItemFilter.unfiltered());
    startLocalPlayback();
    FeedMedia media = episodes.get(0).getMedia();
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> media.getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
    Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> media.getId() != PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
    startLocalPlayback();
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(() -> media.getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Intent(android.content.Intent)

Example 64 with FeedItem

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

the class DbNullCleanupAlgorithmTest method testPerformAutoCleanupShouldNotDelete.

/**
 * A test with no items in the queue, but multiple items downloaded.
 * The null algorithm should never delete any items, even if they're played and not in the queue.
 */
@Test
public void testPerformAutoCleanupShouldNotDelete() throws IOException {
    final int numItems = EPISODE_CACHE_SIZE * 2;
    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    List<File> files = new ArrayList<>();
    for (int i = 0; i < numItems; i++) {
        FeedItem item = new FeedItem(0, "title", "id" + i, "link", new Date(), FeedItem.PLAYED, feed);
        File f = new File(destFolder, "file " + i);
        assertTrue(f.createNewFile());
        files.add(f);
        item.setMedia(new FeedMedia(0, item, 1, 0, 1L, "m", f.getAbsolutePath(), "url", true, new Date(numItems - i), 0, 0));
        items.add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    for (FeedItem item : items) {
        assertTrue(item.getId() != 0);
        // noinspection ConstantConditions
        assertTrue(item.getMedia().getId() != 0);
    }
    DBTasks.performAutoCleanup(context);
    for (int i = 0; i < files.size(); i++) {
        assertTrue(files.get(i).exists());
    }
}
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 65 with FeedItem

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

the class DbReaderTest method testGetNewItemIds.

@Test
public void testGetNewItemIds() {
    final int numItems = 10;
    List<FeedItem> newItems = saveNewItems(numItems);
    long[] unreadIds = new long[newItems.size()];
    for (int i = 0; i < newItems.size(); i++) {
        unreadIds[i] = newItems.get(i).getId();
    }
    List<FeedItem> newItemsSaved = DBReader.getNewItemsList(0, Integer.MAX_VALUE);
    assertNotNull(newItemsSaved);
    assertEquals(newItemsSaved.size(), newItems.size());
    for (FeedItem feedItem : newItemsSaved) {
        long savedId = feedItem.getId();
        boolean found = false;
        for (long id : unreadIds) {
            if (id == savedId) {
                found = true;
                break;
            }
        }
        assertTrue(found);
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) 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