From 74e91c86d1b5c91085de5034dc29c3537e396b05 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 24 May 2022 22:23:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=94=99=E8=AF=AF=E6=97=B6=E5=8D=A1=E9=A1=BF=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/provider/ImageProvider.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 d88e26c95..054bf6371 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 @@ -35,6 +35,7 @@ object ImageProvider { private val cacheSize = max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt())) val bitmapLruCache = object : LruCache(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