taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

MerchantAvatar.kt (2891B)


      1 /*
      2  * This file is part of GNU Taler
      3  * (C) 2026 Taler Systems S.A.
      4  *
      5  * GNU Taler is free software; you can redistribute it and/or modify it under the
      6  * terms of the GNU General Public License as published by the Free Software
      7  * Foundation; either version 3, or (at your option) any later version.
      8  *
      9  * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
     10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11  * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License along with
     14  * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 
     17 package net.taler.wallet.compose
     18 
     19 import android.graphics.Bitmap
     20 import androidx.compose.foundation.Image
     21 import androidx.compose.foundation.background
     22 import androidx.compose.foundation.clickable
     23 import androidx.compose.foundation.layout.Box
     24 import androidx.compose.foundation.layout.fillMaxSize
     25 import androidx.compose.foundation.layout.size
     26 import androidx.compose.foundation.shape.CircleShape
     27 import androidx.compose.material.icons.Icons
     28 import androidx.compose.material.icons.filled.Store
     29 import androidx.compose.material3.Icon
     30 import androidx.compose.material3.MaterialTheme
     31 import androidx.compose.runtime.Composable
     32 import androidx.compose.runtime.remember
     33 import androidx.compose.ui.Alignment
     34 import androidx.compose.ui.Modifier
     35 import androidx.compose.ui.draw.clip
     36 import androidx.compose.ui.graphics.Color
     37 import androidx.compose.ui.graphics.asImageBitmap
     38 import androidx.compose.ui.unit.Dp
     39 import androidx.compose.ui.unit.dp
     40 import net.taler.common.Merchant
     41 import net.taler.lib.android.base64Bitmap
     42 
     43 @Composable
     44 fun MerchantAvatar(
     45     merchantInfo: Merchant?,
     46     modifier: Modifier = Modifier,
     47     size: Dp = 60.dp,
     48     onClickImage: ((Bitmap) -> Unit) = {},
     49 ) {
     50     val logo = remember(merchantInfo?.logo) { merchantInfo?.logo?.base64Bitmap }
     51 
     52     Box(
     53         modifier
     54             .size(size)
     55             .background(
     56                 shape = CircleShape,
     57                 color = if (logo != null) {
     58                     Color.White
     59                 } else {
     60                     MaterialTheme.colorScheme.surfaceVariant
     61                 },
     62             )
     63             .clip(CircleShape)
     64             .clickable { if (logo != null) onClickImage(logo) },
     65         contentAlignment = Alignment.Center,
     66     ) {
     67         if (logo != null) {
     68             Image(
     69                 logo.asImageBitmap(),
     70                 modifier = Modifier.fillMaxSize(),
     71                 contentDescription = null,
     72             )
     73         } else {
     74             Icon(
     75                 Icons.Default.Store,
     76                 modifier = Modifier.fillMaxSize(0.54f),
     77                 tint = MaterialTheme.colorScheme.onSurfaceVariant,
     78                 contentDescription = null,
     79             )
     80         }
     81     }
     82 }