Explorar el Código

Merge branch '143-mediaboxseekbar-crash' into 'master'

Resolve "MediaBoxSeekBar crash"

Closes #143

See merge request kdanandroid/pdf/pdfreaderreadermodule!74
Wayne Huang hace 4 años
padre
commit
8d5e20d338

+ 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
         }