@@ -72,34 +72,38 @@ internal class SequenceStepDot @JvmOverloads constructor(
72
72
}
73
73
74
74
private fun setupAnimator () {
75
- pulseAnimator = AnimatorInflater .loadAnimator(context, R .animator.fading_pulse) as AnimatorSet
76
- pulseAnimator!! .setTarget(pulseView)
77
- pulseAnimator!! .addListener(object : AnimatorListenerAdapter () {
78
- override fun onAnimationEnd (animator : Animator ) {
79
- if (isActivated) {
80
- animator.start()
81
- }
75
+ pulseAnimator =
76
+ (AnimatorInflater .loadAnimator(context, R .animator.fading_pulse) as AnimatorSet ).apply {
77
+ setTarget(pulseView)
78
+ addListener(object : AnimatorListenerAdapter () {
79
+ override fun onAnimationEnd (animator : Animator ) {
80
+ if (isActivated) {
81
+ animator.start()
82
+ }
83
+ }
84
+ })
85
+ start()
82
86
}
83
- })
84
87
}
85
88
86
89
private fun startAnimation () {
87
- if (pulseAnimator == null ) {
88
- setupAnimator()
89
- }
90
- if (pulseAnimator!! .isStarted) {
91
- return
90
+ pulseAnimator.let {
91
+ if (it == null ) {
92
+ setupAnimator()
93
+ } else if (it.isStarted) {
94
+ return
95
+ }
96
+ pulseView.visibility = VISIBLE
92
97
}
93
-
94
- pulseView.visibility = VISIBLE
95
- pulseAnimator!! .start()
96
98
}
97
99
98
100
private fun stopAnimation () {
99
- if (pulseAnimator == null || ! pulseAnimator!! .isStarted) {
100
- return
101
+ pulseAnimator.let {
102
+ if (it == null || ! it.isStarted) {
103
+ return
104
+ }
105
+ it.end()
101
106
}
102
- pulseAnimator!! .end()
103
107
pulseView.visibility = GONE
104
108
}
105
109
@@ -122,7 +126,11 @@ internal class SequenceStepDot @JvmOverloads constructor(
122
126
}
123
127
124
128
override fun onDetachedFromWindow () {
125
- pulseAnimator?.cancel()
129
+ pulseAnimator?.apply {
130
+ removeAllListeners()
131
+ cancel()
132
+ }
133
+ pulseAnimator = null
126
134
super .onDetachedFromWindow()
127
135
}
128
136
}
0 commit comments