Fix webtoon scroll
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId 'org.koitharu.kotatsu'
|
applicationId 'org.koitharu.kotatsu'
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 31
|
targetSdkVersion 31
|
||||||
versionCode 377
|
versionCode 378
|
||||||
versionName '2.1.1'
|
versionName '2.1.2'
|
||||||
generatedDensities = []
|
generatedDensities = []
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
package org.koitharu.kotatsu.reader.ui.pager.webtoon
|
package org.koitharu.kotatsu.reader.ui.pager.webtoon
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.PointF
|
import android.graphics.PointF
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import org.koitharu.kotatsu.utils.ext.toIntUp
|
import org.koitharu.kotatsu.utils.ext.toIntUp
|
||||||
|
|
||||||
class WebtoonImageView @JvmOverloads constructor(context: Context, attr: AttributeSet? = null) :
|
class WebtoonImageView @JvmOverloads constructor(
|
||||||
SubsamplingScaleImageView(context, attr) {
|
context: Context,
|
||||||
|
attr: AttributeSet? = null,
|
||||||
|
) : SubsamplingScaleImageView(context, attr) {
|
||||||
|
|
||||||
private val ct = PointF()
|
private val ct = PointF()
|
||||||
private val displayHeight = resources.displayMetrics.heightPixels
|
private val displayHeight = (context as Activity).window.decorView.height
|
||||||
|
|
||||||
private var scrollPos = 0
|
private var scrollPos = 0
|
||||||
private var scrollRange = SCROLL_UNKNOWN
|
private var scrollRange = SCROLL_UNKNOWN
|
||||||
@@ -55,6 +58,30 @@ class WebtoonImageView @JvmOverloads constructor(context: Context, attr: Attribu
|
|||||||
return desiredHeight
|
return desiredHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
|
val widthSpecMode = MeasureSpec.getMode(widthMeasureSpec)
|
||||||
|
val heightSpecMode = MeasureSpec.getMode(heightMeasureSpec)
|
||||||
|
val parentWidth = MeasureSpec.getSize(widthMeasureSpec)
|
||||||
|
val parentHeight = MeasureSpec.getSize(heightMeasureSpec)
|
||||||
|
val resizeWidth = widthSpecMode != MeasureSpec.EXACTLY
|
||||||
|
val resizeHeight = heightSpecMode != MeasureSpec.EXACTLY
|
||||||
|
var width = parentWidth
|
||||||
|
var height = parentHeight
|
||||||
|
if (sWidth > 0 && sHeight > 0) {
|
||||||
|
if (resizeWidth && resizeHeight) {
|
||||||
|
width = sWidth
|
||||||
|
height = sHeight
|
||||||
|
} else if (resizeHeight) {
|
||||||
|
height = (sHeight.toDouble() / sWidth.toDouble() * width).toInt()
|
||||||
|
} else if (resizeWidth) {
|
||||||
|
width = (sWidth.toDouble() / sHeight.toDouble() * height).toInt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
width = width.coerceAtLeast(suggestedMinimumWidth)
|
||||||
|
height = height.coerceIn(suggestedMinimumHeight, displayHeight)
|
||||||
|
setMeasuredDimension(width, height)
|
||||||
|
}
|
||||||
|
|
||||||
private fun scrollToInternal(pos: Int) {
|
private fun scrollToInternal(pos: Int) {
|
||||||
scrollPos = pos
|
scrollPos = pos
|
||||||
ct.set(sWidth / 2f, (height / 2f + pos.toFloat()) / minScale)
|
ct.set(sWidth / 2f, (height / 2f + pos.toFloat()) / minScale)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class WebtoonRecyclerView @JvmOverloads constructor(
|
|||||||
consumed[0] = 0
|
consumed[0] = 0
|
||||||
consumed[1] = consumedY
|
consumed[1] = consumedY
|
||||||
}
|
}
|
||||||
return consumedY != 0
|
return consumedY != 0 || dy == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun consumeVerticalScroll(dy: Int): Int {
|
private fun consumeVerticalScroll(dy: Int): Int {
|
||||||
|
|||||||
Reference in New Issue
Block a user