11package com.flipcash.app.core.ui
22
33import androidx.compose.foundation.Image
4+ import androidx.compose.foundation.border
45import androidx.compose.foundation.clickable
56import androidx.compose.foundation.layout.Arrangement
67import androidx.compose.foundation.layout.PaddingValues
@@ -11,7 +12,8 @@ import androidx.compose.foundation.layout.size
1112import androidx.compose.foundation.layout.width
1213import androidx.compose.foundation.layout.wrapContentWidth
1314import androidx.compose.foundation.shape.CircleShape
14- import androidx.compose.material.Text
15+ import androidx.compose.material3.Icon
16+ import androidx.compose.material3.Text
1517import androidx.compose.runtime.Composable
1618import androidx.compose.ui.Alignment
1719import androidx.compose.ui.Modifier
@@ -20,30 +22,56 @@ import androidx.compose.ui.graphics.painter.Painter
2022import androidx.compose.ui.res.painterResource
2123import androidx.compose.ui.text.TextStyle
2224import androidx.compose.ui.unit.Dp
25+ import androidx.compose.ui.unit.dp
2326import com.flipcash.core.R
2427import com.getcode.opencode.compose.LocalExchange
2528import com.getcode.opencode.model.financial.Fiat
2629import com.getcode.opencode.model.financial.Token
2730import com.getcode.opencode.model.financial.TokenWithBalance
2831import com.getcode.opencode.model.financial.TokenWithLocalizedBalance
2932import com.getcode.theme.CodeTheme
33+ import com.getcode.theme.White20
34+ import com.getcode.theme.extraSmall
3035import com.getcode.ui.components.text.AnimatedNumberText
3136import com.getcode.ui.core.addIf
3237
33- data class TokenBalanceRowSizing (
38+ sealed interface TokenBalanceStyle {
39+ val textStyle: TextStyle
40+
41+ data class Large (override val textStyle : TextStyle = TextStyle .Default ) : TokenBalanceStyle
42+ data class Pill (override val textStyle : TextStyle = TextStyle .Default ) : TokenBalanceStyle
43+ }
44+
45+ enum class TokenSelectionStyle {
46+ None ,
47+ Chevron ,
48+ Checkbox ,
49+ ;
50+ }
51+
52+ data class TokenBalanceRowStyling (
3453 val nameTextStyle : TextStyle ,
35- val balanceTextStyle : TextStyle ,
54+ val balanceDisplayStyle : TokenBalanceStyle ,
3655 val iconSize : Dp ,
3756 val flagSize : Dp ,
57+ val selectionStyle : TokenSelectionStyle ,
3858)
3959
4060@Composable
41- fun rememberTokenBalanceRowSizing (
61+ fun rememberTokenBalanceRowStyling (
4262 nameTextStyle : TextStyle = CodeTheme .typography.screenTitle,
43- balanceTextStyle : TextStyle = CodeTheme .typography.screenTitle ,
63+ balanceDisplayStyle : TokenBalanceStyle = TokenBalanceStyle . Large () ,
4464 iconSize : Dp = CodeTheme .dimens.staticGrid.x6,
4565 flagSize : Dp = CodeTheme .dimens.staticGrid.x3,
46- ): TokenBalanceRowSizing = TokenBalanceRowSizing (nameTextStyle, balanceTextStyle, iconSize, flagSize)
66+ selectionStyle : TokenSelectionStyle = TokenSelectionStyle .None ,
67+ ): TokenBalanceRowStyling =
68+ TokenBalanceRowStyling (
69+ nameTextStyle = nameTextStyle,
70+ balanceDisplayStyle = balanceDisplayStyle,
71+ iconSize = iconSize,
72+ flagSize = flagSize,
73+ selectionStyle = selectionStyle
74+ )
4775
4876@Composable
4977fun TokenBalanceRow (
@@ -56,7 +84,7 @@ fun TokenBalanceRow(
5684 iconOverride : @Composable ((Any? ) -> Any? ) = { it },
5785 formattedBalance : (Fiat ) -> String = { it.formatted() },
5886 horizontalArrangement : Arrangement .Horizontal = Arrangement .SpaceBetween ,
59- sizing : TokenBalanceRowSizing = rememberTokenBalanceRowSizing (),
87+ styling : TokenBalanceRowStyling = rememberTokenBalanceRowStyling (),
6088 contentPadding : PaddingValues = PaddingValues (vertical = CodeTheme .dimens.inset),
6189 onClick : (() -> Unit )? = null,
6290) {
@@ -72,7 +100,7 @@ fun TokenBalanceRow(
72100 showName = showName,
73101 showFlag = showFlag,
74102 showLogo = showLogo,
75- sizing = sizing ,
103+ styling = styling ,
76104 horizontalArrangement = horizontalArrangement,
77105 contentPadding = contentPadding,
78106 onClick = onClick
@@ -90,7 +118,7 @@ fun TokenBalanceRow(
90118 iconOverride : @Composable ((Any? ) -> Any? ) = { it },
91119 formattedBalance : (Fiat ) -> String = { it.formatted() },
92120 horizontalArrangement : Arrangement .Horizontal = Arrangement .SpaceBetween ,
93- sizing : TokenBalanceRowSizing = rememberTokenBalanceRowSizing (),
121+ styling : TokenBalanceRowStyling = rememberTokenBalanceRowStyling (),
94122 contentPadding : PaddingValues = PaddingValues (vertical = CodeTheme .dimens.inset),
95123 onClick : (() -> Unit )? = null,
96124) {
@@ -104,7 +132,7 @@ fun TokenBalanceRow(
104132 showFlag = showFlag,
105133 isSelected = isSelected,
106134 modifier = modifier,
107- sizing = sizing ,
135+ styling = styling ,
108136 iconOverride = iconOverride,
109137 formattedBalance = formattedBalance,
110138 horizontalArrangement = horizontalArrangement,
@@ -127,7 +155,7 @@ fun TokenBalanceRow(
127155 iconOverride : @Composable ((Any? ) -> Any? ) = { it },
128156 formattedBalance : (Fiat ) -> String = { it.formatted() },
129157 horizontalArrangement : Arrangement .Horizontal = Arrangement .SpaceBetween ,
130- sizing : TokenBalanceRowSizing = rememberTokenBalanceRowSizing (),
158+ styling : TokenBalanceRowStyling = rememberTokenBalanceRowStyling (),
131159 contentPadding : PaddingValues = PaddingValues (vertical = CodeTheme .dimens.inset),
132160 onClick : (() -> Unit )? = null,
133161) {
@@ -150,8 +178,8 @@ fun TokenBalanceRow(
150178 token = token,
151179 iconOverride = iconOverride,
152180 displayName = { displayName },
153- imageSize = sizing .iconSize,
154- textStyle = sizing .nameTextStyle,
181+ imageSize = styling .iconSize,
182+ textStyle = styling .nameTextStyle,
155183 textColor = CodeTheme .colors.textMain,
156184 spacing = CodeTheme .dimens.grid.x2,
157185 )
@@ -162,19 +190,20 @@ fun TokenBalanceRow(
162190 is Painter -> Image (
163191 painter = image,
164192 contentDescription = null ,
165- modifier = Modifier .size(sizing .iconSize),
193+ modifier = Modifier .size(styling .iconSize),
166194 )
195+
167196 else -> TokenIcon (
168197 image = image,
169- modifier = Modifier .size(sizing .iconSize)
198+ modifier = Modifier .size(styling .iconSize)
170199 )
171200 }
172201 }
173202
174203 showName -> {
175204 Text (
176205 text = displayName,
177- style = sizing .nameTextStyle,
206+ style = styling .nameTextStyle,
178207 color = CodeTheme .colors.textMain,
179208 )
180209 }
@@ -190,33 +219,79 @@ fun TokenBalanceRow(
190219 flag?.let {
191220 Image (
192221 modifier = Modifier
193- .height(sizing .flagSize)
194- .width(sizing .flagSize)
222+ .height(styling .flagSize)
223+ .width(styling .flagSize)
195224 .clip(CircleShape ),
196225 painter = painterResource(it),
197226 contentDescription = " "
198227 )
199228 }
200229 }
201230
202- AnimatedNumberText (
203- value = formattedBalance(balance),
204- style = sizing.balanceTextStyle,
205- color = CodeTheme .colors.textMain,
206- )
207-
208- if (isSelected != null ) {
209- Image (
210- modifier = Modifier
211- .wrapContentWidth()
212- .padding(start = CodeTheme .dimens.grid.x3),
213- painter = painterResource(
214- if (isSelected)
215- R .drawable.ic_checked else R .drawable.ic_unchecked
216- ),
217- contentDescription = " "
218- )
231+ when (val displayStyle = styling.balanceDisplayStyle) {
232+ is TokenBalanceStyle .Large -> {
233+ val resolvedTextStyle = displayStyle.textStyle
234+ .takeUnless { it == TextStyle .Default }
235+ ? : CodeTheme .typography.screenTitle
236+
237+ AnimatedNumberText (
238+ value = formattedBalance(balance),
239+ style = resolvedTextStyle,
240+ color = CodeTheme .colors.textMain,
241+ )
242+ }
243+
244+ is TokenBalanceStyle .Pill -> {
245+ val resolvedTextStyle = displayStyle.textStyle
246+ .takeUnless { it == TextStyle .Default }
247+ ? : CodeTheme .typography.caption
248+
249+ Text (
250+ modifier = Modifier
251+ .padding(start = CodeTheme .dimens.grid.x1)
252+ .border(
253+ width = CodeTheme .dimens.border,
254+ color = White20 ,
255+ shape = CodeTheme .shapes.extraSmall,
256+ )
257+ .padding(
258+ horizontal = 4 .dp,
259+ vertical = 3 .dp
260+ ),
261+ text = formattedBalance(balance),
262+ color = CodeTheme .colors.textSecondary,
263+ style = resolvedTextStyle,
264+ )
265+ }
266+ }
267+
268+ when (styling.selectionStyle) {
269+ TokenSelectionStyle .Chevron -> {
270+ Icon (
271+ modifier = Modifier .padding(start = CodeTheme .dimens.grid.x1),
272+ painter = painterResource(R .drawable.ic_chevron_right),
273+ contentDescription = null ,
274+ tint = CodeTheme .colors.secondary,
275+ )
276+ }
277+
278+ TokenSelectionStyle .Checkbox -> {
279+ if (isSelected != null ) {
280+ Image (
281+ modifier = Modifier
282+ .wrapContentWidth()
283+ .padding(start = CodeTheme .dimens.grid.x3),
284+ painter = painterResource(
285+ if (isSelected)
286+ R .drawable.ic_checked else R .drawable.ic_unchecked
287+ ),
288+ contentDescription = " "
289+ )
290+ }
291+ }
292+
293+ TokenSelectionStyle .None -> Unit
219294 }
220295 }
221296 }
222- }
297+ }
0 commit comments