Search in sources :

Example 21 with FeedItem

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

the class PlayerWidgetService method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "Service is about to be destroyed");
    if (playbackService != null) {
        Playable playable = playbackService.getPlayable();
        if (playable != null && playable instanceof FeedMedia) {
            FeedMedia media = (FeedMedia) playable;
            if (media.hasAlmostEnded()) {
                Log.d(TAG, "smart mark as read");
                FeedItem item = media.getItem();
                DBWriter.markItemPlayed(item, FeedItem.PLAYED, false);
                DBWriter.removeQueueItem(this, item, false);
                DBWriter.addItemToPlaybackHistory(media);
                if (item.getFeed().getPreferences().getCurrentAutoDelete()) {
                    Log.d(TAG, "Delete " + media.toString());
                    DBWriter.deleteFeedMediaOfItem(this, media.getId());
                }
            }
        }
    }
    try {
        unbindService(mConnection);
    } catch (IllegalArgumentException e) {
        Log.w(TAG, "IllegalArgumentException when trying to unbind service");
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 22 with FeedItem

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

the class MediaplayerActivity method checkFavorite.

private void checkFavorite() {
    Playable playable = controller.getMedia();
    if (playable != null && playable instanceof FeedMedia) {
        FeedItem feedItem = ((FeedMedia) playable).getItem();
        if (feedItem != null) {
            Observable.fromCallable(() -> DBReader.getFeedItem(feedItem.getId())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(item -> {
                boolean isFav = item.isTagged(FeedItem.TAG_FAVORITE);
                if (isFavorite != isFav) {
                    isFavorite = isFav;
                    invalidateOptionsMenu();
                }
            }, error -> Log.e(TAG, Log.getStackTraceString(error)));
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 23 with FeedItem

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

the class OnlineFeedViewActivity method beforeShowFeedInformation.

/**
     * Called after the feed has been downloaded and parsed and before showFeedInformation is called.
     * This method is executed on a background thread
     */
private void beforeShowFeedInformation(Feed feed) {
    final HtmlToPlainText formatter = new HtmlToPlainText();
    if (Feed.TYPE_ATOM1.equals(feed.getType()) && feed.getDescription() != null) {
        // remove HTML tags from descriptions
        Log.d(TAG, "Removing HTML from feed description");
        Document feedDescription = Jsoup.parse(feed.getDescription());
        feed.setDescription(StringUtils.trim(formatter.getPlainText(feedDescription)));
    }
    Log.d(TAG, "Removing HTML from shownotes");
    if (feed.getItems() != null) {
        for (FeedItem item : feed.getItems()) {
            if (item.getDescription() != null) {
                Document itemDescription = Jsoup.parse(item.getDescription());
                item.setDescription(StringUtils.trim(formatter.getPlainText(itemDescription)));
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) HtmlToPlainText(de.danoeh.antennapod.core.util.syndication.HtmlToPlainText) Document(org.jsoup.nodes.Document)

Example 24 with FeedItem

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

the class AdapterUtils method updateEpisodePlaybackProgress.

/**
     * Updates the contents of the TextView that shows the current playback position and the ProgressBar.
     */
static void updateEpisodePlaybackProgress(FeedItem item, TextView txtvPos, ProgressBar episodeProgress) {
    FeedMedia media = item.getMedia();
    episodeProgress.setVisibility(View.GONE);
    if (media == null) {
        txtvPos.setVisibility(View.GONE);
        return;
    } else {
        txtvPos.setVisibility(View.VISIBLE);
    }
    FeedItem.State state = item.getState();
    if (state == FeedItem.State.PLAYING || state == FeedItem.State.IN_PROGRESS) {
        if (media.getDuration() > 0) {
            episodeProgress.setVisibility(View.VISIBLE);
            episodeProgress.setProgress((int) (((double) media.getPosition()) / media.getDuration() * 100));
            txtvPos.setText(Converter.getDurationStringLong(media.getDuration() - media.getPosition()));
        }
    } else if (!media.isDownloaded()) {
        if (media.getSize() > 0) {
            txtvPos.setText(Converter.byteToString(media.getSize()));
        } else if (NetworkUtils.isDownloadAllowed() && !media.checkedOnSizeButUnknown()) {
            txtvPos.setText("{fa-spinner}");
            Iconify.addIcons(txtvPos);
            NetworkUtils.getFeedMediaSizeObservable(media).subscribe(size -> {
                if (size > 0) {
                    txtvPos.setText(Converter.byteToString(size));
                } else {
                    txtvPos.setText("");
                }
            }, error -> {
                txtvPos.setText("");
                Log.e(TAG, Log.getStackTraceString(error));
            });
        } else {
            txtvPos.setText("");
        }
    } else {
        txtvPos.setText(Converter.getDurationStringLong(media.getDuration()));
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 25 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)

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