From 9dda89f891e8359545ddeb7bcb87c1b2867c5536 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sun, 19 May 2024 08:37:47 +0200 Subject: [PATCH] feat(Poll): scale animation based on votes Updates the animation timing, to be based on the amount of votes a option recieved 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. --- .../android/ui/displayitems/PollOptionStatusDisplayItem.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java index e1bfb5c7a2..6b59255a30 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java @@ -150,10 +150,11 @@ public void showResults(boolean shown) { 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 void showResults(boolean shown) { // 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();