pull/279/head
gedoor 4 years ago
parent cae073d92b
commit d23a7353e2
  1. 16
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -10,12 +10,12 @@ import android.view.animation.DecelerateInterpolator
import android.widget.Scroller
import androidx.annotation.CallSuper
import com.google.android.material.snackbar.Snackbar
import io.legado.app.R
import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.book.read.page.ContentView
import io.legado.app.ui.book.read.page.PageView
import kotlin.math.abs
import io.legado.app.R
abstract class PageDelegate(protected val pageView: PageView) :
GestureDetector.SimpleOnGestureListener() {
@ -24,6 +24,7 @@ abstract class PageDelegate(protected val pageView: PageView) :
pageView.width * 0.66f, pageView.height * 0.66f
)
protected val context: Context = pageView.context
private val animationSpeed = 300
//起始点
protected var startX: Float = 0f
@ -115,13 +116,12 @@ abstract class PageDelegate(protected val pageView: PageView) :
}
protected fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int) {
scroller.startScroll(
startX,
startY,
dx,
dy,
if (dx != 0) (abs(dx) * 0.3).toInt() else (abs(dy) * 0.3).toInt()
)
val duration = if (dx != 0) {
(animationSpeed * abs(dx)) / viewWidth
} else {
(animationSpeed * abs(dy)) / viewHeight
}
scroller.startScroll(startX, startY, dx, dy, duration)
isRunning = true
isStarted = true
pageView.invalidate()

@ -127,7 +127,7 @@ object ChapterProvider {
when (imageStyle?.toUpperCase()) {
"FULL" -> {
width = visibleWidth
height = it.width / width * it.height
height = it.height * visibleWidth / it.width
}
else -> {
if (it.width > visibleWidth) {

@ -10,10 +10,11 @@ import io.legado.app.utils.FileUtils
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.externalFilesDir
import java.io.FileOutputStream
import java.util.concurrent.ConcurrentHashMap
object ImageProvider {
private val cache = hashMapOf<Int, HashMap<String, Bitmap>>()
private val cache = ConcurrentHashMap<Int, ConcurrentHashMap<String, Bitmap>>()
@Synchronized
fun getCache(chapterIndex: Int, src: String): Bitmap? {
@ -24,7 +25,7 @@ object ImageProvider {
fun setCache(chapterIndex: Int, src: String, bitmap: Bitmap) {
var indexCache = cache[chapterIndex]
if (indexCache == null) {
indexCache = hashMapOf()
indexCache = ConcurrentHashMap()
cache[chapterIndex] = indexCache
}
indexCache[src] = bitmap

Loading…
Cancel
Save