Optimize webtoon scroll

This commit is contained in:
Koitharu
2020-05-09 10:16:46 +03:00
parent 1b7c8355ec
commit 23412e5c17
6 changed files with 59 additions and 30 deletions

View File

@@ -25,7 +25,6 @@ android {
}
}
}
archivesBaseName = "kotatsu_${gitCommits}"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -38,6 +37,7 @@ android {
applicationIdSuffix = '.debug'
}
release {
multiDexEnabled false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

View File

@@ -9,4 +9,5 @@
-keep class org.koitharu.kotatsu.core.db.entity.* { *; }
-keepclassmembers public class * extends org.koitharu.kotatsu.core.parser.MangaRepository {
public <init>(...);
}
}
-dontwarn okhttp3.internal.platform.ConscryptPlatform

View File

@@ -1,41 +1,17 @@
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)
private val target: WebtoonImageView by lazy {
findViewById(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
}
}
fun dispatchVerticalScroll(dy: Int) = target.dispatchVerticalScroll(dy)
}

View File

@@ -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
}
}
}

View File

@@ -22,4 +22,13 @@ fun Number.format(decimals: Int = 0, decPoint: Char = '.', thousandsSep: Char? =
is Double -> formatter.format(this.toDouble())
else -> formatter.format(this.toLong())
}
}
fun Float.toIntUp(): Int {
val intValue = toInt()
return if (this == intValue.toFloat()) {
intValue
} else {
intValue + 1
}
}

View File

@@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
<org.koitharu.kotatsu.ui.reader.wetoon.WebtoonImageView
android:id="@+id/ssiv"
android:layout_width="match_parent"
android:layout_height="match_parent"