refactor(ImageProvider.kt):minify code
This commit is contained in:
@@ -96,7 +96,7 @@ object ImageProvider {
|
|||||||
book: Book,
|
book: Book,
|
||||||
src: String,
|
src: String,
|
||||||
width: Int,
|
width: Int,
|
||||||
height: Int
|
height: Int? = null
|
||||||
): Bitmap {
|
): Bitmap {
|
||||||
val cacheBitmap = bitmapLruCache.get(src)
|
val cacheBitmap = bitmapLruCache.get(src)
|
||||||
if (cacheBitmap != null) return cacheBitmap
|
if (cacheBitmap != null) return cacheBitmap
|
||||||
@@ -118,32 +118,4 @@ object ImageProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*获取bitmap 使用LruCache缓存
|
|
||||||
*/
|
|
||||||
fun getImage(
|
|
||||||
book: Book,
|
|
||||||
src: String,
|
|
||||||
width: Int
|
|
||||||
): Bitmap {
|
|
||||||
val cacheBitmap = bitmapLruCache.get(src)
|
|
||||||
if (cacheBitmap != null) return cacheBitmap
|
|
||||||
val vFile = BookHelp.getImage(book, src)
|
|
||||||
@Suppress("BlockingMethodInNonBlockingContext")
|
|
||||||
return try {
|
|
||||||
val bitmap = BitmapUtils.decodeBitmap(vFile.absolutePath, width)
|
|
||||||
bitmapLruCache.put(src, bitmap)
|
|
||||||
bitmap
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Coroutine.async {
|
|
||||||
putDebug("${vFile.absolutePath} 解码失败\n$e", e)
|
|
||||||
if (FileUtils.readText(vFile.absolutePath).isXml()) {
|
|
||||||
putDebug("${vFile.absolutePath}为xml,自动删除")
|
|
||||||
vFile.delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
errorBitmap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user