feat:正文图片添加失败图,加载失败删除

pull/1772/head
Xwite 3 years ago
parent 9d7c896842
commit e4e9d4c2d4
  1. 40
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  2. BIN
      app/src/main/res/drawable/image_loading_error.jpg

@ -1,6 +1,10 @@
package io.legado.app.ui.book.read.page.provider
import android.graphics.Bitmap
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp
@ -8,9 +12,11 @@ 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.R
import kotlinx.coroutines.runBlocking
import splitties.init.appCtx
import java.io.FileOutputStream
import java.io.File
import java.util.concurrent.ConcurrentHashMap
object ImageProvider {
@ -37,10 +43,36 @@ object ImageProvider {
}
}
}
return try {
ImageLoader.loadBitmap(appCtx, vFile.absolutePath).submit().get()
} catch (e: Exception) {
null
return ImageLoader.loadBitmap(appCtx, vFile.absolutePath)
.error(R.drawable.image_loading_error)
.listener(glideListener)
.submit()
.get()
}
private val glideListener by lazy {
object : RequestListener<Bitmap> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Bitmap>?,
isFirstResource: Boolean
): Boolean {
File(model as String).delete()
return false
}
override fun onResourceReady(
resource: Bitmap?,
model: Any?,
target: Target<Bitmap>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
return false
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Loading…
Cancel
Save