|
| 1 | +package team.aliens.dms.android.core.designsystem.card |
| 2 | + |
| 3 | +import androidx.annotation.DrawableRes |
| 4 | +import androidx.compose.animation.animateColorAsState |
| 5 | +import androidx.compose.foundation.Image |
| 6 | +import androidx.compose.foundation.background |
| 7 | +import androidx.compose.foundation.border |
| 8 | +import androidx.compose.foundation.layout.Arrangement |
| 9 | +import androidx.compose.foundation.layout.Column |
| 10 | +import androidx.compose.foundation.layout.Row |
| 11 | +import androidx.compose.foundation.layout.Spacer |
| 12 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 13 | +import androidx.compose.foundation.layout.padding |
| 14 | +import androidx.compose.foundation.layout.size |
| 15 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 16 | +import androidx.compose.material3.Icon |
| 17 | +import androidx.compose.material3.Text |
| 18 | +import androidx.compose.runtime.Composable |
| 19 | +import androidx.compose.runtime.getValue |
| 20 | +import androidx.compose.ui.Alignment |
| 21 | +import androidx.compose.ui.Modifier |
| 22 | +import androidx.compose.ui.draw.clip |
| 23 | +import androidx.compose.ui.res.painterResource |
| 24 | +import androidx.compose.ui.unit.dp |
| 25 | +import team.aliens.dms.android.core.designsystem.DmsTheme |
| 26 | +import team.aliens.dms.android.core.designsystem.bodyB |
| 27 | +import team.aliens.dms.android.core.designsystem.endPadding |
| 28 | +import team.aliens.dms.android.core.designsystem.foundation.DmsIcon |
| 29 | +import team.aliens.dms.android.core.designsystem.labelB |
| 30 | +import team.aliens.dms.android.core.designsystem.labelM |
| 31 | +import team.aliens.dms.android.core.designsystem.util.clickable |
| 32 | + |
| 33 | +@Composable |
| 34 | +fun DmsApplicationCard( |
| 35 | + modifier: Modifier = Modifier, |
| 36 | + title: String, |
| 37 | + description: String? = null, |
| 38 | + period: String? = null, |
| 39 | + appliedTitle: String? = null, |
| 40 | + @DrawableRes iconRes: Int, |
| 41 | + isSelected: Boolean = false, |
| 42 | + onClick: () -> Unit, |
| 43 | +) { |
| 44 | + val borderColor by animateColorAsState( |
| 45 | + targetValue = if (isSelected) { |
| 46 | + DmsTheme.colorScheme.onPrimaryContainer |
| 47 | + } else { |
| 48 | + DmsTheme.colorScheme.surfaceTint |
| 49 | + }, |
| 50 | + ) |
| 51 | + Column( |
| 52 | + modifier = modifier |
| 53 | + .fillMaxWidth() |
| 54 | + .clip(RoundedCornerShape(32.dp)) |
| 55 | + .background(DmsTheme.colorScheme.surfaceTint) |
| 56 | + .clickable(onClick = onClick) |
| 57 | + .border( |
| 58 | + width = 2.dp, |
| 59 | + color = borderColor, |
| 60 | + shape = RoundedCornerShape(32.dp), |
| 61 | + ) |
| 62 | + .padding(horizontal = 16.dp, vertical = 24.dp), |
| 63 | + verticalArrangement = Arrangement.spacedBy(8.dp), |
| 64 | + ) { |
| 65 | + Row( |
| 66 | + verticalAlignment = Alignment.CenterVertically, |
| 67 | + ) { |
| 68 | + Image( |
| 69 | + modifier = Modifier.size(32.dp), |
| 70 | + painter = painterResource(iconRes), |
| 71 | + contentDescription = null, |
| 72 | + ) |
| 73 | + Text( |
| 74 | + modifier = Modifier.padding(start = 8.dp), |
| 75 | + text = title, |
| 76 | + style = DmsTheme.typography.bodyB, |
| 77 | + color = DmsTheme.colorScheme.inverseOnSurface, |
| 78 | + ) |
| 79 | + Spacer(modifier = Modifier.weight(1f)) |
| 80 | + if (description == null && appliedTitle != null) { |
| 81 | + AppliedTitleText( |
| 82 | + modifier = Modifier.endPadding(16.dp), |
| 83 | + appliedTitle = appliedTitle, |
| 84 | + ) |
| 85 | + } |
| 86 | + Icon( |
| 87 | + painter = painterResource(DmsIcon.Forward), |
| 88 | + tint = DmsTheme.colorScheme.scrim, |
| 89 | + contentDescription = null, |
| 90 | + ) |
| 91 | + } |
| 92 | + period?.let { |
| 93 | + Text( |
| 94 | + text = period, |
| 95 | + style = DmsTheme.typography.labelM, |
| 96 | + color = DmsTheme.colorScheme.onPrimaryContainer, |
| 97 | + ) |
| 98 | + } |
| 99 | + description?.let { |
| 100 | + Row( |
| 101 | + verticalAlignment = Alignment.CenterVertically, |
| 102 | + horizontalArrangement = Arrangement.SpaceBetween, |
| 103 | + ) { |
| 104 | + Text( |
| 105 | + text = description, |
| 106 | + style = DmsTheme.typography.labelM, |
| 107 | + color = DmsTheme.colorScheme.inverseSurface, |
| 108 | + ) |
| 109 | + Spacer(modifier = Modifier.weight(1f)) |
| 110 | + appliedTitle?.let { |
| 111 | + AppliedTitleText(appliedTitle = appliedTitle) |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +@Composable |
| 119 | +private fun AppliedTitleText( |
| 120 | + modifier: Modifier = Modifier, |
| 121 | + appliedTitle: String, |
| 122 | +) { |
| 123 | + Text( |
| 124 | + modifier = modifier |
| 125 | + .background( |
| 126 | + color = DmsTheme.colorScheme.primary, |
| 127 | + shape = RoundedCornerShape(6.dp), |
| 128 | + ) |
| 129 | + .padding(horizontal = 22.dp, vertical = 8.dp), |
| 130 | + text = appliedTitle, |
| 131 | + style = DmsTheme.typography.labelB, |
| 132 | + color = DmsTheme.colorScheme.onPrimaryContainer, |
| 133 | + ) |
| 134 | +} |
0 commit comments