Merge pull request #1776 from Xwite/master

fix:#1774
pull/1778/head
kunfei 3 years ago committed by GitHub
commit 51a3b41c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 53
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -13,6 +13,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.ImageLoader
import io.legado.app.model.localBook.EpubFile import io.legado.app.model.localBook.EpubFile
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import io.legado.app.utils.BitmapUtils
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
@ -20,6 +21,15 @@ import java.io.FileOutputStream
object ImageProvider { object ImageProvider {
private val errorBitmap: Bitmap? by lazy {
BitmapUtils.decodeBitmap(
appCtx,
R.drawable.image_loading_error,
ChapterProvider.visibleWidth,
ChapterProvider.visibleHeight
)
}
fun getImage( fun getImage(
book: Book, book: Book,
src: String, src: String,
@ -41,41 +51,14 @@ object ImageProvider {
} }
} }
} }
return ImageLoader.loadBitmap(appCtx, vFile.absolutePath) return try {
.error(R.drawable.image_loading_error) ImageLoader.loadBitmap(appCtx, vFile.absolutePath).submit().get()
.listener(glideListener) } catch (e: Exception) {
.submit() Coroutine.async { vFile.delete() }
.get() //must call this method on a background thread
} //ImageLoader.loadBitmap(appCtx, R.drawable.image_loading_error).submit().get()
errorBitmap
private val glideListener by lazy { }
object : RequestListener<Bitmap> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Bitmap>?,
isFirstResource: Boolean
): Boolean {
Coroutine.async {
(model as? String)?.let { path ->
File(path).delete()
}
}
return false
}
override fun onResourceReady(
resource: Bitmap?,
model: Any?,
target: Target<Bitmap>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
return false
}
}
} }
} }

Loading…
Cancel
Save