From e43b39aff1108aa7f1cf28c2c617abaf8218bad1 Mon Sep 17 00:00:00 2001 From: booker-lee Date: Sun, 11 Sep 2022 16:14:45 +0800 Subject: [PATCH] Fix hp display when value is under 1 #1842 The cause of this issue comes from the ValueAnimator. The under 1 value is truncated due to the cast to int in ValueAnimator. Add animation for floating point values (when value is between 0 ~ 1) --- .../java/com/habitrpg/common/habitica/views/ValueBar.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/habitrpg/common/habitica/views/ValueBar.kt b/common/src/main/java/com/habitrpg/common/habitica/views/ValueBar.kt index 54d70ad78..2e3a4a87b 100644 --- a/common/src/main/java/com/habitrpg/common/habitica/views/ValueBar.kt +++ b/common/src/main/java/com/habitrpg/common/habitica/views/ValueBar.kt @@ -184,11 +184,16 @@ class ValueBar(context: Context, attrs: AttributeSet?) : FrameLayout(context, at if (animationDuration == 0L || binding.valueTextView.text.isEmpty()) { currentValue = value } else { - val animator = ValueAnimator.ofInt(currentValue.toInt(), value.toInt()) + val animator = if (0 < value && value < 1) { + // Show floating points in animation only if the value is between 0 to 1 + ValueAnimator.ofFloat(currentValue.toFloat(), value.toFloat()) + } else { + ValueAnimator.ofInt(currentValue.toInt(), value.toInt()) + } animator.duration = animationDuration animator.startDelay = animationDelay animator.addUpdateListener { - currentValue = (it.animatedValue as Int).toDouble() + currentValue = (it.animatedValue as? Int)?.toDouble() ?: (it.animatedValue as Float).toDouble() updateBar() } animator.start()