Search in sources :

Example 31 with FeedMedia

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

the class PlaybackTest method playFromQueue.

/**
 * @param itemIdx The 0-based index of the episode to be played in the queue.
 */
protected void playFromQueue(int itemIdx) {
    final List<FeedItem> queue = DBReader.getQueue();
    Matcher<View> queueMatcher = allOf(withId(R.id.recyclerView), isDisplayed(), hasMinimumChildCount(2));
    onView(isRoot()).perform(waitForView(queueMatcher, 1000));
    onView(queueMatcher).perform(actionOnItemAtPosition(itemIdx, clickChildViewWithId(R.id.secondaryActionButton)));
    FeedMedia media = queue.get(itemIdx).getMedia();
    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) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView) EspressoTestUtils.waitForView(de.test.antennapod.EspressoTestUtils.waitForView)

Example 32 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia 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 33 with FeedMedia

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

the class DownloadRequestTest method doTestParcelInArrayList.

// Test to ensure parcel using put/getParcelableArrayList() API work
// based on: https://stackoverflow.com/a/13507191
private void doTestParcelInArrayList(String message, String username1, String password1, String username2, String password2) {
    ArrayList<DownloadRequest> toParcel;
    {
        // test DownloadRequests to parcel
        String destStr = "file://location/media.mp3";
        FeedMedia item1 = createFeedItem(1);
        DownloadRequest request1 = new DownloadRequest.Builder(destStr, item1).withAuthentication(username1, password1).build();
        FeedMedia item2 = createFeedItem(2);
        DownloadRequest request2 = new DownloadRequest.Builder(destStr, item2).withAuthentication(username2, password2).build();
        toParcel = new ArrayList<>();
        toParcel.add(request1);
        toParcel.add(request2);
    }
    // parcel the download requests
    Bundle bundleIn = new Bundle();
    bundleIn.putParcelableArrayList("r", toParcel);
    Parcel parcel = Parcel.obtain();
    bundleIn.writeToParcel(parcel, 0);
    Bundle bundleOut = new Bundle();
    bundleOut.setClassLoader(DownloadRequest.class.getClassLoader());
    // to read the parcel from the beginning.
    parcel.setDataPosition(0);
    bundleOut.readFromParcel(parcel);
    ArrayList<DownloadRequest> fromParcel = bundleOut.getParcelableArrayList("r");
    // spot-check contents to ensure they are the same
    // DownloadRequest.equals() implementation doesn't quite work
    // for DownloadRequest.argument (a Bundle)
    assertEquals(message + " - size", toParcel.size(), fromParcel.size());
    assertEquals(message + " - source", toParcel.get(1).getSource(), fromParcel.get(1).getSource());
    assertEquals(message + " - password", toParcel.get(0).getPassword(), fromParcel.get(0).getPassword());
    assertEquals(message + " - argument", toString(toParcel.get(0).getArguments()), toString(fromParcel.get(0).getArguments()));
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Bundle(android.os.Bundle) Parcel(android.os.Parcel) ArrayList(java.util.ArrayList)

Example 34 with FeedMedia

use of de.danoeh.antennapod.model.feed.FeedMedia 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 35 with FeedMedia

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

Aggregations

FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)91 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)46 Test (org.junit.Test)28 Feed (de.danoeh.antennapod.model.feed.Feed)26 Date (java.util.Date)25 ArrayList (java.util.ArrayList)18 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)15 File (java.io.File)15 Playable (de.danoeh.antennapod.model.playback.Playable)8 View (android.view.View)6 NonNull (androidx.annotation.NonNull)6 Context (android.content.Context)5 Log (android.util.Log)5 PlaybackServiceStarter (de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter)5 Cursor (android.database.Cursor)4 Nullable (androidx.annotation.Nullable)4 R (de.danoeh.antennapod.R)4 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)4 DownloadService (de.danoeh.antennapod.core.service.download.DownloadService)4 Intent (android.content.Intent)3