浏览代码

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

Resolve "MediaBoxSeekBar crash"

Closes #143

See merge request kdanandroid/pdf/pdfreaderreadermodule!74
Wayne Huang 4 年之前
父节点
当前提交
8d5e20d338
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      src/main/java/com/kdanmobile/reader/screen/reader/mediabox/common/MediaBoxSeekBar.kt

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