Search in sources :

Example 11 with FeedImage

use of de.danoeh.antennapod.core.feed.FeedImage in project AntennaPod by AntennaPod.

the class DBWriterTest method testDeleteFeedNoDownloadedFiles.

public void testDeleteFeedNoDownloadedFiles() throws ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<FeedItem>());
    // create Feed image
    File imgFile = new File(destFolder, "image");
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);
    List<File> itemFiles = new ArrayList<File>();
    // 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);
        itemFiles.add(enc);
        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);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
        assertTrue(item.getMedia().getId() != 0);
    }
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    for (FeedItem item : feed.getItems()) {
        c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
        assertTrue(c.getCount() == 0);
        c.close();
        c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
        assertTrue(c.getCount() == 0);
        c.close();
    }
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 12 with FeedImage

use of de.danoeh.antennapod.core.feed.FeedImage in project AntennaPod by AntennaPod.

the class DBWriterTest method testDeleteFeedNoFeedMedia.

public void testDeleteFeedNoFeedMedia() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    // create Feed image
    File imgFile = new File(destFolder, "image");
    assertTrue(imgFile.createNewFile());
    FeedImage image = new FeedImage(0, "image", imgFile.getAbsolutePath(), "url", true);
    image.setOwner(feed);
    feed.setImage(image);
    // create items
    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);
    }
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().getId() != 0);
    for (FeedItem item : feed.getItems()) {
        assertTrue(item.getId() != 0);
    }
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    // check if files still exist
    assertFalse(imgFile.exists());
    adapter = PodDBAdapter.getInstance();
    adapter.open();
    Cursor c = adapter.getFeedCursor(feed.getId());
    assertTrue(c.getCount() == 0);
    c.close();
    c = adapter.getImageCursor(String.valueOf(image.getId()));
    assertTrue(c.getCount() == 0);
    c.close();
    for (FeedItem item : feed.getItems()) {
        c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
        assertTrue(c.getCount() == 0);
        c.close();
    }
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Cursor(android.database.Cursor) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 13 with FeedImage

use of de.danoeh.antennapod.core.feed.FeedImage in project AntennaPod by AntennaPod.

the class FeedHandlerTest method createTestFeed.

private Feed createTestFeed(int numItems, boolean withImage, boolean withFeedMedia, boolean withChapters) {
    FeedImage image = null;
    if (withImage) {
        image = new FeedImage(0, "image", null, "http://example.com/picture", false);
    }
    Feed feed = new Feed(0, null, "title", "http://example.com", "This is the description", "http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", image, file.getAbsolutePath(), "http://example.com/feed", true);
    feed.setItems(new ArrayList<FeedItem>());
    for (int i = 0; i < numItems; i++) {
        FeedItem item = new FeedItem(0, "item-" + i, "http://example.com/item-" + i, "http://example.com/items/" + i, new Date(i * 60000), FeedItem.UNPLAYED, feed);
        feed.getItems().add(item);
        if (withFeedMedia) {
            item.setMedia(new FeedMedia(0, item, 4711, 0, 1024 * 1024, "audio/mp3", null, "http://example.com/media-" + i, false, null, 0, 0));
        }
    }
    return feed;
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 14 with FeedImage

use of de.danoeh.antennapod.core.feed.FeedImage in project AntennaPod by AntennaPod.

the class FeedHandlerTest method feedValid.

private void feedValid(Feed feed, Feed parsedFeed, String feedType) {
    assertEquals(feed.getTitle(), parsedFeed.getTitle());
    if (feedType.equals(Feed.TYPE_ATOM1)) {
        assertEquals(feed.getFeedIdentifier(), parsedFeed.getFeedIdentifier());
    } else {
        assertEquals(feed.getLanguage(), parsedFeed.getLanguage());
    }
    assertEquals(feed.getLink(), parsedFeed.getLink());
    assertEquals(feed.getDescription(), parsedFeed.getDescription());
    assertEquals(feed.getPaymentLink(), parsedFeed.getPaymentLink());
    if (feed.getImage() != null) {
        FeedImage image = feed.getImage();
        FeedImage parsedImage = parsedFeed.getImage();
        assertNotNull(parsedImage);
        assertEquals(image.getTitle(), parsedImage.getTitle());
        assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
    }
    if (feed.getItems() != null) {
        assertNotNull(parsedFeed.getItems());
        assertEquals(feed.getItems().size(), parsedFeed.getItems().size());
        for (int i = 0; i < feed.getItems().size(); i++) {
            FeedItem item = feed.getItems().get(i);
            FeedItem parsedItem = parsedFeed.getItems().get(i);
            if (item.getItemIdentifier() != null)
                assertEquals(item.getItemIdentifier(), parsedItem.getItemIdentifier());
            assertEquals(item.getTitle(), parsedItem.getTitle());
            assertEquals(item.getDescription(), parsedItem.getDescription());
            assertEquals(item.getContentEncoded(), parsedItem.getContentEncoded());
            assertEquals(item.getLink(), parsedItem.getLink());
            assertEquals(item.getPubDate().getTime(), parsedItem.getPubDate().getTime());
            assertEquals(item.getPaymentLink(), parsedItem.getPaymentLink());
            if (item.hasMedia()) {
                assertTrue(parsedItem.hasMedia());
                FeedMedia media = item.getMedia();
                FeedMedia parsedMedia = parsedItem.getMedia();
                assertEquals(media.getDownload_url(), parsedMedia.getDownload_url());
                assertEquals(media.getSize(), parsedMedia.getSize());
                assertEquals(media.getMime_type(), parsedMedia.getMime_type());
            }
            if (item.hasItemImage()) {
                assertTrue(parsedItem.hasItemImage());
                FeedImage image = item.getImage();
                FeedImage parsedImage = parsedItem.getImage();
                assertEquals(image.getTitle(), parsedImage.getTitle());
                assertEquals(image.getDownload_url(), parsedImage.getDownload_url());
            }
            if (item.getChapters() != null) {
                assertNotNull(parsedItem.getChapters());
                assertEquals(item.getChapters().size(), parsedItem.getChapters().size());
                List<Chapter> chapters = item.getChapters();
                List<Chapter> parsedChapters = parsedItem.getChapters();
                for (int j = 0; j < chapters.size(); j++) {
                    Chapter chapter = chapters.get(j);
                    Chapter parsedChapter = parsedChapters.get(j);
                    assertEquals(chapter.getTitle(), parsedChapter.getTitle());
                    assertEquals(chapter.getLink(), parsedChapter.getLink());
                }
            }
        }
    }
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Chapter(de.danoeh.antennapod.core.feed.Chapter)

Example 15 with FeedImage

use of de.danoeh.antennapod.core.feed.FeedImage in project AntennaPod by AntennaPod.

the class NSITunes method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (IMAGE.equals(localName)) {
        FeedImage image = new FeedImage();
        image.setTitle(IMAGE_TITLE);
        image.setDownload_url(attributes.getValue(IMAGE_HREF));
        if (state.getCurrentItem() != null) {
            // this is an items image
            image.setTitle(state.getCurrentItem().getTitle() + IMAGE_TITLE);
            image.setOwner(state.getCurrentItem());
            state.getCurrentItem().setImage(image);
        } else {
            // prefer to all other images
            if (!TextUtils.isEmpty(image.getDownload_url())) {
                image.setOwner(state.getFeed());
                state.getFeed().setImage(image);
            }
        }
    }
    return new SyndElement(localName, this);
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage)

Aggregations

FeedImage (de.danoeh.antennapod.core.feed.FeedImage)20 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)14 Feed (de.danoeh.antennapod.core.feed.Feed)13 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)10 File (java.io.File)8 Date (java.util.Date)8 Cursor (android.database.Cursor)7 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)7 ArrayList (java.util.ArrayList)7 Chapter (de.danoeh.antennapod.core.feed.Chapter)2 BackupManager (android.app.backup.BackupManager)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 ArrayMap (android.support.v4.util.ArrayMap)1 MediaInfo (com.google.android.gms.cast.MediaInfo)1 MediaMetadata (com.google.android.gms.cast.MediaMetadata)1 WebImage (com.google.android.gms.common.images.WebImage)1 FeedPreferences (de.danoeh.antennapod.core.feed.FeedPreferences)1 SimpleChapter (de.danoeh.antennapod.core.feed.SimpleChapter)1 SyndElement (de.danoeh.antennapod.core.syndication.namespace.SyndElement)1