Merge pull request #1853 from booker-lee/1842-fix-hp-under-1

Fix hp display when value is under 1 #1842
This commit is contained in:
Phillip Thelen 2022-12-05 17:45:34 +01:00 committed by GitHub
commit 5d9f2d4b5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()