Skip to content

Commit

Permalink
improve nullability checks and fix mem leak in SequenceStepDot
Browse files Browse the repository at this point in the history
  • Loading branch information
saschoar committed Oct 24, 2023
1 parent cffa592 commit 628949f
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(context: Context, attrs: AttributeSet?, defStyleA
}

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(context: Context, attrs: AttributeSet?, defStyleA
}

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

0 comments on commit 628949f

Please sign in to comment.