Search in sources :

Example 1 with StreamingConfirmationDialog

use of de.danoeh.antennapod.dialog.StreamingConfirmationDialog in project AntennaPod by AntennaPod.

the class FeedItemlistDescriptionAdapter method getView.

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    Holder holder;
    FeedItem item = getItem(position);
    // Inflate layout
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.itemdescription_listitem, parent, false);
        holder.title = convertView.findViewById(R.id.txtvTitle);
        holder.pubDate = convertView.findViewById(R.id.txtvPubDate);
        holder.description = convertView.findViewById(R.id.txtvDescription);
        holder.preview = convertView.findViewById(R.id.butPreview);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    holder.title.setText(item.getTitle());
    holder.pubDate.setText(DateFormatter.formatAbbrev(getContext(), item.getPubDate()));
    if (item.getDescription() != null) {
        String description = HtmlToPlainText.getPlainText(item.getDescription()).replaceAll("\n", " ").replaceAll("\\s+", " ").trim();
        holder.description.setText(description);
        holder.description.setMaxLines(MAX_LINES_COLLAPSED);
    }
    // not expanded
    holder.description.setTag(Boolean.FALSE);
    holder.preview.setVisibility(View.GONE);
    holder.preview.setOnClickListener(v -> {
        if (item.getMedia() == null) {
            return;
        }
        Playable playable = new RemoteMedia(item);
        if (!NetworkUtils.isStreamingAllowed()) {
            new StreamingConfirmationDialog(getContext(), playable).show();
            return;
        }
        new PlaybackServiceStarter(getContext(), playable).shouldStream(true).startWhenPrepared(true).callEvenIfRunning(true).start();
        if (playable.getMediaType() == MediaType.VIDEO) {
            getContext().startActivity(PlaybackService.getPlayerActivityIntent(getContext(), playable));
        }
    });
    convertView.setOnClickListener(v -> {
        if (holder.description.getTag() == Boolean.TRUE) {
            holder.description.setMaxLines(MAX_LINES_COLLAPSED);
            holder.preview.setVisibility(View.GONE);
            holder.description.setTag(Boolean.FALSE);
        } else {
            holder.description.setMaxLines(30);
            holder.description.setTag(Boolean.TRUE);
            holder.preview.setVisibility(item.getMedia() != null ? View.VISIBLE : View.GONE);
            holder.preview.setText(R.string.preview_episode);
        }
    });
    return convertView;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) Playable(de.danoeh.antennapod.model.playback.Playable) LayoutInflater(android.view.LayoutInflater) RemoteMedia(de.danoeh.antennapod.model.playback.RemoteMedia) StreamingConfirmationDialog(de.danoeh.antennapod.dialog.StreamingConfirmationDialog) NonNull(androidx.annotation.NonNull)

Example 2 with StreamingConfirmationDialog

use of de.danoeh.antennapod.dialog.StreamingConfirmationDialog in project AntennaPod by AntennaPod.

the class StreamActionButton method onClick.

@Override
public void onClick(Context context) {
    final FeedMedia media = item.getMedia();
    if (media == null) {
        return;
    }
    UsageStatistics.logAction(UsageStatistics.ACTION_STREAM);
    if (!NetworkUtils.isStreamingAllowed()) {
        new StreamingConfirmationDialog(context, media).show();
        return;
    }
    new PlaybackServiceStarter(context, media).callEvenIfRunning(true).startWhenPrepared(true).shouldStream(true).start();
    if (media.getMediaType() == MediaType.VIDEO) {
        context.startActivity(PlaybackService.getPlayerActivityIntent(context, media));
    }
}
Also used : PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) StreamingConfirmationDialog(de.danoeh.antennapod.dialog.StreamingConfirmationDialog)

Aggregations

PlaybackServiceStarter (de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter)2 StreamingConfirmationDialog (de.danoeh.antennapod.dialog.StreamingConfirmationDialog)2 LayoutInflater (android.view.LayoutInflater)1 NonNull (androidx.annotation.NonNull)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)1 Playable (de.danoeh.antennapod.model.playback.Playable)1 RemoteMedia (de.danoeh.antennapod.model.playback.RemoteMedia)1