From 0629bf982cf9e0f340e028d2e8f8000f7c488861 Mon Sep 17 00:00:00 2001 From: morcefaster <51055657+morcefaster@users.noreply.github.com> Date: Sat, 18 Apr 2020 21:43:54 +0300 Subject: [PATCH] Webtoon zoom out (#2892) * Increased added support for zoom out on webtoons to help with horizontal layout reading * Renamed var --- .../viewer/webtoon/WebtoonRecyclerView.kt | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt index 3b11be3be2..6b70bea56e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonRecyclerView.kt @@ -27,6 +27,8 @@ open class WebtoonRecyclerView @JvmOverloads constructor( private var atFirstPosition = false private var halfWidth = 0 private var halfHeight = 0 + private var originalHeight = 0 + private var heightSet = false private var firstVisibleItemPosition = 0 private var lastVisibleItemPosition = 0 private var currentScale = DEFAULT_RATE @@ -40,6 +42,10 @@ open class WebtoonRecyclerView @JvmOverloads constructor( override fun onMeasure(widthSpec: Int, heightSpec: Int) { halfWidth = MeasureSpec.getSize(widthSpec) / 2 halfHeight = MeasureSpec.getSize(heightSpec) / 2 + if (!heightSet) { + originalHeight = MeasureSpec.getSize(heightSpec) + heightSet = true + } super.onMeasure(widthSpec, heightSpec) } @@ -66,11 +72,17 @@ open class WebtoonRecyclerView @JvmOverloads constructor( } private fun getPositionX(positionX: Float): Float { + if (currentScale < 1) { + return 0f + } val maxPositionX = halfWidth * (currentScale - 1) return positionX.coerceIn(-maxPositionX, maxPositionX) } private fun getPositionY(positionY: Float): Float { + if (currentScale < 1) { + return (originalHeight / 2 - halfHeight).toFloat() + } val maxPositionY = halfHeight * (currentScale - 1) return positionY.coerceIn(-maxPositionY, maxPositionY) } @@ -161,11 +173,14 @@ open class WebtoonRecyclerView @JvmOverloads constructor( fun onScale(scaleFactor: Float) { currentScale *= scaleFactor currentScale = currentScale.coerceIn( - DEFAULT_RATE, + MIN_RATE, MAX_SCALE_RATE) setScaleRate(currentScale) + layoutParams.height = if (currentScale < 1) { (originalHeight / currentScale).toInt() } else { originalHeight } + halfHeight = layoutParams.height / 2 + if (currentScale != DEFAULT_RATE) { x = getPositionX(x) y = getPositionY(y) @@ -173,6 +188,8 @@ open class WebtoonRecyclerView @JvmOverloads constructor( x = 0f y = 0f } + + requestLayout() } fun onScaleBegin() { @@ -182,8 +199,8 @@ open class WebtoonRecyclerView @JvmOverloads constructor( } fun onScaleEnd() { - if (scaleX < DEFAULT_RATE) { - zoom(currentScale, DEFAULT_RATE, x, 0f, y, 0f) + if (scaleX < MIN_RATE) { + zoom(currentScale, MIN_RATE, x, 0f, y, 0f) } } @@ -309,6 +326,7 @@ open class WebtoonRecyclerView @JvmOverloads constructor( private companion object { const val ANIMATOR_DURATION_TIME = 200 + const val MIN_RATE = 0.5f const val DEFAULT_RATE = 1f const val MAX_SCALE_RATE = 3f }