Skip to content

Commit

Permalink
fix: improve nullability checks and fix mem leak in SequenceStepDot (#77
Browse files Browse the repository at this point in the history
)
  • Loading branch information
saschoar authored Oct 25, 2023
1 parent d998c44 commit a6e5ed1
Showing 1 changed file with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,38 @@ internal class SequenceStepDot @JvmOverloads constructor(
}

private fun setupAnimator() {
pulseAnimator = AnimatorInflater.loadAnimator(context, R.animator.fading_pulse) as AnimatorSet
pulseAnimator!!.setTarget(pulseView)
pulseAnimator!!.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animator: Animator) {
if (isActivated) {
animator.start()
}
pulseAnimator =
(AnimatorInflater.loadAnimator(context, R.animator.fading_pulse) as AnimatorSet).apply {
setTarget(pulseView)
addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animator: Animator) {
if (isActivated) {
animator.start()
}
}
})
start()
}
})
}

private fun startAnimation() {
if (pulseAnimator == null) {
setupAnimator()
}
if (pulseAnimator!!.isStarted) {
return
pulseAnimator.let {
if (it == null) {
setupAnimator()
} else if (it.isStarted) {
return
}
pulseView.visibility = VISIBLE
}

pulseView.visibility = VISIBLE
pulseAnimator!!.start()
}

private fun stopAnimation() {
if (pulseAnimator == null || !pulseAnimator!!.isStarted) {
return
pulseAnimator.let {
if (it == null || !it.isStarted) {
return
}
it.end()
}
pulseAnimator!!.end()
pulseView.visibility = GONE
}

Expand All @@ -122,7 +126,11 @@ internal class SequenceStepDot @JvmOverloads constructor(
}

override fun onDetachedFromWindow() {
pulseAnimator?.cancel()
pulseAnimator?.apply {
removeAllListeners()
cancel()
}
pulseAnimator = null
super.onDetachedFromWindow()
}
}

0 comments on commit a6e5ed1

Please sign in to comment.