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");
}
}
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)));
}
}
}
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)));
}
}
}
}
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()));
}
}
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()));
}
Aggregations