From a8cfb3521c6056446eac6b2e5b4d826b01f05a3a Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 28 Jun 2025 06:52:41 +0300 Subject: [PATCH] Fix window size handling in reader --- .../koitharu/kotatsu/reader/ui/ReaderActivity.kt | 2 +- .../kotatsu/reader/ui/tapgrid/TapGridDispatcher.kt | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt index 7b1a1ca5f..2e1818fa7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt @@ -109,7 +109,7 @@ class ReaderActivity : setContentView(ActivityReaderBinding.inflate(layoutInflater)) readerManager = ReaderManager(supportFragmentManager, viewBinding.container, settings) setDisplayHomeAsUp(isEnabled = true, showUpAsClose = false) - touchHelper = TapGridDispatcher(this, this) + touchHelper = TapGridDispatcher(viewBinding.root, this) scrollTimer = scrollTimerFactory.create(resources, this, this) pageSaveHelper = pageSaveHelperFactory.create(this) controlDelegate = ReaderControlDelegate(resources, settings, tapGridSettings, this) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/tapgrid/TapGridDispatcher.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/tapgrid/TapGridDispatcher.kt index 9987cd4cf..e170d6d5b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/tapgrid/TapGridDispatcher.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/tapgrid/TapGridDispatcher.kt @@ -1,19 +1,17 @@ package org.koitharu.kotatsu.reader.ui.tapgrid -import android.content.Context import android.view.GestureDetector import android.view.MotionEvent +import android.view.View import org.koitharu.kotatsu.reader.domain.TapGridArea import kotlin.math.roundToInt class TapGridDispatcher( - context: Context, + private val rootView: View, private val listener: OnGridTouchListener, ) : GestureDetector.SimpleOnGestureListener() { - private val detector = GestureDetector(context, this) - private val width = context.resources.displayMetrics.widthPixels - private val height = context.resources.displayMetrics.heightPixels + private val detector = GestureDetector(rootView.context, this) private var isDispatching = false init { @@ -49,6 +47,11 @@ class TapGridDispatcher( } private fun getArea(x: Float, y: Float): TapGridArea? { + val width = rootView.width + val height = rootView.height + if (height <= 0 || width <= 0) { + return null + } val xIndex = (x * 2f / width).roundToInt() val yIndex = (y * 2f / height).roundToInt() val area = when (xIndex) {