更新界面

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,18 +1,57 @@
package io.legato.kazusa.lib.theme.view package io.legato.kazusa.lib.theme.view
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.MotionEvent
import com.google.android.material.slider.Slider import com.google.android.material.slider.Slider
import kotlin.math.abs
//import io.legado.app.lib.theme.accentColor //import io.legado.app.lib.theme.accentColor
/** /**
* @author Aidan Follestad (afollestad) * @author Aidan Follestad (afollestad)
*/ */
class ThemeSlider(context: Context, attrs: AttributeSet) : Slider(context, attrs) { class ThemeSlider(context: Context, attrs: AttributeSet) : Slider(context, attrs) {
// init { // private var isDragging = false
// if (!isInEditMode) {
// applyTint(context.accentColor) // @SuppressLint("ClickableViewAccessibility")
// override fun onTouchEvent(event: MotionEvent): Boolean {
// when (event.action) {
// MotionEvent.ACTION_DOWN -> {
// // 检查是否点击在滑块上
// isDragging = isPointOnThumb(event.x, event.y)
// if (!isDragging) {
// // 如果点击不在滑块上,不处理事件
// return false
// } // }
// } // }
// MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
// isDragging = false
// }
// }
//
// // 只有在拖动状态下或者在滑块上点击时才处理事件
// return (isDragging || isPointOnThumb(event.x, event.y)) && super.onTouchEvent(event)
// }
//
// // 检查触摸点是否在滑块上
// private fun isPointOnThumb(x: Float, y: Float): Boolean {
// // 计算滑块位置
// val valueRange = valueTo - valueFrom
// val proportion = if (valueRange != 0f) (value - valueFrom) / valueRange else 0f
//
// // 计算滑块中心X坐标
// val sliderWidth = width
// val sliderLeft = paddingLeft.toFloat()
// val thumbCenterX = sliderLeft + proportion * sliderWidth
//
//
// // 检查触摸点是否在滑块区域内
// return x >= thumbCenterX - thumbRadius && x <= thumbCenterX + thumbRadius
// }
} }
@@ -1,10 +1,14 @@
package io.legato.kazusa.ui.widget package io.legato.kazusa.ui.widget
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.os.Build
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.SeekBar import android.widget.SeekBar
import androidx.annotation.RequiresApi
import androidx.appcompat.widget.TooltipCompat import androidx.appcompat.widget.TooltipCompat
import com.google.android.material.slider.Slider import com.google.android.material.slider.Slider
import io.legato.kazusa.R 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.bottomBackground
//import io.legado.app.lib.theme.getPrimaryTextColor //import io.legado.app.lib.theme.getPrimaryTextColor
import io.legato.kazusa.ui.widget.seekbar.SeekBarChangeListener import io.legato.kazusa.ui.widget.seekbar.SeekBarChangeListener
import kotlin.math.abs
@RequiresApi(Build.VERSION_CODES.O)
@SuppressLint("ClickableViewAccessibility")
class DetailSeekBar @JvmOverloads constructor( class DetailSeekBar @JvmOverloads constructor(
context: Context, context: Context,
attrs: AttributeSet? = null attrs: AttributeSet? = null
@@ -46,10 +53,13 @@ class DetailSeekBar @JvmOverloads constructor(
isBottomBackground = isBottomBackground =
typedArray.getBoolean(R.styleable.DetailSeekBar_isBottomBackground, false) typedArray.getBoolean(R.styleable.DetailSeekBar_isBottomBackground, false)
val title = typedArray.getText(R.styleable.DetailSeekBar_title) val title = typedArray.getText(R.styleable.DetailSeekBar_title)
binding.tvSeekTitle.apply { binding.tvSeekTitle.apply {
text = title text = title
TooltipCompat.setTooltipText(this, title) TooltipCompat.setTooltipText(this, title)
} }
binding.slider.valueTo = typedArray.getInteger(R.styleable.DetailSeekBar_max, 0).toFloat() binding.slider.valueTo = typedArray.getInteger(R.styleable.DetailSeekBar_max, 0).toFloat()
typedArray.recycle() typedArray.recycle()
binding.ivSeekPlus.setOnClickListener { binding.ivSeekPlus.setOnClickListener {
@@ -82,6 +92,24 @@ class DetailSeekBar @JvmOverloads constructor(
onChanged?.invoke(slider.value.toInt()) 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()) { private fun upValue(progress: Int = binding.slider.value.toInt()) {
@@ -96,11 +124,4 @@ class DetailSeekBar @JvmOverloads constructor(
upValue(progress) upValue(progress)
} }
// override fun onStartTrackingTouch(seekBar: SeekBar) {
//
// }
//
// override fun onStopTrackingTouch(seekBar: SeekBar) {
// onChanged?.invoke(binding.slider.progress)
// }
} }
@@ -56,11 +56,12 @@
android:contentDescription="@string/reduce" android:contentDescription="@string/reduce"
app:icon="@drawable/ic_reduce" /> app:icon="@drawable/ic_reduce" />
<com.google.android.material.slider.Slider <io.legato.kazusa.lib.theme.view.ThemeSlider
android:id="@+id/slider" android:id="@+id/slider"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="25dp" android:layout_height="25dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
app:labelBehavior="gone"
android:layout_weight="4" android:layout_weight="4"
android:stepSize="1"/> android:stepSize="1"/>