This commit is contained in:
Horis
2025-05-14 14:51:35 +08:00
parent 04183240cb
commit b8f34b6b41
@@ -55,15 +55,15 @@ object ImageProvider {
val count get() = putCount() + createCount() - evictionCount() - removeCount val count get() = putCount() + createCount() - evictionCount() - removeCount
override fun sizeOf(filePath: String, bitmap: Bitmap): Int { override fun sizeOf(key: String, value: Bitmap): Int {
return bitmap.byteCount return value.byteCount
} }
override fun entryRemoved( override fun entryRemoved(
evicted: Boolean, evicted: Boolean,
filePath: String, key: String,
oldBitmap: Bitmap, oldValue: Bitmap,
newBitmap: Bitmap? newValue: Bitmap?
) { ) {
if (!evicted) { if (!evicted) {
synchronized(this) { synchronized(this) {
@@ -71,8 +71,8 @@ object ImageProvider {
} }
} }
//错误图片不能释放,占位用,防止一直重复获取图片 //错误图片不能释放,占位用,防止一直重复获取图片
if (oldBitmap != errorBitmap) { if (oldValue != errorBitmap) {
oldBitmap.recycle() oldValue.recycle()
//putDebug("ImageProvider: trigger bitmap recycle. URI: $filePath") //putDebug("ImageProvider: trigger bitmap recycle. URI: $filePath")
//putDebug("ImageProvider : cacheUsage ${size()}bytes / ${maxSize()}bytes") //putDebug("ImageProvider : cacheUsage ${size()}bytes / ${maxSize()}bytes")
} }
@@ -86,7 +86,7 @@ object ImageProvider {
} }
fun get(key: String): Bitmap? { fun get(key: String): Bitmap? {
return bitmapLruCache.get(key) return bitmapLruCache[key]
} }
fun remove(key: String): Bitmap? { fun remove(key: String): Bitmap? {
@@ -94,7 +94,7 @@ object ImageProvider {
} }
private fun getNotRecycled(key: String): Bitmap? { private fun getNotRecycled(key: String): Bitmap? {
val bitmap = bitmapLruCache.get(key) ?: return null val bitmap = bitmapLruCache[key] ?: return null
if (bitmap.isRecycled) { if (bitmap.isRecycled) {
bitmapLruCache.remove(key) bitmapLruCache.remove(key)
return null return null