diff options
author | Tony Tam <149837+tonytamsf@users.noreply.github.com> | 2021-04-02 05:30:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 14:30:21 +0200 |
commit | 843892e34fb2ca04bf3f5b0f6fce7e45285e0ecd (patch) | |
tree | 713e37192f35d7c94deb5703d1446fbbcbf023be /app/src/main/java/de/danoeh/antennapod/view | |
parent | 6b9821a1f9c674972813522034626a7491248c4d (diff) | |
download | AntennaPod-843892e34fb2ca04bf3f5b0f6fce7e45285e0ecd.zip |
Safer remain time - default to zero when the media duration is wrong (#5043)
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/view')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java index 8b46a781f..9fd742d5f 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java +++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java @@ -154,6 +154,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { Converter.getDurationStringLocalized(activity, media.getDuration()))); if (item.getState() == FeedItem.State.PLAYING || item.getState() == FeedItem.State.IN_PROGRESS) { int progress = (int) (100.0 * media.getPosition() / media.getDuration()); + int remainingTime = Math.max(media.getDuration() - media.getPosition(), 0); progressBar.setProgress(progress); position.setText(Converter.getDurationStringLong(media.getPosition())); position.setContentDescription(activity.getString(R.string.position, @@ -161,7 +162,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { progressBar.setVisibility(View.VISIBLE); position.setVisibility(View.VISIBLE); if (UserPreferences.shouldShowRemainingTime()) { - duration.setText("-" + Converter.getDurationStringLong(media.getDuration() - media.getPosition())); + duration.setText(((remainingTime > 0) ? "-" : "") + Converter.getDurationStringLong(remainingTime)); duration.setContentDescription(activity.getString(R.string.chapter_duration, Converter.getDurationStringLocalized(activity, (media.getDuration() - media.getPosition())))); } @@ -194,14 +195,14 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder { private void updateDuration(PlaybackPositionEvent event) { int currentPosition = event.getPosition(); int timeDuration = event.getDuration(); - int remainingTime = event.getDuration() - event.getPosition(); + int remainingTime = Math.max(timeDuration - currentPosition, 0); Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition)); if (currentPosition == PlaybackService.INVALID_TIME || timeDuration == PlaybackService.INVALID_TIME) { Log.w(TAG, "Could not react to position observer update because of invalid time"); return; } if (UserPreferences.shouldShowRemainingTime()) { - duration.setText("-" + Converter.getDurationStringLong(remainingTime)); + duration.setText(((remainingTime > 0) ? "-" : "") + Converter.getDurationStringLong(remainingTime)); } else { duration.setText(Converter.getDurationStringLong(timeDuration)); } |