Webtoon reader scroll with pan
parent
a5d863c84c
commit
a3dbef6bfe
@ -1,16 +1,29 @@
|
||||
package org.koitharu.kotatsu.ui.reader.wetoon
|
||||
|
||||
import android.view.Gravity
|
||||
import android.view.ViewGroup
|
||||
import org.koitharu.kotatsu.core.model.MangaPage
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseRecyclerAdapter
|
||||
import org.koitharu.kotatsu.ui.common.list.BaseViewHolder
|
||||
import org.koitharu.kotatsu.ui.reader.PageLoader
|
||||
|
||||
class WebtoonAdapter(private val loader: PageLoader) : BaseRecyclerAdapter<MangaPage, Unit>() {
|
||||
class WebtoonAdapter(private val loader: PageLoader) : BaseRecyclerAdapter<MangaPage, Int>() {
|
||||
|
||||
private var lastBound = -1
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup) =
|
||||
WebtoonHolder(parent, loader)
|
||||
|
||||
override fun onGetItemId(item: MangaPage) = item.id
|
||||
|
||||
override fun getExtra(item: MangaPage, position: Int) = Unit
|
||||
override fun onBindViewHolder(holder: BaseViewHolder<MangaPage, Int>, position: Int) {
|
||||
super.onBindViewHolder(holder, position)
|
||||
lastBound = position
|
||||
}
|
||||
|
||||
override fun getExtra(item: MangaPage, position: Int) = if (position >= lastBound) {
|
||||
Gravity.TOP
|
||||
} else {
|
||||
Gravity.BOTTOM
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package org.koitharu.kotatsu.ui.reader.wetoon
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.RectF
|
||||
import android.util.AttributeSet
|
||||
import android.widget.FrameLayout
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import kotlinx.android.synthetic.main.item_page_webtoon.view.*
|
||||
import org.koitharu.kotatsu.R
|
||||
|
||||
class WebtoonFrameLayout @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
|
||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private val pan = RectF()
|
||||
|
||||
private val target by lazy {
|
||||
findViewById<SubsamplingScaleImageView>(R.id.ssiv)
|
||||
}
|
||||
|
||||
fun dispatchVerticalScroll(dy: Int): Int {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package org.koitharu.kotatsu.ui.reader.wetoon
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
|
||||
class WebtoonImageView @JvmOverloads constructor(context: Context, attr: AttributeSet? = null) :
|
||||
SubsamplingScaleImageView(context, attr) {
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent) = false
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue