feat(Poll): scale animation based on votes

Updates the animation timing, to be based on the amount of votes a
option received relative to the other options. This means a option with
more votes will run longer than one with less votes. Overall this makes
the animation appear more dynamic and smoother.
This commit is contained in:
FineFindus
2024-05-19 08:37:47 +02:00
parent 44e3e5faaf
commit 169fbc2d52

View File

@@ -150,10 +150,11 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
item.showResults = shown;
item.calculateResults();
Drawable bg=progressBg;
long animationDuration = (long) (ANIMATION_DURATION*item.votesFraction);
int startLevel=shown ? 0 : progressBg.getLevel();
int targetLevel=shown ? Math.round(10000f*item.votesFraction) : 0;
ObjectAnimator animator=ObjectAnimator.ofInt(bg, "level", startLevel, targetLevel);
animator.setDuration(ANIMATION_DURATION);
animator.setDuration(animationDuration);
animator.setInterpolator(new DecelerateInterpolator());
button.setBackground(bg);
if(shown){
@@ -161,7 +162,7 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
// animate percent
percent.setVisibility(View.VISIBLE);
ValueAnimator percentAnimation=ValueAnimator.ofInt(0, Math.round(100f*item.votesFraction));
percentAnimation.setDuration(ANIMATION_DURATION);
percentAnimation.setDuration(animationDuration);
percentAnimation.setInterpolator(new DecelerateInterpolator());
percentAnimation.addUpdateListener(animation -> percent.setText(String.format(Locale.getDefault(), "%d%%", (int) animation.getAnimatedValue())));
percentAnimation.start();