diff options
author | Iván Ávalos <avalos@disroot.org> | 2024-03-04 15:34:46 -0600 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2024-03-06 14:18:55 -0300 |
commit | da3d59bcabc0195f09f1259ded4058b6e9b5c385 (patch) | |
tree | 0dad6aa46ebeed311e51f09c44d083324cd2225b | |
parent | 6120660ee0f3417a740981dd1b39eeb21405afe0 (diff) | |
download | taler-android-da3d59bcabc0195f09f1259ded4058b6e9b5c385.tar.gz taler-android-da3d59bcabc0195f09f1259ded4058b6e9b5c385.tar.bz2 taler-android-da3d59bcabc0195f09f1259ded4058b6e9b5c385.zip |
[wallet] Fix NullPointerException in base64 decoding of product image
bug 0008505
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt b/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt index 35ec18b..289f0d7 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt @@ -67,17 +67,18 @@ internal class ProductAdapter(private val listener: ProductImageClickListener) : fun bind(product: ContractProduct) { quantity.text = product.quantity.toString() - if (product.image == null) { + val productImage = product.image + if (productImage == null) { image.visibility = GONE - } else { - image.visibility = VISIBLE - // product.image was validated before, so non-null below - val match = REGEX_PRODUCT_IMAGE.matchEntire(product.image!!)!! - val decodedString = Base64.decode(match.groups[2]!!.value, Base64.DEFAULT) - val bitmap = decodeByteArray(decodedString, 0, decodedString.size) - image.setImageBitmap(bitmap) - image.setOnClickListener { - listener.onImageClick(bitmap) + } else REGEX_PRODUCT_IMAGE.matchEntire(productImage)?.let { match -> + match.groups[2]?.value?.let { group -> + image.visibility = VISIBLE + val decodedString = Base64.decode(group, Base64.DEFAULT) + val bitmap = decodeByteArray(decodedString, 0, decodedString.size) + image.setImageBitmap(bitmap) + image.setOnClickListener { + listener.onImageClick(bitmap) + } } } name.text = product.description |