@@ -32,6 +32,7 @@ import androidx.compose.runtime.remember
3232import androidx.compose.runtime.setValue
3333import androidx.compose.ui.Alignment
3434import androidx.compose.ui.Modifier
35+ import androidx.compose.ui.draw.alpha
3536import androidx.compose.ui.draw.clipToBounds
3637import androidx.compose.ui.draw.rotate
3738import androidx.compose.ui.geometry.Offset
@@ -51,13 +52,13 @@ import androidx.compose.ui.unit.DpSize
5152import androidx.compose.ui.unit.IntOffset
5253import androidx.compose.ui.unit.IntSize
5354import androidx.compose.ui.unit.dp
55+ import androidx.compose.ui.unit.isSpecified
5456import androidx.core.content.ContextCompat
5557import com.getcode.R
5658import com.getcode.model.KinAmount
5759import com.getcode.solana.keys.Key32.Companion.kinMint
5860import com.getcode.solana.keys.base58
5961import com.getcode.theme.CodeTheme
60- import com.getcode.theme.White50
6162import com.getcode.util.formattedRaw
6263import com.getcode.ui.utils.nonScaledSp
6364import com.getcode.ui.utils.punchCircle
@@ -76,6 +77,8 @@ object CashBillDefaults {
7677 const val CodeBackgroundOpacity = 0.65f
7778
7879 const val SecurityStripCount = 3
80+
81+ val DecorColor : Color = Color (0xFFA9A9B1 )
7982}
8083
8184object CashBillAssets {
@@ -167,7 +170,7 @@ private class CashBillGeometry(width: Dp, height: Dp) {
167170 val globePosition: Offset
168171 get() = Offset (
169172 x = - (size.width.value * 1.25f ),
170- y = size.height.value * 1.2f
173+ y = size.height.value * 0.5f
171174 )
172175
173176
@@ -226,7 +229,7 @@ internal fun CashBill(
226229 }
227230
228231 // Hexagons
229- BillImage (
232+ BillDecorImage (
230233 modifier = Modifier
231234 .fillMaxSize(),
232235 image = ImageBitmap .imageResource(R .drawable.ic_bill_hexagons),
@@ -236,7 +239,7 @@ internal fun CashBill(
236239 )
237240
238241 // Waves
239- BillImage (
242+ BillDecorImage (
240243 modifier = Modifier
241244 .matchParentSize()
242245 .clipToBounds(),
@@ -248,16 +251,17 @@ internal fun CashBill(
248251 )
249252
250253 // Globe
251- BillImage (
254+ BillDecorImage (
252255 modifier = Modifier
253256 .matchParentSize()
254257 .clipToBounds(),
258+ size = DpSize (width = geometry.size.width * 1.45f , height = Dp .Unspecified ),
255259 image = CashBillAssets .globe,
256260 topLeft = geometry.globePosition
257261 )
258262
259263 // Grid pattern
260- BillImage (
264+ BillDecorImage (
261265 modifier = Modifier
262266 .matchParentSize()
263267 .clipToBounds(),
@@ -317,7 +321,7 @@ internal fun CashBill(
317321 Text (
318322 text = kinMint.base58(),
319323 fontSize = 8 .nonScaledSp,
320- color = CodeTheme .colors.onBackground.copy(alpha = 0.60f )
324+ color = CashBillDefaults . DecorColor ,
321325 )
322326 }
323327
@@ -330,10 +334,11 @@ internal fun CashBill(
330334 Image (
331335 modifier = Modifier
332336 .width(geometry.brandWidth),
337+ contentScale = ContentScale .FillWidth ,
333338 painter = painterResource(
334339 R .drawable.ic_code_logo_offwhite_small
335340 ),
336- colorFilter = ColorFilter .tint(CodeTheme .colors.onBackground.copy(alpha = 0.60f ) ),
341+ colorFilter = ColorFilter .tint(CashBillDefaults . DecorColor ),
337342 contentDescription = " " ,
338343 )
339344 Spacer (modifier = Modifier .weight(1f ))
@@ -343,20 +348,11 @@ internal fun CashBill(
343348 }
344349
345350 // Scan code
346- Box (
347- modifier = Modifier
348- .align(Alignment .Center )
349- .punchCircle(CashBillDefaults .BillColor .copy(CashBillDefaults .CodeBackgroundOpacity )),
350- contentAlignment = Alignment .Center
351- ) {
352- if (payloadData.isNotEmpty()) {
353- ScannableCode (
354- modifier = Modifier
355- .size(geometry.codeSize),
356- data = payloadData
357- )
358- }
359- }
351+ BillCode (
352+ modifier = Modifier .align(Alignment .Center ),
353+ geometry = geometry,
354+ data = payloadData
355+ )
360356 }
361357 }
362358}
@@ -370,11 +366,13 @@ private fun SecurityStrip(
370366 modifier = modifier
371367 .size(geometry.securityStripSize)
372368 .offset(geometry.securityStripPosition.x, geometry.securityStripPosition.y)
373- .punchRectangle(Color . Black .copy(0.6f )),
369+ .punchRectangle(CashBillDefaults . BillColor .copy(CashBillDefaults . CodeBackgroundOpacity )),
374370 ) {
375371 for (i in 0 until CashBillDefaults .SecurityStripCount ) {
376372 Image (
377- modifier = Modifier .weight(1f ),
373+ modifier = Modifier
374+ .weight(1f )
375+ .alpha(0.5f ),
378376 contentScale = ContentScale .FillBounds ,
379377 painter = painterResource(id = R .drawable.ic_bill_security_strip),
380378 contentDescription = null
@@ -394,7 +392,7 @@ private fun Lines(
394392 Box (
395393 modifier = Modifier
396394 .rotate(- 18f )
397- .background(White50 )
395+ .background(CashBillDefaults . DecorColor )
398396 .fillMaxHeight()
399397 .width(1 .dp)
400398 )
@@ -403,10 +401,11 @@ private fun Lines(
403401}
404402
405403@Composable
406- private fun BillImage (
404+ private fun BillDecorImage (
407405 modifier : Modifier = Modifier ,
408406 image : ImageBitmap ? ,
409407 alpha : Float = 1f,
408+ size : DpSize = DpSize .Unspecified ,
410409 topLeft : Offset = Offset .Zero ,
411410 blendMode : BlendMode = DrawScope .DefaultBlendMode ,
412411 fill : Boolean = false,
@@ -419,7 +418,10 @@ private fun BillImage(
419418 if (fill) {
420419 drawImage(
421420 image = it,
422- dstSize = IntSize (size.width.roundToInt(), size.height.roundToInt()),
421+ dstSize = IntSize (
422+ width = if (size.isSpecified && size.width.isSpecified) size.width.roundToPx() else this .size.width.toInt(),
423+ height = if (size.isSpecified && size.height.isSpecified) size.height.roundToPx() else this .size.height.toInt(),
424+ ),
423425 alpha = alpha,
424426 dstOffset = IntOffset (topLeft.x.roundToInt(), topLeft.y.roundToInt()),
425427 blendMode = blendMode,
@@ -428,10 +430,31 @@ private fun BillImage(
428430 drawImage(
429431 image = it,
430432 alpha = alpha,
433+ dstSize = IntSize (
434+ width = if (size.isSpecified && size.width.isSpecified) size.width.roundToPx() else this .size.width.toInt(),
435+ height = if (size.isSpecified && size.height.isSpecified) size.height.roundToPx() else this .size.height.toInt(),
436+ ),
431437 dstOffset = IntOffset (topLeft.x.roundToInt(), topLeft.y.roundToInt()),
432438 blendMode = blendMode,
433439 )
434440 }
435441 }
436442 }
437443}
444+
445+ @Composable
446+ private fun BillCode (modifier : Modifier = Modifier , geometry : CashBillGeometry , data : List <Byte >) {
447+ Box (
448+ modifier = modifier
449+ .punchCircle(CashBillDefaults .BillColor .copy(0.9f )),
450+ contentAlignment = Alignment .Center
451+ ) {
452+ if (data.isNotEmpty()) {
453+ ScannableCode (
454+ modifier = Modifier
455+ .size(geometry.codeSize),
456+ data = data
457+ )
458+ }
459+ }
460+ }
0 commit comments