Skip to content

Instantly share code, notes, and snippets.

@AndreVero
Last active October 7, 2024 14:09
Show Gist options
  • Save AndreVero/7a7d4a5da54c577eb46ddfc1055b9e82 to your computer and use it in GitHub Desktop.
Save AndreVero/7a7d4a5da54c577eb46ddfc1055b9e82 to your computer and use it in GitHub Desktop.
val hashMap = ConcurrentHashMap<String, Bitmap?>()
job = scope.launch {
val bitmap = if (hashMap.containsKey(url)) {
hashMap[url]
} else {
val bitmap = loadBitmap(url)
if (!hashMap.containsKey(url)) {
hashMap[url] = bitmap
bitmap
} else {
hashMap[url]
}
}
withContext(Dispatchers.Main) {
setImageBitmap(bitmap)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment