Search in sources :

Example 6 with FeedImage

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

the class DBReader method extractItemlistFromCursor.

private static List<FeedItem> extractItemlistFromCursor(PodDBAdapter adapter, Cursor cursor) {
    List<FeedItem> result = new ArrayList<>(cursor.getCount());
    LongList imageIds = new LongList(cursor.getCount());
    LongList itemIds = new LongList(cursor.getCount());
    if (cursor.moveToFirst()) {
        do {
            int indexImage = cursor.getColumnIndex(PodDBAdapter.KEY_IMAGE);
            long imageId = cursor.getLong(indexImage);
            imageIds.add(imageId);
            FeedItem item = FeedItem.fromCursor(cursor);
            result.add(item);
            itemIds.add(item.getId());
        } while (cursor.moveToNext());
        Map<Long, FeedImage> images = getFeedImages(adapter, imageIds.toArray());
        Map<Long, FeedMedia> medias = getFeedMedia(adapter, itemIds.toArray());
        for (int i = 0; i < result.size(); i++) {
            FeedItem item = result.get(i);
            long imageId = imageIds.get(i);
            FeedImage image = images.get(imageId);
            item.setImage(image);
            FeedMedia media = medias.get(item.getId());
            item.setMedia(media);
            if (media != null) {
                media.setItem(item);
            }
        }
    }
    return result;
}
Also used : 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) LongList(de.danoeh.antennapod.core.util.LongList)

Example 7 with FeedImage

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

the class UITestUtils method addHostedFeedData.

/**
     * Adds feeds, images and episodes to the webserver for testing purposes.
     */
public void addHostedFeedData() throws IOException {
    if (feedDataHosted)
        throw new IllegalStateException("addHostedFeedData was called twice on the same instance");
    for (int i = 0; i < NUM_FEEDS; i++) {
        File bitmapFile = newBitmapFile("image" + i);
        FeedImage image = new FeedImage(0, "image " + i, null, hostFile(bitmapFile), false);
        Feed feed = new Feed(0, null, "Title " + i, "http://example.com/" + i, "Description of feed " + i, "http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, image, null, "http://example.com/feed/src/" + i, false);
        image.setOwner(feed);
        // create items
        List<FeedItem> items = new ArrayList<FeedItem>();
        for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) {
            FeedItem item = new FeedItem(j, "Feed " + (i + 1) + ": Item " + (j + 1), "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), FeedItem.UNPLAYED, feed);
            items.add(item);
            File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
            item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0, 0));
        }
        feed.setItems(items);
        feed.setDownload_url(hostFeed(feed));
        hostedFeeds.add(feed);
    }
    feedDataHosted = true;
}
Also used : 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) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 8 with FeedImage

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

the class UITestUtils method addLocalFeedData.

/**
     * Adds feeds, images and episodes to the local database. This method will also call addHostedFeedData if it has not
     * been called yet.
     *
     * Adds one item of each feed to the queue and to the playback history.
     *
     * This method should NOT be called if the testing class wants to download the hosted feed data.
     *
     * @param downloadEpisodes true if episodes should also be marked as downloaded.
     */
public void addLocalFeedData(boolean downloadEpisodes) throws Exception {
    if (localFeedDataAdded) {
        Log.w(TAG, "addLocalFeedData was called twice on the same instance");
        // might be a flaky test, this is actually not that severe
        return;
    }
    if (!feedDataHosted) {
        addHostedFeedData();
    }
    List<FeedItem> queue = new ArrayList<>();
    for (Feed feed : hostedFeeds) {
        feed.setDownloaded(true);
        if (feed.getImage() != null) {
            FeedImage image = feed.getImage();
            int fileId = Integer.parseInt(StringUtils.substringAfter(image.getDownload_url(), "files/"));
            image.setFile_url(server.accessFile(fileId).getAbsolutePath());
            image.setDownloaded(true);
        }
        if (downloadEpisodes) {
            for (FeedItem item : feed.getItems()) {
                if (item.hasMedia()) {
                    FeedMedia media = item.getMedia();
                    int fileId = Integer.parseInt(StringUtils.substringAfter(media.getDownload_url(), "files/"));
                    media.setFile_url(server.accessFile(fileId).getAbsolutePath());
                    media.setDownloaded(true);
                }
            }
        }
        queue.add(feed.getItems().get(0));
        feed.getItems().get(1).getMedia().setPlaybackCompletionDate(new Date());
    }
    localFeedDataAdded = true;
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()]));
    adapter.setQueue(queue);
    adapter.close();
    EventDistributor.getInstance().sendFeedUpdateBroadcast();
    EventBus.getDefault().post(QueueEvent.setQueue(queue));
}
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) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 9 with FeedImage

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

the class DBWriterTest method testDeleteFeedWithQueueItems.

public void testDeleteFeedWithQueueItems() throws 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");
    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);
    }
    List<FeedItem> queue = new ArrayList<FeedItem>();
    queue.addAll(feed.getItems());
    adapter.open();
    adapter.setQueue(queue);
    Cursor queueCursor = adapter.getQueueIDCursor();
    assertTrue(queueCursor.getCount() == queue.size());
    queueCursor.close();
    adapter.close();
    DBWriter.deleteFeed(getInstrumentation().getTargetContext(), feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
    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();
    }
    c = adapter.getQueueCursor();
    assertTrue(c.getCount() == 0);
    c.close();
    adapter.close();
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Date(java.util.Date) PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 10 with FeedImage

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

the class DBWriterTest method testDeleteFeedNoItems.

public void testDeleteFeedNoItems() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    Feed feed = new Feed("url", null, "title");
    feed.setItems(null);
    // 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);
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(feed.getId() != 0);
    assertTrue(feed.getImage().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();
    adapter.close();
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) Cursor(android.database.Cursor) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed)

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