Hide progress bar when there is no progress

This commit is contained in:
ByteHamster 2022-12-03 12:33:59 +01:00
parent bc3b717911
commit 655e3c6e4e
2 changed files with 26 additions and 5 deletions

View File

@ -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
}
}

View File

@ -93,6 +93,12 @@
</androidx.cardview.widget.CardView>
<View
android:id="@+id/progressBarReplacementSpacer"
android:layout_width="match_parent"
android:layout_height="4dp"
android:visibility="gone" />
<TextView
android:id="@+id/titleLabel"
android:layout_width="128dp"
@ -103,7 +109,8 @@
android:paddingHorizontal="4dp"
android:singleLine="false"
android:textColor="?android:attr/textColorPrimary"
android:textSize="14sp" />
android:textSize="14sp"
tools:text="@sample/episodes.json/data/title" />
<TextView
android:id="@+id/dateLabel"
@ -114,6 +121,7 @@
android:singleLine="true"
android:textAlignment="textStart"
android:textSize="14sp"
tools:text="@sample/episodes.json/data/published_at"
style="@style/AntennaPod.TextView.ListItemSecondaryTitle" />
</LinearLayout>