From b3ebf9567bd0c099b06be3658d156a7d516795ba Mon Sep 17 00:00:00 2001 From: Giannis Stamatopoulos Date: Fri, 9 Aug 2024 15:53:02 +0300 Subject: [PATCH] Refactor: Updated WrapModalBottomSheet to use ModalOptionUi. - Updated WrapModalBottomSheet to use ModalOptionUi instead of OptionListItemUi to make it more consistent with other components in the UI logic. - Removed OptionListItemUi data class. - Updated DashboardViewModel to use ModalOptionUi for bottom sheet options. --- .../ui/dashboard/DashboardScreen.kt | 1 + .../ui/dashboard/DashboardViewModel.kt | 20 +++----- .../component/wrap/WrapModalBottomSheet.kt | 51 +++++++------------ 3 files changed, 26 insertions(+), 46 deletions(-) diff --git a/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardScreen.kt b/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardScreen.kt index e16154cc..e617ade1 100644 --- a/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardScreen.kt +++ b/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardScreen.kt @@ -439,6 +439,7 @@ private fun DashboardSheetContent( id = R.string.dashboard_bottom_sheet_deferred_documents_ready_subtitle ), options = sheetContent.options, + onEventSent = onEventSent, ) } } diff --git a/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardViewModel.kt b/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardViewModel.kt index fcd815f8..5487db98 100644 --- a/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardViewModel.kt +++ b/dashboard-feature/src/main/java/eu/europa/ec/dashboardfeature/ui/dashboard/DashboardViewModel.kt @@ -42,7 +42,6 @@ import eu.europa.ec.resourceslogic.provider.ResourceProvider import eu.europa.ec.uilogic.component.AppIcons import eu.europa.ec.uilogic.component.ModalOptionUi import eu.europa.ec.uilogic.component.content.ContentErrorConfig -import eu.europa.ec.uilogic.component.wrap.OptionListItemUi import eu.europa.ec.uilogic.config.ConfigNavigation import eu.europa.ec.uilogic.config.NavigationType import eu.europa.ec.uilogic.mvi.MviViewModel @@ -169,7 +168,7 @@ sealed class DashboardBottomSheetContent { data class DeferredDocumentPressed(val documentUi: DocumentUi) : DashboardBottomSheetContent() data class DeferredDocumentsReady( val successfullyIssuedDeferredDocuments: List, - val options: List, + val options: List>, ) : DashboardBottomSheetContent() } @@ -513,17 +512,14 @@ class DashboardViewModel( } } - private fun getBottomSheetOptions(deferredDocumentsData: List): List { + private fun getBottomSheetOptions(deferredDocumentsData: List): List> { return deferredDocumentsData.map { - OptionListItemUi( - text = it.docName, - onClick = { - setEvent( - Event.BottomSheet.DeferredDocument.OptionListItemForSuccessfullyIssuingDeferredDocumentSelected( - documentId = it.documentId - ) - ) - } + ModalOptionUi( + title = it.docName, + icon = AppIcons.KeyboardArrowRight, + event = Event.BottomSheet.DeferredDocument.OptionListItemForSuccessfullyIssuingDeferredDocumentSelected( + documentId = it.documentId + ) ) } } diff --git a/ui-logic/src/main/java/eu/europa/ec/uilogic/component/wrap/WrapModalBottomSheet.kt b/ui-logic/src/main/java/eu/europa/ec/uilogic/component/wrap/WrapModalBottomSheet.kt index ffc450e9..7deb6637 100644 --- a/ui-logic/src/main/java/eu/europa/ec/uilogic/component/wrap/WrapModalBottomSheet.kt +++ b/ui-logic/src/main/java/eu/europa/ec/uilogic/component/wrap/WrapModalBottomSheet.kt @@ -43,8 +43,7 @@ import eu.europa.ec.resourceslogic.theme.values.backgroundDefault import eu.europa.ec.resourceslogic.theme.values.backgroundPaper import eu.europa.ec.resourceslogic.theme.values.textPrimaryDark import eu.europa.ec.resourceslogic.theme.values.textSecondaryDark -import eu.europa.ec.uilogic.component.AppIcons -import eu.europa.ec.uilogic.component.IconData +import eu.europa.ec.uilogic.component.ModalOptionUi import eu.europa.ec.uilogic.component.preview.PreviewTheme import eu.europa.ec.uilogic.component.preview.ThemeModePreviews import eu.europa.ec.uilogic.component.utils.SIZE_SMALL @@ -54,12 +53,7 @@ import eu.europa.ec.uilogic.component.utils.SPACING_MEDIUM import eu.europa.ec.uilogic.component.utils.SPACING_SMALL import eu.europa.ec.uilogic.component.utils.VSpacer import eu.europa.ec.uilogic.extension.throttledClickable - -data class OptionListItemUi( - val text: String, - val icon: IconData = AppIcons.KeyboardArrowRight, - val onClick: () -> Unit -) +import eu.europa.ec.uilogic.mvi.ViewEvent @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -174,10 +168,11 @@ fun DialogBottomSheet( } @Composable -fun BottomSheetWithOptionsList( +fun BottomSheetWithOptionsList( title: String, message: String, - options: List, + options: List>, + onEventSent: (T) -> Unit ) { if (options.isNotEmpty()) { GenericBaseSheetContent( @@ -198,6 +193,7 @@ fun BottomSheetWithOptionsList( ) { OptionsList( optionItems = options, + itemSelected = onEventSent ) } } @@ -206,8 +202,9 @@ fun BottomSheetWithOptionsList( } @Composable -fun OptionsList( - optionItems: List, +fun OptionsList( + optionItems: List>, + itemSelected: (T) -> Unit ) { LazyColumn( verticalArrangement = Arrangement.spacedBy(SPACING_SMALL.dp) @@ -215,18 +212,16 @@ fun OptionsList( items(optionItems) { item -> OptionListItem( item = item, - onItemSelected = { - item.onClick() - }, + itemSelected = itemSelected ) } } } @Composable -fun OptionListItem( - item: OptionListItemUi, - onItemSelected: () -> Unit, +fun OptionListItem( + item: ModalOptionUi, + itemSelected: (T) -> Unit ) { Row( modifier = Modifier @@ -234,7 +229,7 @@ fun OptionListItem( .clip(RoundedCornerShape(SIZE_SMALL.dp)) .background(MaterialTheme.colorScheme.backgroundDefault) .throttledClickable { - onItemSelected.invoke() + itemSelected(item.event) } .padding( horizontal = SPACING_SMALL.dp, @@ -245,7 +240,7 @@ fun OptionListItem( ) { Text( modifier = Modifier.weight(1f), - text = item.text, + text = item.title, style = MaterialTheme.typography.bodyMedium ) WrapIcon( @@ -276,20 +271,8 @@ private fun BottomSheetWithOptionsListPreview() { BottomSheetWithOptionsList( title = "Title", message = "Message", - options = listOf( - OptionListItemUi( - text = "Small Name", - onClick = {} - ), - OptionListItemUi( - text = "MediumMediumMediumMedium Name", - onClick = {} - ), - OptionListItemUi( - text = "LargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLargeLarge Name", - onClick = {} - ), - ), + options = listOf>(), + onEventSent = {} ) } } \ No newline at end of file