forked from shihaam/thijooree
25 lines
742 B
Kotlin
25 lines
742 B
Kotlin
package sh.sar.basedbank.util
|
|
|
|
import android.content.Context
|
|
import android.graphics.Bitmap
|
|
import android.graphics.BitmapFactory
|
|
import java.io.File
|
|
|
|
object ContactImageCache {
|
|
|
|
private fun file(context: Context, hash: String) =
|
|
File(context.cacheDir, "cimg_${hash.replace(Regex("[^A-Za-z0-9]"), "_")}.png")
|
|
|
|
fun save(context: Context, hash: String, bitmap: Bitmap) {
|
|
try {
|
|
file(context, hash).outputStream().use {
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 90, it)
|
|
}
|
|
} catch (_: Exception) {}
|
|
}
|
|
|
|
fun load(context: Context, hash: String): Bitmap? = try {
|
|
BitmapFactory.decodeFile(file(context, hash).absolutePath)
|
|
} catch (_: Exception) { null }
|
|
}
|