From e7a4746d228c1e9e0ea7bdaa27ed05619df1d7f2 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 1 Aug 2023 21:51:15 -0400 Subject: [PATCH] Faster method to generate the hex of a url --- .../java/com/vitorpamplona/amethyst/ui/components/Robohash.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/Robohash.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/Robohash.kt index e8f635e8f1..20c15f8733 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/Robohash.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/Robohash.kt @@ -13,6 +13,7 @@ import coil.fetch.Fetcher import coil.fetch.SourceResult import coil.request.ImageRequest import coil.request.Options +import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.service.CryptoUtils import com.vitorpamplona.amethyst.service.checkNotInMainThread import okio.Buffer @@ -36,7 +37,7 @@ private fun svgString(msg: String): String { checkNotInMainThread() val hash = CryptoUtils.sha256(msg.toByteArray()) - val hashHex = hash.joinToString(separator = "") { b -> "%02x".format(b) } + val hashHex = hash.toHexKey() val bgColor = bytesToRGB(hash[0], hash[1], hash[2]) val fgColor = bytesToRGB(hash[3], hash[4], hash[5]) val bodyIndex = byteMod10(hash[6])