Search in sources :

Example 56 with FeedItem

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

the class AllEpisodesRecycleAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final Holder holder, int position) {
    final FeedItem item = itemAccess.getItem(position);
    if (item == null)
        return;
    holder.itemView.setOnLongClickListener(v -> {
        this.position = position;
        return false;
    });
    holder.item = item;
    holder.position = position;
    holder.placeholder.setVisibility(View.VISIBLE);
    holder.placeholder.setText(item.getFeed().getTitle());
    holder.title.setText(item.getTitle());
    String pubDateStr = DateUtils.formatAbbrev(mainActivityRef.get(), item.getPubDate());
    holder.pubDate.setText(pubDateStr);
    if (showOnlyNewEpisodes || !item.isNew()) {
        holder.statusUnread.setVisibility(View.INVISIBLE);
    } else {
        holder.statusUnread.setVisibility(View.VISIBLE);
    }
    if (item.isPlayed()) {
        ViewHelper.setAlpha(holder.content, 0.5f);
    } else {
        ViewHelper.setAlpha(holder.content, 1.0f);
    }
    FeedMedia media = item.getMedia();
    if (media != null) {
        final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media);
        if (media.getDuration() > 0) {
            holder.txtvDuration.setText(Converter.getDurationStringLong(media.getDuration()));
        } else if (media.getSize() > 0) {
            holder.txtvDuration.setText(Converter.byteToString(media.getSize()));
        } else if (NetworkUtils.isDownloadAllowed() && !media.checkedOnSizeButUnknown()) {
            holder.txtvDuration.setText("{fa-spinner}");
            Iconify.addIcons(holder.txtvDuration);
            NetworkUtils.getFeedMediaSizeObservable(media).subscribe(size -> {
                if (size > 0) {
                    holder.txtvDuration.setText(Converter.byteToString(size));
                } else {
                    holder.txtvDuration.setText("");
                }
            }, error -> {
                holder.txtvDuration.setText("");
                Log.e(TAG, Log.getStackTraceString(error));
            });
        } else {
            holder.txtvDuration.setText("");
        }
        FeedItem.State state = item.getState();
        if (isDownloadingMedia) {
            holder.progress.setVisibility(View.VISIBLE);
            // item is being downloaded
            holder.progress.setProgress(itemAccess.getItemDownloadProgressPercent(item));
        } else if (state == FeedItem.State.PLAYING || state == FeedItem.State.IN_PROGRESS) {
            if (media.getDuration() > 0) {
                int progress = (int) (100.0 * media.getPosition() / media.getDuration());
                holder.progress.setProgress(progress);
                holder.progress.setVisibility(View.VISIBLE);
            }
        } else {
            holder.progress.setVisibility(View.GONE);
        }
        if (media.isCurrentlyPlaying()) {
            holder.container.setBackgroundColor(playingBackGroundColor);
        } else {
            holder.container.setBackgroundColor(normalBackGroundColor);
        }
    } else {
        holder.progress.setVisibility(View.GONE);
        holder.txtvDuration.setVisibility(View.GONE);
    }
    boolean isInQueue = itemAccess.isInQueue(item);
    if (isInQueue) {
        holder.queueStatus.setVisibility(View.VISIBLE);
    } else {
        holder.queueStatus.setVisibility(View.INVISIBLE);
    }
    actionButtonUtils.configureActionButton(holder.butSecondary, item, isInQueue);
    holder.butSecondary.setFocusable(false);
    holder.butSecondary.setTag(item);
    holder.butSecondary.setOnClickListener(secondaryActionListener);
    Glide.with(mainActivityRef.get()).load(item.getImageLocation()).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(new CoverTarget(item.getFeed().getImageLocation(), holder.placeholder, holder.cover, mainActivityRef.get()));
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 57 with FeedItem

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

the class AtomGenerator method writeFeed.

@Override
public void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException {
    if (feed == null)
        throw new IllegalArgumentException("feed = null");
    if (outputStream == null)
        throw new IllegalArgumentException("outputStream = null");
    if (encoding == null)
        throw new IllegalArgumentException("encoding = null");
    XmlSerializer xml = Xml.newSerializer();
    xml.setOutput(outputStream, encoding);
    xml.startDocument(encoding, null);
    xml.startTag(null, "feed");
    xml.attribute(null, "xmlns", NS_ATOM);
    // Write Feed data
    if (feed.getIdentifyingValue() != null) {
        xml.startTag(null, "id");
        xml.text(feed.getIdentifyingValue());
        xml.endTag(null, "id");
    }
    if (feed.getTitle() != null) {
        xml.startTag(null, "title");
        xml.text(feed.getTitle());
        xml.endTag(null, "title");
    }
    if (feed.getLink() != null) {
        xml.startTag(null, "link");
        xml.attribute(null, "rel", "alternate");
        xml.attribute(null, "href", feed.getLink());
        xml.endTag(null, "link");
    }
    if (feed.getDescription() != null) {
        xml.startTag(null, "subtitle");
        xml.text(feed.getDescription());
        xml.endTag(null, "subtitle");
    }
    if (feed.getPaymentLink() != null) {
        GeneratorUtil.addPaymentLink(xml, feed.getPaymentLink(), false);
    }
    // Write FeedItem data
    if (feed.getItems() != null) {
        for (FeedItem item : feed.getItems()) {
            xml.startTag(null, "entry");
            if (item.getIdentifyingValue() != null) {
                xml.startTag(null, "id");
                xml.text(item.getIdentifyingValue());
                xml.endTag(null, "id");
            }
            if (item.getTitle() != null) {
                xml.startTag(null, "title");
                xml.text(item.getTitle());
                xml.endTag(null, "title");
            }
            if (item.getLink() != null) {
                xml.startTag(null, "link");
                xml.attribute(null, "rel", "alternate");
                xml.attribute(null, "href", item.getLink());
                xml.endTag(null, "link");
            }
            if (item.getPubDate() != null) {
                xml.startTag(null, "published");
                if ((flags & FEATURE_USE_RFC3339LOCAL) != 0) {
                    xml.text(DateUtils.formatRFC3339Local(item.getPubDate()));
                } else {
                    xml.text(DateUtils.formatRFC3339UTC(item.getPubDate()));
                }
                xml.endTag(null, "published");
            }
            if (item.getDescription() != null) {
                xml.startTag(null, "content");
                xml.text(item.getDescription());
                xml.endTag(null, "content");
            }
            if (item.getMedia() != null) {
                FeedMedia media = item.getMedia();
                xml.startTag(null, "link");
                xml.attribute(null, "rel", "enclosure");
                xml.attribute(null, "href", media.getDownload_url());
                xml.attribute(null, "type", media.getMime_type());
                xml.attribute(null, "length", String.valueOf(media.getSize()));
                xml.endTag(null, "link");
            }
            if (item.getPaymentLink() != null) {
                GeneratorUtil.addPaymentLink(xml, item.getPaymentLink(), false);
            }
            xml.endTag(null, "entry");
        }
    }
    xml.endTag(null, "feed");
    xml.endDocument();
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Example 58 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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 59 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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 60 with FeedItem

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

the class UITestUtilsTest method addLocalFeedDataCheck.

private void addLocalFeedDataCheck(boolean downloadEpisodes) throws Exception {
    uiTestUtils.addLocalFeedData(downloadEpisodes);
    assertNotNull(uiTestUtils.hostedFeeds);
    assertFalse(uiTestUtils.hostedFeeds.isEmpty());
    for (Feed feed : uiTestUtils.hostedFeeds) {
        assertTrue(feed.getId() != 0);
        if (feed.getImage() != null) {
            assertTrue(feed.getImage().getId() != 0);
        }
        for (FeedItem item : feed.getItems()) {
            assertTrue(item.getId() != 0);
            if (item.hasMedia()) {
                assertTrue(item.getMedia().getId() != 0);
                if (downloadEpisodes) {
                    assertTrue(item.getMedia().isDownloaded());
                    assertNotNull(item.getMedia().getFile_url());
                    File file = new File(item.getMedia().getFile_url());
                    assertTrue(file.exists());
                }
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) File(java.io.File) Feed(de.danoeh.antennapod.core.feed.Feed)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4