Skip to content

Commit

Permalink
potential memory leak fix
Browse files Browse the repository at this point in the history
  • Loading branch information
apprajapati9 committed Mar 22, 2024
1 parent 832ce92 commit 0ebeb3e
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CircularLoadingView @JvmOverloads constructor(context: Context, attributeS
private var outerCirclePaint = Paint()
private var shownOuter = false

private val mAnimator = ValueAnimator()
private var animStatus = true
init {
val setValues =
context.obtainStyledAttributes(attributeSet, R.styleable.CircularLoadingView, 0, 0)
Expand Down Expand Up @@ -106,26 +108,36 @@ class CircularLoadingView @JvmOverloads constructor(context: Context, attributeS

override fun setVisibility(visibility: Int) {
if(visibility == GONE || visibility == INVISIBLE){

animStatus = false
// mAnimator.cancel()
}else{
animateProgress()
animStatus = true
}

animateProgress()

super.setVisibility(visibility)
}

override fun onDetachedFromWindow() {
mAnimator.removeAllUpdateListeners()
mAnimator.cancel()
super.onDetachedFromWindow()
}


fun animateProgress() {

if (visibility != VISIBLE || windowVisibility != VISIBLE) {
return
}else{
}else if(animStatus){
val colorValues = getColorRange() //0 being black and 255 being white.

Handler(Looper.getMainLooper()).postDelayed({
shownOuter = true
}, 300)

ValueAnimator().apply {
mAnimator.apply {
setValues(PropertyValuesHolder.ofFloat("progressValue", 0f, minHeight), colorValues)
duration = animationDuration.toLong()
repeatCount = ValueAnimator.INFINITE
Expand Down

0 comments on commit 0ebeb3e

Please sign in to comment.