|
| 1 | +/* |
| 2 | + * Copyright 2024 Marlonlom |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package dev.marlonlom.apps.cappajv.features.catalog_list.screens |
| 7 | + |
| 8 | +import androidx.compose.foundation.ExperimentalFoundationApi |
| 9 | +import androidx.compose.foundation.background |
| 10 | +import androidx.compose.foundation.layout.Arrangement |
| 11 | +import androidx.compose.foundation.layout.Column |
| 12 | +import androidx.compose.foundation.layout.ExperimentalLayoutApi |
| 13 | +import androidx.compose.foundation.layout.Row |
| 14 | +import androidx.compose.foundation.layout.fillMaxHeight |
| 15 | +import androidx.compose.foundation.layout.fillMaxSize |
| 16 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 17 | +import androidx.compose.foundation.layout.padding |
| 18 | +import androidx.compose.foundation.layout.safeContentPadding |
| 19 | +import androidx.compose.foundation.lazy.LazyListState |
| 20 | +import androidx.compose.material3.MaterialTheme |
| 21 | +import androidx.compose.runtime.Composable |
| 22 | +import androidx.compose.ui.Alignment |
| 23 | +import androidx.compose.ui.Modifier |
| 24 | +import androidx.compose.ui.unit.dp |
| 25 | +import dev.marlonlom.apps.cappajv.core.database.entities.CatalogItemTuple |
| 26 | +import dev.marlonlom.apps.cappajv.features.catalog_list.parts.CatalogListHeadline |
| 27 | +import dev.marlonlom.apps.cappajv.features.catalog_list.slots.CatalogCategoriesChipGroup |
| 28 | +import dev.marlonlom.apps.cappajv.features.catalog_list.slots.CatalogListBanner |
| 29 | +import dev.marlonlom.apps.cappajv.features.catalog_list.slots.CatalogListTuplesSlot |
| 30 | +import dev.marlonlom.apps.cappajv.ui.layout.DevicePosture |
| 31 | +import dev.marlonlom.apps.cappajv.ui.main.CappajvAppState |
| 32 | + |
| 33 | + |
| 34 | +/** |
| 35 | + * TableTop catalog list screen composable ui. |
| 36 | + * |
| 37 | + * @author marlonlom |
| 38 | + * |
| 39 | + * @param appState Application ui state. |
| 40 | + * @param catalogItemsListState Catalog items lazy list state. |
| 41 | + * @param catalogItems Catalog items list. |
| 42 | + * @param categories Categories list. |
| 43 | + * @param selectedCategory Selected category name. |
| 44 | + * @param onSelectedCategoryChanged Action for category selected. |
| 45 | + * @param onCatalogItemSelected Action for catalog item selected. |
| 46 | + * @param modifier Modifier for this composable. |
| 47 | + */ |
| 48 | +@ExperimentalLayoutApi |
| 49 | +@ExperimentalFoundationApi |
| 50 | +@Composable |
| 51 | +fun TableTopCatalogListScreen( |
| 52 | + appState: CappajvAppState, |
| 53 | + catalogItemsListState: LazyListState, |
| 54 | + catalogItems: List<CatalogItemTuple>, |
| 55 | + categories: List<String>, |
| 56 | + selectedCategory: String, |
| 57 | + onSelectedCategoryChanged: (String) -> Unit, |
| 58 | + onCatalogItemSelected: (Long) -> Unit, |
| 59 | + modifier: Modifier = Modifier, |
| 60 | +) { |
| 61 | + val hingeRatio = (appState.devicePosture as DevicePosture.Separating.TableTop).hingeRatio |
| 62 | + |
| 63 | + Column( |
| 64 | + modifier = modifier.fillMaxWidth(), |
| 65 | + ) { |
| 66 | + Row( |
| 67 | + modifier = modifier.fillMaxHeight(hingeRatio), |
| 68 | + horizontalArrangement = Arrangement.spacedBy(20.dp) |
| 69 | + ) { |
| 70 | + Column(modifier = modifier.fillMaxWidth(0.45f)) { |
| 71 | + CatalogListHeadline(appState) |
| 72 | + CatalogListBanner(appState) |
| 73 | + CatalogCategoriesChipGroup( |
| 74 | + categories = categories, |
| 75 | + selectedCategory = selectedCategory, |
| 76 | + onCategoryChipSelected = { onSelectedCategoryChanged(it) }, |
| 77 | + ) |
| 78 | + } |
| 79 | + Column(modifier = modifier.safeContentPadding()) { |
| 80 | + CatalogListTuplesSlot( |
| 81 | + appState = appState, |
| 82 | + catalogItemsListState = catalogItemsListState, |
| 83 | + catalogTuples = catalogItems, |
| 84 | + onCatalogItemTupleClicked = onCatalogItemSelected, |
| 85 | + ) |
| 86 | + } |
| 87 | + } |
| 88 | + Row( |
| 89 | + modifier = modifier |
| 90 | + .fillMaxSize() |
| 91 | + .padding(top = 30.dp) |
| 92 | + .safeContentPadding() |
| 93 | + .background( |
| 94 | + MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.25f) |
| 95 | + ), |
| 96 | + ) { |
| 97 | + |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments