From 655e3c6e4e424bebaf77b903cae60ffaea5d1416 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 3 Dec 2022 12:33:59 +0100 Subject: [PATCH] Hide progress bar when there is no progress --- .../viewholder/HorizontalItemViewHolder.java | 21 +++++++++++++++---- .../res/layout/horizontal_itemlist_item.xml | 10 ++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java index 42b0cb57c..83d589518 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java +++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/HorizontalItemViewHolder.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.view.viewholder; import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ProgressBar; @@ -31,6 +32,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { private final TextView date; private final ProgressBar progressBar; private final CircularProgressBar circularProgressBar; + private final View progressBarReplacementSpacer; private final MainActivity activity; private FeedItem item; @@ -46,6 +48,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { secondaryActionIcon = itemView.findViewById(R.id.secondaryActionIcon); circularProgressBar = itemView.findViewById(R.id.circularProgressBar); progressBar = itemView.findViewById(R.id.progressBar); + progressBarReplacementSpacer = itemView.findViewById(R.id.progressBarReplacementSpacer); itemView.setTag(this); } @@ -67,6 +70,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { FeedMedia media = item.getMedia(); if (media == null) { circularProgressBar.setPercentage(0, item); + setProgressBar(false, 0); } else { if (PlaybackStatus.isCurrentlyPlaying(media)) { card.setCardBackgroundColor(ThemeUtils.getColorFromAttr(activity, R.attr.card_background_playing)); @@ -74,9 +78,12 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { card.setCardBackgroundColor(ThemeUtils.getColorFromAttr(activity, R.attr.card_background)); } - if (item.getMedia().getDuration() > 0) { - progressBar.setProgress(100 * item.getMedia().getPosition() / item.getMedia().getDuration()); + if (item.getMedia().getDuration() > 0 && item.getMedia().getPosition() > 0) { + setProgressBar(true, 100.0f * item.getMedia().getPosition() / item.getMedia().getDuration()); + } else { + setProgressBar(false, 0); } + if (DownloadService.isDownloadingFile(media.getDownload_url())) { final DownloadRequest downloadRequest = DownloadService.findRequest(media.getDownload_url()); float percent = 0.01f * downloadRequest.getProgressPercent(); @@ -99,7 +106,7 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { date.setText("███"); secondaryActionIcon.setImageDrawable(null); circularProgressBar.setPercentage(0, null); - progressBar.setProgress(50); + setProgressBar(true, 50); } public boolean isCurrentlyPlayingItem() { @@ -107,6 +114,12 @@ public class HorizontalItemViewHolder extends RecyclerView.ViewHolder { } public void notifyPlaybackPositionUpdated(PlaybackPositionEvent event) { - progressBar.setProgress((int) (100.0 * event.getPosition() / event.getDuration())); + setProgressBar(true, 100.0f * event.getPosition() / event.getDuration()); + } + + private void setProgressBar(boolean visible, float progress) { + progressBar.setVisibility(visible ? ViewGroup.VISIBLE : ViewGroup.GONE); + progressBarReplacementSpacer.setVisibility(visible ? View.GONE : ViewGroup.VISIBLE); + progressBar.setProgress(Math.max(5, (int) progress)); // otherwise invisible below the edge radius } } diff --git a/app/src/main/res/layout/horizontal_itemlist_item.xml b/app/src/main/res/layout/horizontal_itemlist_item.xml index b69a3f445..bb45d0ca1 100644 --- a/app/src/main/res/layout/horizontal_itemlist_item.xml +++ b/app/src/main/res/layout/horizontal_itemlist_item.xml @@ -93,6 +93,12 @@ + + + android:textSize="14sp" + tools:text="@sample/episodes.json/data/title" />