@@ -27,6 +27,7 @@ import androidx.compose.runtime.Composable
27
27
import androidx.compose.runtime.getValue
28
28
import androidx.compose.ui.Alignment
29
29
import androidx.compose.ui.Modifier
30
+ import androidx.compose.ui.draw.clip
30
31
import androidx.compose.ui.graphics.Color
31
32
import androidx.compose.ui.graphics.Shape
32
33
import androidx.compose.ui.res.stringResource
@@ -47,6 +48,7 @@ import com.wisnu.kurniawan.wallee.foundation.uicomponent.PgIcon
47
48
import com.wisnu.kurniawan.wallee.foundation.uicomponent.PgIconButton
48
49
import com.wisnu.kurniawan.wallee.foundation.uicomponent.PgPageLayout
49
50
import com.wisnu.kurniawan.wallee.foundation.viewmodel.HandleEffect
51
+ import com.wisnu.kurniawan.wallee.model.Currency
50
52
51
53
@OptIn(ExperimentalLifecycleComposeApi ::class )
52
54
@Composable
@@ -160,6 +162,7 @@ private fun Content(
160
162
161
163
CurrencyCell (
162
164
data = items,
165
+ selectedCurrency = state.selectedCurrency,
163
166
onItemClick = onItemClick,
164
167
)
165
168
@@ -171,7 +174,8 @@ private fun Content(
171
174
172
175
@OptIn(ExperimentalFoundationApi ::class )
173
176
private inline fun LazyListScope.CurrencyCell (
174
- data : Map <Char , List <CurrencyItem >>,
177
+ data : Map <String , List <CurrencyItem >>,
178
+ selectedCurrency : Currency ? ,
175
179
noinline onItemClick : (CurrencyItem ) -> Unit ,
176
180
) {
177
181
item {
@@ -187,31 +191,33 @@ private inline fun LazyListScope.CurrencyCell(
187
191
SpacerHeadline2 ()
188
192
}
189
193
190
- data.forEach { (initial, currenciesForInitial) ->
191
- stickyHeader {
192
- Box (
193
- modifier = Modifier
194
- .fillMaxWidth()
195
- .background(color = MaterialTheme .colorScheme.surface)
196
- ) {
197
- Text (
198
- style = MaterialTheme .typography.titleSmall.copy(color = MaterialTheme .colorScheme.onBackground, fontSize = 16 .sp),
199
- text = initial.toString(),
200
- modifier = Modifier .padding(horizontal = 32 .dp, vertical = 8 .dp)
201
- )
194
+ data.forEach { (title, currencies) ->
195
+ if (title.isNotBlank()) {
196
+ stickyHeader {
197
+ Box (
198
+ modifier = Modifier
199
+ .fillMaxWidth()
200
+ .background(color = MaterialTheme .colorScheme.surface)
201
+ ) {
202
+ Text (
203
+ style = MaterialTheme .typography.titleSmall.copy(color = MaterialTheme .colorScheme.onBackground, fontSize = 16 .sp),
204
+ text = title,
205
+ modifier = Modifier .padding(horizontal = 32 .dp, vertical = 8 .dp)
206
+ )
207
+ }
202
208
}
203
209
}
204
210
205
- val size = currenciesForInitial .size
211
+ val size = currencies .size
206
212
itemsIndexed(
207
- items = currenciesForInitial ,
208
- key = { _ , item -> item.currency.countryCode + item.currency.currencyCode }
213
+ items = currencies ,
214
+ key = { index , item -> index.toString() + item.currency.countryCode + item.currency.currencyCode }
209
215
) { index, item ->
210
216
CurrencyItemCell (
211
217
currencySymbol = item.currencySymbol,
212
218
flag = item.flag,
213
219
countryName = item.countryName,
214
- selected = item.selected ,
220
+ selected = item.currency == selectedCurrency ,
215
221
shape = cellShape(index, size),
216
222
showDivider = shouldShowDivider(index, size),
217
223
onClick = { onItemClick(item) }
@@ -234,6 +240,7 @@ private fun CurrencyItemCell(
234
240
modifier = Modifier
235
241
.fillMaxWidth()
236
242
.padding(horizontal = 16 .dp)
243
+ .clip(shape)
237
244
.clickable(onClick = onClick),
238
245
shape = shape,
239
246
color = MaterialTheme .colorScheme.secondary,
0 commit comments