From de3d0d85152e668bd5724e6202bf728dcba2a226 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Sun, 5 Jul 2020 22:00:28 +0200 Subject: [PATCH] Fix an issue where the progress bar refresher ran in a tight loop If the animator scale setting is set to 0, the progress bar refresher would run in a tight loop. This issue was introduced by 93cc945a2c9cd1cdaefc745b33a196cdeec198ac and caused the UI tests to fail. --- .../beemdevelopment/aegis/ui/views/TotpProgressBar.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/TotpProgressBar.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/TotpProgressBar.java index 53e8a6f2..fc83a585 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/TotpProgressBar.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/TotpProgressBar.java @@ -66,11 +66,12 @@ public class TotpProgressBar extends ProgressBar { // start progress animation, compensating for any changes to the animator duration scale settings float animPart = (float) maxProgress / _period; - int animEnd = (int) ((currentProgress / animPart) * animPart); - int animPartDuration = (int) (1000 / _animDurationScale); + int animEnd = (int) (Math.floor(currentProgress / animPart) * animPart); + int animPartDuration = _animDurationScale > 0 ? (int) (1000 / _animDurationScale) : 0; float animDurationFraction = (float) (currentProgress - animEnd) / animPart; - int realAnimDuration = (int) (1000 * animDurationFraction); + int realAnimDuration = (int) (1000 * animDurationFraction); int animDuration = (int) (animPartDuration * animDurationFraction); + ObjectAnimator animation = ObjectAnimator.ofInt(this, "progress", currentProgress, animEnd); animation.setDuration(animDuration); animation.setInterpolator(new LinearInterpolator());