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 {
|
override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velX: Float, velY: Float): Boolean {
|
||||||
var result = false
|
var result = false
|
||||||
try {
|
if (e1 != null && e2 != null) {
|
||||||
val diffY = e2!!.y - e1!!.y
|
try {
|
||||||
val diffX = e2.x - e1.x
|
val diffY = e2.y - e1.y
|
||||||
if (abs(diffX) > abs(diffY)) {
|
val diffX = e2.x - e1.x
|
||||||
if (abs(diffX) > SWIPE_THRESHOLD && abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
if (abs(diffX) > abs(diffY)) {
|
||||||
if (diffX > 0) {
|
if (abs(diffX) > SWIPE_THRESHOLD && abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||||
onSwipeRight()
|
if (diffX > 0) {
|
||||||
} else {
|
onSwipeRight()
|
||||||
onSwipeLeft()
|
} 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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user