From d6dd5f21fe7cc94e32dcc3452b43773c509441db Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Thu, 11 Mar 2021 19:16:09 +0200 Subject: [PATCH] Try to catch onFling null pointer exception --- .../tutpro/baresip/OnSwipeTouchListener.kt | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt b/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt index 4663f30c..9bface8e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/OnSwipeTouchListener.kt @@ -18,26 +18,23 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener { gestureDetector = GestureDetector(ctx, GestureListener()) } - override fun onTouch(v: View?, e: MotionEvent?): Boolean { - return if (v != null && e != null) - gestureDetector.onTouchEvent(e) - else - false + override fun onTouch(view: View?, event: MotionEvent?): Boolean { + return gestureDetector.onTouchEvent(event) } private inner class GestureListener : GestureDetector.SimpleOnGestureListener() { - override fun onDown(e: MotionEvent): Boolean { + override fun onDown(event: MotionEvent): Boolean { return true } - override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean { + override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velX: Float, velY: Float): Boolean { var result = false try { - val diffY = e2.y - e1.y + 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(velocityX) > SWIPE_VELOCITY_THRESHOLD) { + if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velX) > SWIPE_VELOCITY_THRESHOLD) { if (diffX > 0) { onSwipeRight() } else { @@ -45,7 +42,7 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener { } result = true } - } else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { + } else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velY) > SWIPE_VELOCITY_THRESHOLD) { if (diffY > 0) { onSwipeBottom() result = false @@ -54,8 +51,9 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener { result = true } } - } catch (exception: Exception) { - exception.printStackTrace() + } catch (e: Exception) { + Log.e("Baresip", "onFling exception $e") + e.printStackTrace() } return result