Add additional safeguards for picking an expiration timer frame.

Fixes #8010
This commit is contained in:
Greyson Parrelli 2018-07-20 14:08:58 -07:00
parent d303a88803
commit d0eaee60e9

View File

@ -54,6 +54,8 @@ public class ExpirationTimerView extends android.support.v7.widget.AppCompatImag
public void setPercentComplete(float percentage) { public void setPercentComplete(float percentage) {
float percentFull = 1 - percentage; float percentFull = 1 - percentage;
int frame = (int) Math.ceil(percentFull * (frames.length - 1)); int frame = (int) Math.ceil(percentFull * (frames.length - 1));
frame = Math.max(0, Math.min(frame, frames.length - 1));
setImageResource(frames[frame]); setImageResource(frames[frame]);
} }
@ -77,7 +79,7 @@ public class ExpirationTimerView extends android.support.v7.widget.AppCompatImag
long progressed = System.currentTimeMillis() - startedAt; long progressed = System.currentTimeMillis() - startedAt;
float percentComplete = (float)progressed / (float)expiresIn; float percentComplete = (float)progressed / (float)expiresIn;
return Math.min(percentComplete, 1); return Math.max(0, Math.min(percentComplete, 1));
} }
private long calculateAnimationDelay(long startedAt, long expiresIn) { private long calculateAnimationDelay(long startedAt, long expiresIn) {