Updated on 2026-08-14

This commit is contained in:
Tangem 2019-11-18 14:30:47 +03:00
parent 4c0ef80dd8
commit e8073b746a
2 changed files with 10 additions and 4 deletions

View file

@ -158,13 +158,13 @@ class LocalStorage
@SuppressLint("ResourceType")
private fun putResourceArtworkToCatalog(resourceId: Int, forceSave: Boolean) {
context.resources.openRawResource(R.drawable.card_default).use { putArtworkToCatalog(context.resources.getResourceEntryName(resourceId), true, it.readBytes(), null, forceSave) }
context.resources.openRawResource(resourceId).use {
putArtworkToCatalog(context.resources.getResourceEntryName(resourceId), true, it.readBytes(), null, forceSave)
}
}
private fun putArtworkToCatalog(artworkId: String, isResource: Boolean, data: ByteArray, updateDate: Date?, forceSave: Boolean = true) {
val artworkInfo = ArtworkInfo(
isResource, Util.bytesToHex(Util.calculateSHA256(data)), updateDate
)
val artworkInfo = ArtworkInfo(isResource, calculateImageHash(data), updateDate)
artworks[artworkId.toLowerCase()] = artworkInfo
if (forceSave) {
val sArtworks = Gson().toJson(artworks)
@ -172,6 +172,12 @@ class LocalStorage
}
}
private fun calculateImageHash(data: ByteArray): String {
val encodedData = Util.bytesToHex(data).toUpperCase(Locale.US).toByteArray()
val hash = Util.calculateSHA256(encodedData)
return Util.bytesToHex(hash).toUpperCase(Locale.US)
}
private fun getArtworkBitmap(artworkId: String): Bitmap? {
if (artworkId.isBlank()) return null
val info = artworks[artworkId.toLowerCase()] ?: return null

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB

After

Width:  |  Height:  |  Size: 77 KiB

Before After
Before After