Optimize webtoon scroll
This commit is contained in:
@@ -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'
|
||||
|
||||
3
app/proguard-rules.pro
vendored
3
app/proguard-rules.pro
vendored
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user