From 9cb683dc55932a6e6fd24f37084c3a4fc260a942 Mon Sep 17 00:00:00 2001 From: tarsin Date: Fri, 16 Dec 2022 22:07:09 +0800 Subject: [PATCH] Fix crash when zoomed and try to swipe to next page --- .../labs/subscaleview/SubsamplingScaleImageView.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.kt b/app/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.kt index 4b420f3fb..25ec9f207 100644 --- a/app/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.kt +++ b/app/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.kt @@ -476,8 +476,10 @@ open class SubsamplingScaleImageView @JvmOverloads constructor( private fun setGestureDetector(context: Context) { detector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() { + @Suppress("SENSELESS_COMPARISON") override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean { - if (panEnabled && isReady && vTranslate != null && (abs(e1.x - e2.x) > 50 || abs(e1.y - e2.y) > 50) && (abs(velocityX) > 500 || abs(velocityY) > 500) && !isZooming) { + // The e1 can be null, that's weird and cause crash + if (panEnabled && isReady && vTranslate != null && e1 != null && e2 != null && (abs(e1.x - e2.x) > 50 || abs(e1.y - e2.y) > 50) && (abs(velocityX) > 500 || abs(velocityY) > 500) && !isZooming) { val vTranslateEnd = PointF(vTranslate!!.x + velocityX * 0.25F, vTranslate!!.y + velocityY * 0.25F) val sCenterXEnd = (width / 2 - vTranslateEnd.x) / scale val sCenterYEnd = (height / 2 - vTranslateEnd.y) / scale