Search in sources :

Example 76 with FeedMedia

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

the class DbWriterTest method testDeleteFeedNoDownloadedFiles.

@Test
public void testDeleteFeedNoDownloadedFiles() 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);
    }
    DBWriter.deleteFeed(context, feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    adapter = PodDBAdapter.getInstance();
    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();
    }
    adapter.close();
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Cursor(android.database.Cursor) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.model.feed.Feed) Test(org.junit.Test)

Example 77 with FeedMedia

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

the class DbWriterTest method testAddItemToPlaybackHistoryAlreadyPlayed.

@Test
public void testAddItemToPlaybackHistoryAlreadyPlayed() throws Exception {
    final long oldDate = 0;
    FeedMedia media = playbackHistorySetup(new Date(oldDate));
    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());
    assertNotEquals(media.getPlaybackCompletionDate().getTime(), oldDate);
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Date(java.util.Date) Test(org.junit.Test)

Example 78 with FeedMedia

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

the class FeedItemDuplicateGuesserTest method item.

private FeedItem item(String guid, String title, String downloadUrl, long date, long duration, String mime) {
    FeedItem item = new FeedItem(0, title, guid, "link", new Date(date), FeedItem.PLAYED, null);
    FeedMedia media = new FeedMedia(item, downloadUrl, duration, mime);
    item.setMedia(media);
    return item;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Date(java.util.Date)

Example 79 with FeedMedia

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

the class DownloadRequestTest method downloadRequestTestEquals.

@Test
public void downloadRequestTestEquals() {
    String destStr = "file://location/media.mp3";
    String username = "testUser";
    String password = "testPassword";
    FeedMedia item = createFeedItem(1);
    DownloadRequest request1 = new DownloadRequest.Builder(destStr, item).deleteOnFailure(true).withAuthentication(username, password).build();
    DownloadRequest request2 = new DownloadRequest.Builder(destStr, item).deleteOnFailure(true).withAuthentication(username, password).build();
    DownloadRequest request3 = new DownloadRequest.Builder(destStr, item).deleteOnFailure(true).withAuthentication("diffUsername", "diffPassword").build();
    assertEquals(request1, request2);
    assertNotEquals(request1, request3);
}
Also used : FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) Test(org.junit.Test)

Example 80 with FeedMedia

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

the class DbTestUtils method saveFeedlist.

/**
 * Use this method when tests involve chapters.
 */
public static List<Feed> saveFeedlist(int numFeeds, int numItems, boolean withMedia, boolean withChapters, int numChapters) {
    if (numFeeds <= 0) {
        throw new IllegalArgumentException("numFeeds<=0");
    }
    if (numItems < 0) {
        throw new IllegalArgumentException("numItems<0");
    }
    List<Feed> feeds = new ArrayList<>();
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    for (int i = 0; i < numFeeds; i++) {
        Feed f = new Feed(0, null, "feed " + i, "link" + i, "descr", null, null, null, null, "id" + i, null, null, "url" + i, false);
        f.setItems(new ArrayList<>());
        for (int j = 0; j < numItems; j++) {
            FeedItem item = new FeedItem(0, "item " + j, "id" + j, "link" + j, new Date(), FeedItem.PLAYED, f, withChapters);
            if (withMedia) {
                FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3");
                item.setMedia(media);
            }
            if (withChapters) {
                List<Chapter> chapters = new ArrayList<>();
                item.setChapters(chapters);
                for (int k = 0; k < numChapters; k++) {
                    chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k, "http://example.com", "http://example.com/image.png"));
                }
            }
            f.getItems().add(item);
        }
        Collections.sort(f.getItems(), new FeedItemPubdateComparator());
        adapter.setCompleteFeed(f);
        assertTrue(f.getId() != 0);
        for (FeedItem item : f.getItems()) {
            assertTrue(item.getId() != 0);
        }
        feeds.add(f);
    }
    adapter.close();
    return feeds;
}
Also used : ArrayList(java.util.ArrayList) SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) Chapter(de.danoeh.antennapod.model.feed.Chapter) Date(java.util.Date) SimpleChapter(de.danoeh.antennapod.parser.feed.element.SimpleChapter) FeedItemPubdateComparator(de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator) 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