Skip to content

Commit

Permalink
Merge pull request #169 from niscy-eudiw/refactor/use_existing_class_…
Browse files Browse the repository at this point in the history
…for_success_deferred_modal_options

Refactor: Updated WrapModalBottomSheet to use ModalOptionUi.
  • Loading branch information
stzouvaras authored Aug 9, 2024
2 parents d30aedf + b3ebf95 commit ce65b95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ private fun DashboardSheetContent(
id = R.string.dashboard_bottom_sheet_deferred_documents_ready_subtitle
),
options = sheetContent.options,
onEventSent = onEventSent,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,7 +168,7 @@ sealed class DashboardBottomSheetContent {
data class DeferredDocumentPressed(val documentUi: DocumentUi) : DashboardBottomSheetContent()
data class DeferredDocumentsReady(
val successfullyIssuedDeferredDocuments: List<DeferredDocumentData>,
val options: List<OptionListItemUi>,
val options: List<ModalOptionUi<Event>>,
) : DashboardBottomSheetContent()
}

Expand Down Expand Up @@ -513,17 +512,14 @@ class DashboardViewModel(
}
}

private fun getBottomSheetOptions(deferredDocumentsData: List<DeferredDocumentData>): List<OptionListItemUi> {
private fun getBottomSheetOptions(deferredDocumentsData: List<DeferredDocumentData>): List<ModalOptionUi<Event>> {
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
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -174,10 +168,11 @@ fun DialogBottomSheet(
}

@Composable
fun BottomSheetWithOptionsList(
fun <T : ViewEvent> BottomSheetWithOptionsList(
title: String,
message: String,
options: List<OptionListItemUi>,
options: List<ModalOptionUi<T>>,
onEventSent: (T) -> Unit
) {
if (options.isNotEmpty()) {
GenericBaseSheetContent(
Expand All @@ -198,6 +193,7 @@ fun BottomSheetWithOptionsList(
) {
OptionsList(
optionItems = options,
itemSelected = onEventSent
)
}
}
Expand All @@ -206,35 +202,34 @@ fun BottomSheetWithOptionsList(
}

@Composable
fun OptionsList(
optionItems: List<OptionListItemUi>,
fun <T : ViewEvent> OptionsList(
optionItems: List<ModalOptionUi<T>>,
itemSelected: (T) -> Unit
) {
LazyColumn(
verticalArrangement = Arrangement.spacedBy(SPACING_SMALL.dp)
) {
items(optionItems) { item ->
OptionListItem(
item = item,
onItemSelected = {
item.onClick()
},
itemSelected = itemSelected
)
}
}
}

@Composable
fun OptionListItem(
item: OptionListItemUi,
onItemSelected: () -> Unit,
fun <T : ViewEvent> OptionListItem(
item: ModalOptionUi<T>,
itemSelected: (T) -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(SIZE_SMALL.dp))
.background(MaterialTheme.colorScheme.backgroundDefault)
.throttledClickable {
onItemSelected.invoke()
itemSelected(item.event)
}
.padding(
horizontal = SPACING_SMALL.dp,
Expand All @@ -245,7 +240,7 @@ fun OptionListItem(
) {
Text(
modifier = Modifier.weight(1f),
text = item.text,
text = item.title,
style = MaterialTheme.typography.bodyMedium
)
WrapIcon(
Expand Down Expand Up @@ -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<ModalOptionUi<ViewEvent>>(),
onEventSent = {}
)
}
}

0 comments on commit ce65b95

Please sign in to comment.