Search in sources :

Example 71 with FeedMedia

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

the class StreamActionButton method onClick.

@Override
public void onClick(Context context) {
    final FeedMedia media = item.getMedia();
    if (media == null) {
        return;
    }
    UsageStatistics.logAction(UsageStatistics.ACTION_STREAM);
    if (!NetworkUtils.isStreamingAllowed()) {
        new StreamingConfirmationDialog(context, media).show();
        return;
    }
    new PlaybackServiceStarter(context, media).callEvenIfRunning(true).startWhenPrepared(true).shouldStream(true).start();
    if (media.getMediaType() == MediaType.VIDEO) {
        context.startActivity(PlaybackService.getPlayerActivityIntent(context, media));
    }
}
Also used : PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) StreamingConfirmationDialog(de.danoeh.antennapod.dialog.StreamingConfirmationDialog)

Example 72 with FeedMedia

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

the class CancelDownloadActionButton method onClick.

@Override
public void onClick(Context context) {
    FeedMedia media = item.getMedia();
    DownloadService.cancel(context, media.getDownload_url());
    if (UserPreferences.isEnableAutodownload()) {
        item.disableAutoDownload();
        DBWriter.setFeedItem(item);
    }
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 73 with FeedMedia

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

the class DbWriterTest method testAddItemToPlaybackHistoryNotPlayedYet.

@Test
public void testAddItemToPlaybackHistoryNotPlayedYet() throws Exception {
    FeedMedia media = playbackHistorySetup(null);
    DBWriter.addItemToPlaybackHistory(media).get(TIMEOUT, TimeUnit.SECONDS);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    media = DBReader.getFeedMedia(media.getId());
    adapter.close();
    assertNotNull(media);
    assertNotNull(media.getPlaybackCompletionDate());
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 74 with FeedMedia

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

the class DbWriterTest method testDeleteFeedMediaOfItemRemoveFromQueue.

@Test
public void testDeleteFeedMediaOfItemRemoveFromQueue() throws Exception {
    assertTrue(UserPreferences.shouldDeleteRemoveFromQueue());
    File dest = new File(context.getExternalFilesDir(TEST_FOLDER), "testFile");
    assertTrue(dest.createNewFile());
    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.UNPLAYED, feed);
    FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", dest.getAbsolutePath(), "download_url", true, null, 0, 0);
    item.setMedia(media);
    items.add(item);
    List<FeedItem> queue = new ArrayList<>();
    queue.add(item);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.setQueue(queue);
    adapter.close();
    assertTrue(media.getId() != 0);
    assertTrue(item.getId() != 0);
    queue = DBReader.getQueue();
    assertTrue(queue.size() != 0);
    DBWriter.deleteFeedMediaOfItem(context, media.getId());
    Awaitility.await().timeout(2, TimeUnit.SECONDS).until(() -> !dest.exists());
    media = DBReader.getFeedMedia(media.getId());
    assertNotNull(media);
    assertFalse(dest.exists());
    assertFalse(media.isDownloaded());
    assertNull(media.getFile_url());
    Awaitility.await().timeout(2, TimeUnit.SECONDS).until(() -> DBReader.getQueue().isEmpty());
}
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 75 with FeedMedia

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

the class DbWriterTest method testDeleteFeedWithQueueItems.

@Test
public void testDeleteFeedWithQueueItems() throws Exception {
    File destFolder = context.getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    feed.setImageUrl("url");
    // create items with downloaded media files
    for (int i = 0; i < 10; i++) {
        FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
        feed.getItems().add(item);
        File enc = new File(destFolder, "file " + i);
        FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", false, null, 0, 0);
        item.setMedia(media);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
    }
    List<FeedItem> queue = new ArrayList<>(feed.getItems());
    adapter.open();
    adapter.setQueue(queue);
    Cursor queueCursor = adapter.getQueueIDCursor();
    assertEquals(queue.size(), queueCursor.getCount());
    queueCursor.close();
    adapter.close();
    DBWriter.deleteFeed(context, feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertEquals(0, c.getCount());
    c.close();
    for (FeedItem item : feed.getItems()) {
        c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
        assertEquals(0, c.getCount());
        c.close();
        c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
        assertEquals(0, c.getCount());
        c.close();
    }
    c = adapter.getQueueCursor();
    assertEquals(0, c.getCount());
    c.close();
    adapter.close();
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) File(java.io.File) 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