mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Fix memory leaks reported by LeakCanary but ending infinite animations when Activity is paused (#2103)
This commit is contained in:
parent
b0fae9418c
commit
376c8b37b9
2 changed files with 28 additions and 8 deletions
|
|
@ -397,4 +397,17 @@ class ArmoireActivity : BaseActivity() {
|
|||
dialog.setContentView(R.layout.armoire_drop_rate_dialog)
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
// Clear infinite animations on pause to make sure Context references aren't leaked.
|
||||
stopInfiniteAnimations()
|
||||
}
|
||||
|
||||
private fun stopInfiniteAnimations() {
|
||||
binding.leftSparkView.stopAnimating()
|
||||
binding.rightSparkView.stopAnimating()
|
||||
binding.iconView.animation?.cancel()
|
||||
binding.iconView.animation = null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ constructor(
|
|||
invalidate()
|
||||
}
|
||||
private var paint: Paint = Paint()
|
||||
private var animator: ValueAnimator? = null
|
||||
|
||||
var thickness = 3.dpToPx(context)
|
||||
var length = 6.dpToPx(context)
|
||||
|
|
@ -59,15 +60,16 @@ constructor(
|
|||
}
|
||||
|
||||
fun startAnimating() {
|
||||
val anim = ObjectAnimator.ofFloat(thickness.toFloat(), maxSpacing.toFloat())
|
||||
anim.addUpdateListener {
|
||||
spacing = it.animatedValue as Float
|
||||
animator = ObjectAnimator.ofFloat(thickness.toFloat(), maxSpacing.toFloat()).apply {
|
||||
addUpdateListener {
|
||||
spacing = it.animatedValue as Float
|
||||
}
|
||||
interpolator = AccelerateDecelerateInterpolator()
|
||||
repeatCount = Animation.INFINITE
|
||||
repeatMode = ValueAnimator.REVERSE
|
||||
duration = animationDuration
|
||||
start()
|
||||
}
|
||||
anim.interpolator = AccelerateDecelerateInterpolator()
|
||||
anim.repeatCount = Animation.INFINITE
|
||||
anim.repeatMode = ValueAnimator.REVERSE
|
||||
anim.duration = animationDuration
|
||||
anim.start()
|
||||
}
|
||||
|
||||
override fun onMeasure(
|
||||
|
|
@ -139,4 +141,9 @@ constructor(
|
|||
paint
|
||||
)
|
||||
}
|
||||
|
||||
fun stopAnimating() {
|
||||
animator?.end()
|
||||
animator = null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue