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

@ -127,7 +127,7 @@ object ChapterProvider {
when (imageStyle?.toUpperCase()) { when (imageStyle?.toUpperCase()) {
"FULL" -> { "FULL" -> {
width = visibleWidth width = visibleWidth
height = it.width / width * it.height height = it.height * visibleWidth / it.width
} }
else -> { else -> {
if (it.width > visibleWidth) { 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.MD5Utils
import io.legado.app.utils.externalFilesDir import io.legado.app.utils.externalFilesDir
import java.io.FileOutputStream import java.io.FileOutputStream
import java.util.concurrent.ConcurrentHashMap
object ImageProvider { object ImageProvider {
private val cache = hashMapOf<Int, HashMap<String, Bitmap>>() private val cache = ConcurrentHashMap<Int, ConcurrentHashMap<String, Bitmap>>()
@Synchronized @Synchronized
fun getCache(chapterIndex: Int, src: String): Bitmap? { fun getCache(chapterIndex: Int, src: String): Bitmap? {
@ -24,7 +25,7 @@ object ImageProvider {
fun setCache(chapterIndex: Int, src: String, bitmap: Bitmap) { fun setCache(chapterIndex: Int, src: String, bitmap: Bitmap) {
var indexCache = cache[chapterIndex] var indexCache = cache[chapterIndex]
if (indexCache == null) { if (indexCache == null) {
indexCache = hashMapOf() indexCache = ConcurrentHashMap()
cache[chapterIndex] = indexCache cache[chapterIndex] = indexCache
} }
indexCache[src] = bitmap indexCache[src] = bitmap

Loading…
Cancel
Save