fixed some bugs

This commit is contained in:
2026-08-24 14:25:31 +08:00
parent 8d4a81b4f5
commit 28674def97
5 changed files with 148 additions and 43 deletions

View File

@@ -28,6 +28,7 @@ class OralTrainerPlayerView @JvmOverloads constructor(
private var longPressStartY = 0f
private var longPressActive = false
private var speedBeforeLongPress: Float? = null
private var verticalSwipeListener: ((isSwipeUp: Boolean) -> Unit)? = null
private val longPressSpeedRunnable = Runnable {
val activeController = controller ?: return@Runnable
@@ -70,6 +71,11 @@ class OralTrainerPlayerView @JvmOverloads constructor(
val dy = e2.y - start.y
val minDistancePx = gestureControls.minSwipeDistanceDp * density
val minVelocityPx = gestureControls.minSwipeVelocityDpPerSecond * density
if (abs(dy) > minDistancePx && abs(dy) > abs(dx) && abs(velocityY) >= minVelocityPx) {
val isSwipeUp = dy < 0
verticalSwipeListener?.invoke(isSwipeUp)
return true
}
if (abs(dx) < abs(dy) || abs(dx) < minDistancePx || abs(velocityX) < minVelocityPx) {
return false
}
@@ -112,6 +118,10 @@ class OralTrainerPlayerView @JvmOverloads constructor(
gestureControls = config
}
fun setVerticalSwipeListener(listener: ((isSwipeUp: Boolean) -> Unit)?) {
verticalSwipeListener = listener
}
override fun onTouchEvent(event: MotionEvent): Boolean {
return gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
}