From 11104223eb1c4861187d5d353178e7bdb8edcb34 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Fri, 14 Oct 2022 13:14:04 +0300 Subject: [PATCH] Disable under-scaling in webtoon zoom --- .../ui/pager/webtoon/WebtoonScalingFrame.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt b/app/src/main/java/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt index b834ecf1e..bd1fe0fd5 100644 --- a/app/src/main/java/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt +++ b/app/src/main/java/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonScalingFrame.kt @@ -2,7 +2,9 @@ package org.koitharu.kotatsu.reader.ui.pager.webtoon import android.animation.ObjectAnimator import android.content.Context -import android.graphics.* +import android.graphics.Matrix +import android.graphics.Rect +import android.graphics.RectF import android.util.AttributeSet import android.view.GestureDetector import android.view.MotionEvent @@ -13,13 +15,14 @@ import android.widget.OverScroller import androidx.core.view.GestureDetectorCompat private const val MAX_SCALE = 2.5f -private const val MIN_SCALE = 0.5f +private const val MIN_SCALE = 1f // under-scaling disabled due to buggy nested scroll class WebtoonScalingFrame @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, - defStyles: Int = 0 -): FrameLayout(context, attrs, defStyles), ScaleGestureDetector.OnScaleGestureListener { + defStyles: Int = 0, +) : FrameLayout(context, attrs, defStyles), ScaleGestureDetector.OnScaleGestureListener { + private val targetChild by lazy(LazyThreadSafetyMode.NONE) { getChildAt(0) } private val scaleDetector = ScaleGestureDetector(context, this) @@ -133,14 +136,14 @@ class WebtoonScalingFrame @JvmOverloads constructor( halfWidth * (1 - newScale), halfHeight * (1 - newScale), halfWidth * (newScale - 1), - halfHeight * (newScale - 1) + halfHeight * (newScale - 1), ) } else { translateBounds.set( 0f, halfHeight - halfHeight / newScale, 0f, - halfHeight - halfHeight / newScale + halfHeight - halfHeight / newScale, ) } transformMatrix.postScale(factor, factor, focusX, focusY) @@ -161,7 +164,7 @@ class WebtoonScalingFrame @JvmOverloads constructor( } - private inner class GestureListener(): GestureDetector.SimpleOnGestureListener(), Runnable { + private inner class GestureListener : GestureDetector.SimpleOnGestureListener(), Runnable { override fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean { if (scale <= 1f) return false transformMatrix.postTranslate(-distanceX, -distanceY) @@ -193,7 +196,7 @@ class WebtoonScalingFrame @JvmOverloads constructor( translateBounds.left.toInt(), translateBounds.right.toInt(), translateBounds.top.toInt(), - translateBounds.bottom.toInt() + translateBounds.bottom.toInt(), ) postOnAnimation(this) return true