Optimize webtoon scroll
parent
1b7c8355ec
commit
23412e5c17
@ -1,41 +1,17 @@
|
|||||||
package org.koitharu.kotatsu.ui.reader.wetoon
|
package org.koitharu.kotatsu.ui.reader.wetoon
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.RectF
|
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
|
||||||
import kotlinx.android.synthetic.main.item_page_webtoon.view.*
|
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
|
||||||
class WebtoonFrameLayout @JvmOverloads constructor(
|
class WebtoonFrameLayout @JvmOverloads constructor(
|
||||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
) : FrameLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
private val pan = RectF()
|
private val target: WebtoonImageView by lazy {
|
||||||
|
findViewById(R.id.ssiv)
|
||||||
private val target by lazy {
|
|
||||||
findViewById<SubsamplingScaleImageView>(R.id.ssiv)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dispatchVerticalScroll(dy: Int): Int {
|
fun dispatchVerticalScroll(dy: Int) = target.dispatchVerticalScroll(dy)
|
||||||
target.getPanRemaining(pan)
|
|
||||||
val c = target.center ?: return 0
|
|
||||||
val s = target.scale
|
|
||||||
return when {
|
|
||||||
dy > 0 -> {
|
|
||||||
val delta = minOf(pan.bottom.toInt(), dy)
|
|
||||||
c.offset(0f, delta.toFloat() / s)
|
|
||||||
target.setScaleAndCenter(s, c)
|
|
||||||
delta
|
|
||||||
}
|
|
||||||
dy < 0 -> {
|
|
||||||
val delta = minOf(pan.top.toInt(), -dy)
|
|
||||||
c.offset(0f, -delta.toFloat() / s)
|
|
||||||
target.setScaleAndCenter(s, c)
|
|
||||||
-delta
|
|
||||||
}
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.reader.wetoon
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.PointF
|
||||||
|
import android.graphics.RectF
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
|
import org.koitharu.kotatsu.utils.ext.toIntUp
|
||||||
|
|
||||||
|
class WebtoonImageView : SubsamplingScaleImageView {
|
||||||
|
|
||||||
|
constructor(context: Context?) : super(context)
|
||||||
|
constructor(context: Context?, attr: AttributeSet?) : super(context, attr)
|
||||||
|
|
||||||
|
private val pan = RectF()
|
||||||
|
private val ct = PointF()
|
||||||
|
|
||||||
|
fun dispatchVerticalScroll(dy: Int): Int {
|
||||||
|
if (!isReady) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
getPanRemaining(pan)
|
||||||
|
// pan.offset(0f, -nonConsumedScroll.toFloat())
|
||||||
|
ct.set(width / 2f, height / 2f)
|
||||||
|
viewToSourceCoord(ct.x, ct.y, ct) ?: return 0
|
||||||
|
val s = scale
|
||||||
|
return when {
|
||||||
|
dy > 0 -> {
|
||||||
|
val delta = minOf(pan.bottom.toIntUp(), dy)
|
||||||
|
ct.offset(0f, delta.toFloat() / s)
|
||||||
|
setScaleAndCenter(s, ct)
|
||||||
|
delta
|
||||||
|
}
|
||||||
|
dy < 0 -> {
|
||||||
|
val delta = minOf(pan.top.toInt(), -dy)
|
||||||
|
ct.offset(0f, -delta.toFloat() / s)
|
||||||
|
setScaleAndCenter(s, ct)
|
||||||
|
-delta
|
||||||
|
}
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue