pull/1778/head
kunfei 3 years ago
parent 8875e0a759
commit b37d120966
  1. 7
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  2. 15
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -101,7 +101,7 @@ object ChapterProvider {
/**
* 获取拆分完的章节数据
*/
fun getTextChapter(
suspend fun getTextChapter(
book: Book,
bookChapter: BookChapter,
displayTitle: String,
@ -136,7 +136,6 @@ object ChapterProvider {
while (matcher.find()) {
matcher.group(1)?.let { src ->
srcList.add(src)
ImageProvider.getImage(book, src, ReadBook.bookSource)
matcher.appendReplacement(sb, srcReplaceChar)
}
}
@ -200,7 +199,7 @@ object ChapterProvider {
)
}
private fun setTypeImage(
private suspend fun setTypeImage(
book: Book,
src: String,
x: Int,
@ -209,7 +208,7 @@ object ChapterProvider {
imageStyle: String?,
): Float {
var durY = y
ImageProvider.getImage(book, src, ReadBook.bookSource)?.let {
ImageProvider.getImageSize(book, src, ReadBook.bookSource).let {
if (durY > visibleHeight) {
textPages.last().height = durY
textPages.add(TextPage())

@ -1,6 +1,7 @@
package io.legado.app.ui.book.read.page.provider
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.Size
import io.legado.app.R
import io.legado.app.constant.AppLog.putDebug
@ -10,7 +11,6 @@ import io.legado.app.help.BookHelp
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.localBook.EpubFile
import io.legado.app.utils.BitmapUtils
import io.legado.app.utils.FileUtils
import io.legado.app.utils.isXml
import kotlinx.coroutines.runBlocking
@ -22,13 +22,8 @@ import kotlin.coroutines.resume
object ImageProvider {
private val errorBitmap: Bitmap? by lazy {
BitmapUtils.decodeBitmap(
appCtx,
R.drawable.image_loading_error,
ChapterProvider.visibleWidth,
ChapterProvider.visibleHeight
)
private val errorBitmap: Bitmap by lazy {
BitmapFactory.decodeResource(appCtx.resources, R.drawable.image_loading_error)
}
private suspend fun cacheImage(
@ -66,12 +61,12 @@ object ImageProvider {
block.resume(Size(width, height))
}
}.onFailure {
block.cancel(it)
block.resume(Size(errorBitmap.width, errorBitmap.height))
}
}
}
fun getImage(
suspend fun getImage(
book: Book,
src: String,
bookSource: BookSource?,

Loading…
Cancel
Save