diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index eeb2a5027..d8c821e6d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.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()) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index 1b08a166f..c3e50c396 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -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?,