Browse Source

Fix: MediaBoxSeekBar crash issue

caused by infinite recursive(stack over flow)
Wayne 4 years ago
parent
commit
762df62848

+ 5 - 3
src/main/java/com/kdanmobile/reader/screen/reader/mediabox/common/MediaBoxSeekBar.kt

@@ -3,11 +3,11 @@ package com.kdanmobile.reader.screen.reader.mediabox.common
 import android.content.Context
 import android.graphics.PorterDuff
 import android.os.Build
-import androidx.constraintlayout.widget.ConstraintLayout
-import androidx.core.content.ContextCompat
 import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.widget.SeekBar
+import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.core.content.ContextCompat
 import com.kdanmobile.reader.R
 import kotlinx.android.synthetic.main.view_media_box_seekbar.view.*
 
@@ -37,7 +37,9 @@ class MediaBoxSeekBar : ConstraintLayout {
 
     var currentValue = 0
         set(value) {
-            field = Math.max(Math.min(value, maxValue), minValue)
+            val v = value.coerceIn(minValue, maxValue)
+            if (field == v) return
+            field = v
             tv_mediaBoxSeekBar_value?.text = "${formatter.format(currentValue)}$unit"
             seekBar_mediaBoxSeekBar?.progress = field - minValue
         }