fixed some bugs
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user