修复图片加载错误时卡顿的bug
This commit is contained in:
@@ -35,6 +35,7 @@ object ImageProvider {
|
|||||||
private val cacheSize =
|
private val cacheSize =
|
||||||
max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt()))
|
max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt()))
|
||||||
val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
|
val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
|
||||||
|
|
||||||
override fun sizeOf(key: String, bitmap: Bitmap): Int {
|
override fun sizeOf(key: String, bitmap: Bitmap): Int {
|
||||||
return bitmap.byteCount
|
return bitmap.byteCount
|
||||||
}
|
}
|
||||||
@@ -45,11 +46,13 @@ object ImageProvider {
|
|||||||
oldBitmap: Bitmap,
|
oldBitmap: Bitmap,
|
||||||
newBitmap: Bitmap?
|
newBitmap: Bitmap?
|
||||||
) {
|
) {
|
||||||
|
if (oldBitmap != errorBitmap) {
|
||||||
oldBitmap.recycle()
|
oldBitmap.recycle()
|
||||||
putDebug("ImageProvider: trigger bitmap recycle. URI: $key")
|
putDebug("ImageProvider: trigger bitmap recycle. URI: $key")
|
||||||
putDebug("ImageProvider : cacheUsage ${size()}bytes / ${maxSize()}bytes")
|
putDebug("ImageProvider : cacheUsage ${size()}bytes / ${maxSize()}bytes")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*缓存网络图片和epub图片
|
*缓存网络图片和epub图片
|
||||||
@@ -121,6 +124,8 @@ object ImageProvider {
|
|||||||
bitmapLruCache.put(src, bitmap)
|
bitmapLruCache.put(src, bitmap)
|
||||||
bitmap
|
bitmap
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
//错误图片占位,防止重复获取
|
||||||
|
bitmapLruCache.put(src, errorBitmap)
|
||||||
putDebug(
|
putDebug(
|
||||||
"ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it",
|
"ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it",
|
||||||
it
|
it
|
||||||
|
|||||||
Reference in New Issue
Block a user