@@ -3,8 +3,10 @@ package dev.shorthouse.coinwatch.ui.screen.market
3
3
import androidx.compose.animation.AnimatedVisibility
4
4
import androidx.compose.animation.scaleIn
5
5
import androidx.compose.animation.scaleOut
6
+ import androidx.compose.foundation.layout.Arrangement
6
7
import androidx.compose.foundation.layout.Box
7
- import androidx.compose.foundation.layout.PaddingValues
8
+ import androidx.compose.foundation.layout.Column
9
+ import androidx.compose.foundation.layout.Row
8
10
import androidx.compose.foundation.layout.Spacer
9
11
import androidx.compose.foundation.layout.fillMaxSize
10
12
import androidx.compose.foundation.layout.padding
@@ -14,13 +16,10 @@ import androidx.compose.foundation.lazy.rememberLazyListState
14
16
import androidx.compose.foundation.shape.CornerSize
15
17
import androidx.compose.foundation.shape.RoundedCornerShape
16
18
import androidx.compose.material.icons.Icons
17
- import androidx.compose.material.icons.rounded.CurrencyExchange
18
19
import androidx.compose.material.icons.rounded.KeyboardDoubleArrowUp
19
- import androidx.compose.material.icons.rounded.SwapVert
20
20
import androidx.compose.material3.ExperimentalMaterial3Api
21
21
import androidx.compose.material3.FloatingActionButtonDefaults
22
22
import androidx.compose.material3.Icon
23
- import androidx.compose.material3.IconButton
24
23
import androidx.compose.material3.MaterialTheme
25
24
import androidx.compose.material3.Scaffold
26
25
import androidx.compose.material3.SmallFloatingActionButton
@@ -51,9 +50,11 @@ import dev.shorthouse.coinwatch.ui.component.ErrorState
51
50
import dev.shorthouse.coinwatch.ui.component.pullrefresh.PullRefreshIndicator
52
51
import dev.shorthouse.coinwatch.ui.component.pullrefresh.pullRefresh
53
52
import dev.shorthouse.coinwatch.ui.component.pullrefresh.rememberPullRefreshState
53
+ import dev.shorthouse.coinwatch.ui.model.TimeOfDay
54
54
import dev.shorthouse.coinwatch.ui.previewdata.MarketUiStatePreviewProvider
55
55
import dev.shorthouse.coinwatch.ui.screen.market.component.CoinSortBottomSheet
56
56
import dev.shorthouse.coinwatch.ui.screen.market.component.CurrencyBottomSheet
57
+ import dev.shorthouse.coinwatch.ui.screen.market.component.MarketChip
57
58
import dev.shorthouse.coinwatch.ui.screen.market.component.MarketCoinItem
58
59
import dev.shorthouse.coinwatch.ui.screen.market.component.MarketEmptyState
59
60
import dev.shorthouse.coinwatch.ui.screen.market.component.MarketSkeletonLoader
@@ -80,11 +81,11 @@ fun MarketScreen(
80
81
onUpdateShowCoinSortBottomSheet = { showSheet ->
81
82
viewModel.updateShowCoinSortBottomSheet(showSheet)
82
83
},
83
- onUpdateCoinCurrency = { currency ->
84
- viewModel.updateCoinCurrency (currency)
84
+ onUpdateCurrency = { currency ->
85
+ viewModel.updateCurrency (currency)
85
86
},
86
- onUpdateShowCoinCurrencyBottomSheet = { showSheet ->
87
- viewModel.updateShowCoinCurrencyBottomSheet (showSheet)
87
+ onUpdateShowCurrencyBottomSheet = { showSheet ->
88
+ viewModel.onUpdateShowCurrencyBottomSheet (showSheet)
88
89
},
89
90
onRefresh = {
90
91
viewModel.pullRefreshCachedCoins()
@@ -99,8 +100,8 @@ fun MarketScreen(
99
100
onCoinClick : (CachedCoin ) -> Unit ,
100
101
onUpdateCoinSort : (CoinSort ) -> Unit ,
101
102
onUpdateShowCoinSortBottomSheet : (Boolean ) -> Unit ,
102
- onUpdateCoinCurrency : (Currency ) -> Unit ,
103
- onUpdateShowCoinCurrencyBottomSheet : (Boolean ) -> Unit ,
103
+ onUpdateCurrency : (Currency ) -> Unit ,
104
+ onUpdateShowCurrencyBottomSheet : (Boolean ) -> Unit ,
104
105
onRefresh : () -> Unit ,
105
106
modifier : Modifier = Modifier
106
107
) {
@@ -122,8 +123,7 @@ fun MarketScreen(
122
123
Scaffold (
123
124
topBar = {
124
125
MarketTopBar (
125
- onUpdateShowCoinSortBottomSheet = onUpdateShowCoinSortBottomSheet,
126
- onUpdateShowCoinCurrencyBottomSheet = onUpdateShowCoinCurrencyBottomSheet,
126
+ timeOfDay = uiState.timeOfDay,
127
127
scrollBehavior = scrollBehavior
128
128
)
129
129
},
@@ -149,6 +149,10 @@ fun MarketScreen(
149
149
MarketContent (
150
150
coins = uiState.coins,
151
151
onCoinClick = onCoinClick,
152
+ currency = uiState.currency,
153
+ onUpdateShowCurrencyBottomSheet = onUpdateShowCurrencyBottomSheet,
154
+ coinSort = uiState.coinSort,
155
+ onUpdateShowCoinSortBottomSheet = onUpdateShowCoinSortBottomSheet,
152
156
lazyListState = lazyListState,
153
157
modifier = Modifier .padding(scaffoldPadding)
154
158
)
@@ -172,22 +176,22 @@ fun MarketScreen(
172
176
)
173
177
}
174
178
175
- if (uiState.showCoinCurrencyBottomSheet ) {
179
+ if (uiState.showCurrencyBottomSheet ) {
176
180
CurrencyBottomSheet (
177
181
sheetState = currencySheetState,
178
- selectedCurrency = uiState.coinCurrency ,
182
+ selectedCurrency = uiState.currency ,
179
183
onCurrencySelected = { currency ->
180
- onUpdateCoinCurrency (currency)
184
+ onUpdateCurrency (currency)
181
185
182
186
scope.launch {
183
187
currencySheetState.hide()
184
188
}.invokeOnCompletion {
185
189
if (! currencySheetState.isVisible) {
186
- onUpdateShowCoinCurrencyBottomSheet (false )
190
+ onUpdateShowCurrencyBottomSheet (false )
187
191
}
188
192
}
189
193
},
190
- onDismissRequest = { onUpdateShowCoinCurrencyBottomSheet (false ) }
194
+ onDismissRequest = { onUpdateShowCurrencyBottomSheet (false ) }
191
195
)
192
196
}
193
197
}
@@ -237,35 +241,19 @@ fun MarketScreen(
237
241
@Composable
238
242
@OptIn(ExperimentalMaterial3Api ::class )
239
243
fun MarketTopBar (
240
- onUpdateShowCoinSortBottomSheet : (Boolean ) -> Unit ,
241
- onUpdateShowCoinCurrencyBottomSheet : (Boolean ) -> Unit ,
244
+ timeOfDay : TimeOfDay ,
242
245
scrollBehavior : TopAppBarScrollBehavior ,
243
246
modifier : Modifier = Modifier
244
247
) {
245
248
TopAppBar (
246
249
title = {
247
250
Text (
248
- text = stringResource(R .string.market_screen),
251
+ text = stringResource(R .string.time_of_day_prefix_good) +
252
+ " " + timeOfDay.name.lowercase(),
249
253
style = MaterialTheme .typography.titleMedium,
250
254
color = MaterialTheme .colorScheme.onBackground
251
255
)
252
256
},
253
- actions = {
254
- IconButton (onClick = { onUpdateShowCoinCurrencyBottomSheet(true ) }) {
255
- Icon (
256
- imageVector = Icons .Rounded .CurrencyExchange ,
257
- tint = MaterialTheme .colorScheme.onBackground,
258
- contentDescription = stringResource(R .string.top_bar_action_change_currency)
259
- )
260
- }
261
- IconButton (onClick = { onUpdateShowCoinSortBottomSheet(true ) }) {
262
- Icon (
263
- imageVector = Icons .Rounded .SwapVert ,
264
- tint = MaterialTheme .colorScheme.onBackground,
265
- contentDescription = stringResource(R .string.top_bar_action_sort_coins)
266
- )
267
- }
268
- },
269
257
colors = TopAppBarDefaults .topAppBarColors(
270
258
containerColor = MaterialTheme .colorScheme.background,
271
259
scrolledContainerColor = MaterialTheme .colorScheme.background
@@ -279,55 +267,75 @@ fun MarketTopBar(
279
267
fun MarketContent (
280
268
coins : ImmutableList <CachedCoin >,
281
269
onCoinClick : (CachedCoin ) -> Unit ,
270
+ currency : Currency ,
271
+ onUpdateShowCurrencyBottomSheet : (Boolean ) -> Unit ,
272
+ coinSort : CoinSort ,
273
+ onUpdateShowCoinSortBottomSheet : (Boolean ) -> Unit ,
282
274
lazyListState : LazyListState ,
283
275
modifier : Modifier = Modifier
284
276
) {
285
- if (coins.isEmpty()) {
286
- MarketEmptyState (
287
- modifier = modifier
288
- .fillMaxSize()
289
- .padding(12 .dp)
290
- )
291
- } else {
292
- LazyColumn (
293
- state = lazyListState,
294
- contentPadding = PaddingValues (horizontal = 12 .dp),
295
- modifier = modifier.fillMaxSize()
296
- ) {
297
- // Workaround for https://issuetracker.google.com/issues/209652366
298
- item(key = " 0" ) {
299
- Spacer (Modifier .padding(1 .dp))
300
- }
301
- items(
302
- count = coins.size,
303
- key = { coins[it].id },
304
- itemContent = { index ->
305
- val coinListItem = coins[index]
277
+ Column (
278
+ modifier = modifier
279
+ .fillMaxSize()
280
+ .padding(horizontal = 12 .dp)
281
+ ) {
282
+ Row (horizontalArrangement = Arrangement .spacedBy(8 .dp)) {
283
+ MarketChip (
284
+ label = currency.name.uppercase(),
285
+ onClick = { onUpdateShowCurrencyBottomSheet(true ) }
286
+ )
287
+ MarketChip (
288
+ label = stringResource(coinSort.nameId),
289
+ onClick = { onUpdateShowCoinSortBottomSheet(true ) }
290
+ )
291
+ }
306
292
307
- val cardShape = when (index) {
308
- 0 -> MaterialTheme .shapes.medium.copy(
309
- bottomStart = CornerSize (0 .dp),
310
- bottomEnd = CornerSize (0 .dp)
311
- )
293
+ if (coins.isEmpty()) {
294
+ MarketEmptyState (
295
+ modifier = Modifier
296
+ .fillMaxSize()
297
+ .padding(12 .dp)
298
+ )
299
+ } else {
300
+ LazyColumn (
301
+ state = lazyListState,
302
+ modifier = Modifier .fillMaxSize()
303
+ ) {
304
+ // Workaround for https://issuetracker.google.com/issues/209652366
305
+ item(key = " 0" ) {
306
+ Spacer (Modifier .padding(1 .dp))
307
+ }
308
+ items(
309
+ count = coins.size,
310
+ key = { coins[it].id },
311
+ itemContent = { index ->
312
+ val coinListItem = coins[index]
312
313
313
- coins.lastIndex -> MaterialTheme .shapes.medium.copy(
314
- topStart = CornerSize (0 .dp),
315
- topEnd = CornerSize (0 .dp)
316
- )
314
+ val cardShape = when (index) {
315
+ 0 -> MaterialTheme .shapes.medium.copy(
316
+ bottomStart = CornerSize (0 .dp),
317
+ bottomEnd = CornerSize (0 .dp)
318
+ )
319
+
320
+ coins.lastIndex -> MaterialTheme .shapes.medium.copy(
321
+ topStart = CornerSize (0 .dp),
322
+ topEnd = CornerSize (0 .dp)
323
+ )
324
+
325
+ else -> RoundedCornerShape (0 .dp)
326
+ }
317
327
318
- else -> RoundedCornerShape (0 .dp)
328
+ MarketCoinItem (
329
+ coin = coinListItem,
330
+ onCoinClick = { onCoinClick(coinListItem) },
331
+ cardShape = cardShape
332
+ )
319
333
}
334
+ )
320
335
321
- MarketCoinItem (
322
- coin = coinListItem,
323
- onCoinClick = { onCoinClick(coinListItem) },
324
- cardShape = cardShape
325
- )
336
+ item {
337
+ SearchPrompt (modifier = Modifier .padding(vertical = 12 .dp))
326
338
}
327
- )
328
-
329
- item {
330
- SearchPrompt (modifier = Modifier .padding(vertical = 12 .dp))
331
339
}
332
340
}
333
341
}
@@ -345,8 +353,8 @@ private fun MarketScreenPreview(
345
353
onUpdateCoinSort = {},
346
354
onUpdateShowCoinSortBottomSheet = {},
347
355
onRefresh = {},
348
- onUpdateCoinCurrency = {},
349
- onUpdateShowCoinCurrencyBottomSheet = {}
356
+ onUpdateCurrency = {},
357
+ onUpdateShowCurrencyBottomSheet = {}
350
358
)
351
359
}
352
360
}
0 commit comments