Avoid swipe related crash
This commit is contained in:
@ -33,32 +33,33 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||
|
||||
override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velX: Float, velY: Float): Boolean {
|
||||
var result = false
|
||||
try {
|
||||
val diffY = e2!!.y - e1!!.y
|
||||
val diffX = e2.x - e1.x
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > SWIPE_THRESHOLD && abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffX > 0) {
|
||||
onSwipeRight()
|
||||
} else {
|
||||
onSwipeLeft()
|
||||
if (e1 != null && e2 != null) {
|
||||
try {
|
||||
val diffY = e2.y - e1.y
|
||||
val diffX = e2.x - e1.x
|
||||
if (abs(diffX) > abs(diffY)) {
|
||||
if (abs(diffX) > SWIPE_THRESHOLD && abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffX > 0) {
|
||||
onSwipeRight()
|
||||
} else {
|
||||
onSwipeLeft()
|
||||
}
|
||||
result = true
|
||||
}
|
||||
} else if (abs(diffY) > SWIPE_THRESHOLD && abs(velY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
result = if (diffY > 0) {
|
||||
onSwipeBottom()
|
||||
false
|
||||
} else {
|
||||
onSwipeTop()
|
||||
true
|
||||
}
|
||||
result = true
|
||||
}
|
||||
} else if (abs(diffY) > SWIPE_THRESHOLD && abs(velY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
result = if (diffY > 0) {
|
||||
onSwipeBottom()
|
||||
false
|
||||
} else {
|
||||
onSwipeTop()
|
||||
true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "onFling exception $e")
|
||||
e.printStackTrace()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "onFling exception $e")
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user