Search in sources :

Example 1 with DownloadActionButton

use of de.danoeh.antennapod.adapter.actionbutton.DownloadActionButton in project AntennaPod by AntennaPod.

the class ItemFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View layout = inflater.inflate(R.layout.feeditem_fragment, container, false);
    root = layout.findViewById(R.id.content_root);
    txtvPodcast = layout.findViewById(R.id.txtvPodcast);
    txtvPodcast.setOnClickListener(v -> openPodcast());
    txtvTitle = layout.findViewById(R.id.txtvTitle);
    if (Build.VERSION.SDK_INT >= 23) {
        txtvTitle.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL);
    }
    txtvDuration = layout.findViewById(R.id.txtvDuration);
    txtvPublished = layout.findViewById(R.id.txtvPublished);
    txtvTitle.setEllipsize(TextUtils.TruncateAt.END);
    webvDescription = layout.findViewById(R.id.webvDescription);
    webvDescription.setTimecodeSelectedListener(time -> {
        if (controller != null && item.getMedia() != null && controller.getMedia() != null && Objects.equals(item.getMedia().getIdentifier(), controller.getMedia().getIdentifier())) {
            controller.seekTo(time);
        } else {
            ((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.play_this_to_seek_position, Snackbar.LENGTH_LONG);
        }
    });
    registerForContextMenu(webvDescription);
    imgvCover = layout.findViewById(R.id.imgvCover);
    imgvCover.setOnClickListener(v -> openPodcast());
    progbarDownload = layout.findViewById(R.id.progbarDownload);
    progbarLoading = layout.findViewById(R.id.progbarLoading);
    butAction1 = layout.findViewById(R.id.butAction1);
    butAction2 = layout.findViewById(R.id.butAction2);
    butAction1Icon = layout.findViewById(R.id.butAction1Icon);
    butAction2Icon = layout.findViewById(R.id.butAction2Icon);
    butAction1Text = layout.findViewById(R.id.butAction1Text);
    butAction2Text = layout.findViewById(R.id.butAction2Text);
    noMediaLabel = layout.findViewById(R.id.noMediaLabel);
    butAction1.setOnClickListener(v -> {
        if (actionButton1 instanceof StreamActionButton && !UserPreferences.isStreamOverDownload() && UsageStatistics.hasSignificantBiasTo(UsageStatistics.ACTION_STREAM)) {
            showOnDemandConfigBalloon(true);
            return;
        }
        actionButton1.onClick(getContext());
    });
    butAction2.setOnClickListener(v -> {
        if (actionButton2 instanceof DownloadActionButton && UserPreferences.isStreamOverDownload() && UsageStatistics.hasSignificantBiasTo(UsageStatistics.ACTION_DOWNLOAD)) {
            showOnDemandConfigBalloon(false);
            return;
        }
        actionButton2.onClick(getContext());
    });
    return layout;
}
Also used : StreamActionButton(de.danoeh.antennapod.adapter.actionbutton.StreamActionButton) MainActivity(de.danoeh.antennapod.activity.MainActivity) CancelDownloadActionButton(de.danoeh.antennapod.adapter.actionbutton.CancelDownloadActionButton) DownloadActionButton(de.danoeh.antennapod.adapter.actionbutton.DownloadActionButton) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ShownotesWebView(de.danoeh.antennapod.view.ShownotesWebView)

Example 2 with DownloadActionButton

use of de.danoeh.antennapod.adapter.actionbutton.DownloadActionButton in project AntennaPod by AntennaPod.

the class ItemFragment method updateButtons.

private void updateButtons() {
    progbarDownload.setVisibility(View.GONE);
    if (item.hasMedia() && downloaderList != null) {
        for (Downloader downloader : downloaderList) {
            if (downloader.getDownloadRequest().getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA && downloader.getDownloadRequest().getFeedfileId() == item.getMedia().getId()) {
                progbarDownload.setVisibility(View.VISIBLE);
                progbarDownload.setProgress(downloader.getDownloadRequest().getProgressPercent());
            }
        }
    }
    FeedMedia media = item.getMedia();
    if (media == null) {
        actionButton1 = new MarkAsPlayedActionButton(item);
        actionButton2 = new VisitWebsiteActionButton(item);
        noMediaLabel.setVisibility(View.VISIBLE);
    } else {
        noMediaLabel.setVisibility(View.GONE);
        if (media.getDuration() > 0) {
            txtvDuration.setText(Converter.getDurationStringLong(media.getDuration()));
            txtvDuration.setContentDescription(Converter.getDurationStringLocalized(getContext(), media.getDuration()));
        }
        if (FeedItemUtil.isCurrentlyPlaying(media)) {
            actionButton1 = new PauseActionButton(item);
        } else if (item.getFeed().isLocalFeed()) {
            actionButton1 = new PlayLocalActionButton(item);
        } else if (media.isDownloaded()) {
            actionButton1 = new PlayActionButton(item);
        } else {
            actionButton1 = new StreamActionButton(item);
        }
        if (DownloadService.isDownloadingFile(media.getDownload_url())) {
            actionButton2 = new CancelDownloadActionButton(item);
        } else if (!media.isDownloaded()) {
            actionButton2 = new DownloadActionButton(item);
        } else {
            actionButton2 = new DeleteActionButton(item);
        }
    }
    butAction1Text.setText(actionButton1.getLabel());
    butAction1Text.setTransformationMethod(null);
    butAction1Icon.setImageResource(actionButton1.getDrawable());
    butAction1.setVisibility(actionButton1.getVisibility());
    butAction2Text.setText(actionButton2.getLabel());
    butAction2Text.setTransformationMethod(null);
    butAction2Icon.setImageResource(actionButton2.getDrawable());
    butAction2.setVisibility(actionButton2.getVisibility());
}
Also used : StreamActionButton(de.danoeh.antennapod.adapter.actionbutton.StreamActionButton) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia) PlayActionButton(de.danoeh.antennapod.adapter.actionbutton.PlayActionButton) PlayLocalActionButton(de.danoeh.antennapod.adapter.actionbutton.PlayLocalActionButton) CancelDownloadActionButton(de.danoeh.antennapod.adapter.actionbutton.CancelDownloadActionButton) DeleteActionButton(de.danoeh.antennapod.adapter.actionbutton.DeleteActionButton) Downloader(de.danoeh.antennapod.core.service.download.Downloader) VisitWebsiteActionButton(de.danoeh.antennapod.adapter.actionbutton.VisitWebsiteActionButton) CancelDownloadActionButton(de.danoeh.antennapod.adapter.actionbutton.CancelDownloadActionButton) DownloadActionButton(de.danoeh.antennapod.adapter.actionbutton.DownloadActionButton) MarkAsPlayedActionButton(de.danoeh.antennapod.adapter.actionbutton.MarkAsPlayedActionButton) PauseActionButton(de.danoeh.antennapod.adapter.actionbutton.PauseActionButton)

Aggregations

CancelDownloadActionButton (de.danoeh.antennapod.adapter.actionbutton.CancelDownloadActionButton)2 DownloadActionButton (de.danoeh.antennapod.adapter.actionbutton.DownloadActionButton)2 StreamActionButton (de.danoeh.antennapod.adapter.actionbutton.StreamActionButton)2 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)1 DeleteActionButton (de.danoeh.antennapod.adapter.actionbutton.DeleteActionButton)1 MarkAsPlayedActionButton (de.danoeh.antennapod.adapter.actionbutton.MarkAsPlayedActionButton)1 PauseActionButton (de.danoeh.antennapod.adapter.actionbutton.PauseActionButton)1 PlayActionButton (de.danoeh.antennapod.adapter.actionbutton.PlayActionButton)1 PlayLocalActionButton (de.danoeh.antennapod.adapter.actionbutton.PlayLocalActionButton)1 VisitWebsiteActionButton (de.danoeh.antennapod.adapter.actionbutton.VisitWebsiteActionButton)1 Downloader (de.danoeh.antennapod.core.service.download.Downloader)1 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)1 ShownotesWebView (de.danoeh.antennapod.view.ShownotesWebView)1