更新界面

This commit is contained in:
HapeLee committed 2025-06-12 01:27:36 +08:00
1 parent a6b1a41605
commit 9949f32909
3 files changed
+72 -11

No files matched your search

@@ -1,10 +1,14 @@
package io.legato.kazusa.ui.widget
import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent
import android.widget.FrameLayout
import android.widget.SeekBar
import androidx.annotation.RequiresApi
import androidx.appcompat.widget.TooltipCompat
import com.google.android.material.slider.Slider
import io.legato.kazusa.R
@@ -12,8 +16,11 @@ import io.legato.kazusa.databinding.ViewDetailSeekBarBinding
//import io.legado.app.lib.theme.bottomBackground
//import io.legado.app.lib.theme.getPrimaryTextColor
import io.legato.kazusa.ui.widget.seekbar.SeekBarChangeListener
import kotlin.math.abs
@RequiresApi(Build.VERSION_CODES.O)
@SuppressLint("ClickableViewAccessibility")
class DetailSeekBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
@@ -46,10 +53,13 @@ class DetailSeekBar @JvmOverloads constructor(
isBottomBackground =
typedArray.getBoolean(R.styleable.DetailSeekBar_isBottomBackground, false)
val title = typedArray.getText(R.styleable.DetailSeekBar_title)
binding.tvSeekTitle.apply {
text = title
TooltipCompat.setTooltipText(this, title)
}
binding.slider.valueTo = typedArray.getInteger(R.styleable.DetailSeekBar_max, 0).toFloat()
typedArray.recycle()
binding.ivSeekPlus.setOnClickListener {
@@ -82,6 +92,24 @@ class DetailSeekBar @JvmOverloads constructor(
onChanged?.invoke(slider.value.toInt())
}
})
binding.slider.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
val slider = binding.slider
val sliderWidth = slider.width - slider.paddingStart - slider.paddingEnd
val touchX = event.x - slider.paddingStart
val proportion = (slider.value - slider.valueFrom) / (slider.valueTo - slider.valueFrom)
val thumbCenterX = proportion * sliderWidth
val thumbRadiusPx = slider.thumbRadius * 2f // 可适当扩大滑块判断区域
val isTouchNearThumb = kotlin.math.abs(touchX - thumbCenterX) <= thumbRadiusPx
return@setOnTouchListener !isTouchNearThumb // 拦截不是点在滑块上的点击
}
return@setOnTouchListener false
}
}
private fun upValue(progress: Int = binding.slider.value.toInt()) {
@@ -96,11 +124,4 @@ class DetailSeekBar @JvmOverloads constructor(
upValue(progress)
}
// override fun onStartTrackingTouch(seekBar: SeekBar) {
//
// }
//
// override fun onStopTrackingTouch(seekBar: SeekBar) {
// onChanged?.invoke(binding.slider.progress)
// }
}