修复图片加载错误时卡顿的bug

pull/1905/head^2
kunfei 2 years ago
parent c36cde3a9a
commit 74e91c86d1
  1. 11
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt

@ -35,6 +35,7 @@ object ImageProvider {
private val cacheSize =
max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt()))
val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
override fun sizeOf(key: String, bitmap: Bitmap): Int {
return bitmap.byteCount
}
@ -45,9 +46,11 @@ object ImageProvider {
oldBitmap: Bitmap,
newBitmap: Bitmap?
) {
oldBitmap.recycle()
putDebug("ImageProvider: trigger bitmap recycle. URI: $key")
putDebug("ImageProvider : cacheUsage ${size()}bytes / ${maxSize()}bytes")
if (oldBitmap != errorBitmap) {
oldBitmap.recycle()
putDebug("ImageProvider: trigger bitmap recycle. URI: $key")
putDebug("ImageProvider : cacheUsage ${size()}bytes / ${maxSize()}bytes")
}
}
}
@ -121,6 +124,8 @@ object ImageProvider {
bitmapLruCache.put(src, bitmap)
bitmap
}.onFailure {
//错误图片占位,防止重复获取
bitmapLruCache.put(src, errorBitmap)
putDebug(
"ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it",
it

Loading…
Cancel
Save