Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Updated WrapModalBottomSheet to use ModalOptionUi. #169

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {}
)
}
}
Loading