Search in sources :

Example 81 with FeedMedia

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

the class DbCleanupTests method populateItems.

@SuppressWarnings("SameParameterValue")
void populateItems(final int numItems, Feed feed, List<FeedItem> items, List<File> files, int itemState, boolean addToQueue, boolean addToFavorites) throws IOException {
    for (int i = 0; i < numItems; i++) {
        Date itemDate = new Date(numItems - i);
        Date playbackCompletionDate = null;
        if (itemState == FeedItem.PLAYED) {
            playbackCompletionDate = itemDate;
        }
        FeedItem item = new FeedItem(0, "title", "id" + i, "link", itemDate, itemState, 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, playbackCompletionDate, 0, 0));
        items.add(item);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    if (addToQueue) {
        adapter.setQueue(items);
    }
    if (addToFavorites) {
        adapter.setFavorites(items);
    }
    adapter.close();
    assertTrue(feed.getId() != 0);
    for (FeedItem item : items) {
        assertTrue(item.getId() != 0);
        // noinspection ConstantConditions
        assertTrue(item.getMedia().getId() != 0);
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) File(java.io.File) Date(java.util.Date)

Example 82 with FeedMedia

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

the class PlaybackVolumeUpdaterTest method updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking.

@Test
public void updatesPreferencesForLoadedFeedMediaIfPlayerStatusIsSeeking() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.SEEKING);
    FeedMedia feedMedia = mockFeedMedia();
    when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
    FeedPreferences feedPreferences = feedMedia.getItem().getFeed().getPreferences();
    playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.LIGHT_REDUCTION);
    verify(feedPreferences, times(1)).setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_REDUCTION);
    verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
    verify(mediaPlayer, never()).resume();
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 83 with FeedMedia

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

the class PlaybackVolumeUpdaterTest method noChangeIfPlayableIsNoItemOfAffectedFeed.

@Test
public void noChangeIfPlayableIsNoItemOfAffectedFeed() {
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PLAYING);
    FeedMedia feedMedia = mockFeedMedia();
    when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
    when(feedMedia.getItem().getFeed().getId()).thenReturn(FEED_ID + 1);
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
    verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
    verify(mediaPlayer, never()).resume();
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 84 with FeedMedia

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

the class PlaybackVolumeUpdaterTest method noChangeIfPlayerStatusIsError.

@Test
public void noChangeIfPlayerStatusIsError() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.ERROR);
    FeedMedia feedMedia = mockFeedMedia();
    when(mediaPlayer.getPlayable()).thenReturn(feedMedia);
    playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
    verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
    verify(mediaPlayer, never()).resume();
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 85 with FeedMedia

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

the class PlaybackVolumeUpdaterTest method mockFeedMedia.

private FeedMedia mockFeedMedia() {
    FeedMedia feedMedia = mock(FeedMedia.class);
    FeedItem feedItem = mock(FeedItem.class);
    Feed feed = mock(Feed.class);
    FeedPreferences feedPreferences = mock(FeedPreferences.class);
    when(feedMedia.getItem()).thenReturn(feedItem);
    when(feedItem.getFeed()).thenReturn(feed);
    when(feed.getId()).thenReturn(FEED_ID);
    when(feed.getPreferences()).thenReturn(feedPreferences);
    return feedMedia;
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Feed(de.danoeh.antennapod.model.feed.Feed)

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