修改图片绘制

pull/1785/head
kunfei 3 years ago
parent ad86c64ad9
commit d57250df32
  1. 15
      app/src/main/java/io/legado/app/ui/book/read/PhotoDialog.kt
  2. 25
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -5,9 +5,10 @@ import android.view.View
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogPhotoViewBinding import io.legado.app.databinding.DialogPhotoViewBinding
import io.legado.app.help.BookHelp
import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.BookCover import io.legado.app.model.BookCover
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.setLayout import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -40,14 +41,12 @@ class PhotoDialog() : BaseDialogFragment(R.layout.dialog_photo_view) {
arguments?.let { arguments?.let {
val path = it.getString("path") val path = it.getString("path")
if (path.isNullOrEmpty()) { if (path.isNullOrEmpty()) {
val src = it.getString("src")
ReadBook.book?.let { book -> ReadBook.book?.let { book ->
src?.let { it.getString("src")?.let { src ->
execute { val file = BookHelp.getImage(book, src)
ImageProvider.getImage(book, src, ReadBook.bookSource) ImageLoader.load(requireContext(), file)
}.onSuccess { bitmap -> .error(R.drawable.image_loading_error)
binding.photoView.setImageBitmap(bitmap) .into(binding.photoView)
}
} }
} }
} else { } else {

@ -94,29 +94,4 @@ object ImageProvider {
} }
} }
suspend fun getImage(
book: Book,
src: String,
bookSource: BookSource?
): Bitmap {
return withContext(IO) {
val vFile = cacheImage(book, src, bookSource)
try {
@Suppress("BlockingMethodInNonBlockingContext")
ImageLoader.loadBitmap(appCtx, vFile.absolutePath)
.submit(ChapterProvider.visibleWidth, ChapterProvider.visibleHeight)
.get()
} catch (e: Exception) {
Coroutine.async {
putDebug("${vFile.absolutePath} 解码失败\n$e", e)
if (FileUtils.readText(vFile.absolutePath).isXml()) {
putDebug("${vFile.absolutePath}为xml,自动删除")
vFile.delete()
}
}
errorBitmap
}
}
}
} }

Loading…
Cancel
Save