Avoid warnings in OnSwipeTouchListener
This commit is contained in:
@ -1,23 +1,26 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.view.GestureDetector
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import kotlin.math.abs
|
||||
|
||||
open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||
|
||||
private val gestureDetector: GestureDetector
|
||||
|
||||
companion object {
|
||||
private val SWIPE_THRESHOLD = 100
|
||||
private val SWIPE_VELOCITY_THRESHOLD = 100
|
||||
private const val SWIPE_THRESHOLD = 100
|
||||
private const val SWIPE_VELOCITY_THRESHOLD = 100
|
||||
}
|
||||
|
||||
init {
|
||||
gestureDetector = GestureDetector(ctx, GestureListener())
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
|
||||
return gestureDetector.onTouchEvent(event)
|
||||
}
|
||||
@ -33,8 +36,8 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||
try {
|
||||
val diffY = e2!!.y - e1!!.y
|
||||
val diffX = e2.x - e1.x
|
||||
if (Math.abs(diffX) > Math.abs(diffY)) {
|
||||
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > SWIPE_THRESHOLD && abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffX > 0) {
|
||||
onSwipeRight()
|
||||
} else {
|
||||
@ -42,13 +45,13 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||
}
|
||||
result = true
|
||||
}
|
||||
} else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffY > 0) {
|
||||
} else if (abs(diffY) > SWIPE_THRESHOLD && abs(velY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
result = if (diffY > 0) {
|
||||
onSwipeBottom()
|
||||
result = false
|
||||
false
|
||||
} else {
|
||||
onSwipeTop()
|
||||
result = true
|
||||
true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in New Issue
Block a user