Skip to content

Commit

Permalink
Merge pull request #798 from Orange-OpenSource/794-update-odschoicech…
Browse files Browse the repository at this point in the history
…ipsflowrow-api-to-make-it-consistent-with-odstabrow

794 - Update OdsChoiceChipsFlowRow API
  • Loading branch information
paulinea authored Jan 29, 2024
2 parents b0de2f5 + a883d5e commit be324c4
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.app.ui.utilities.composable.TechnicalText
import com.orange.ods.compose.OdsComposable
import com.orange.ods.compose.component.appbar.top.OdsTopAppBar
import com.orange.ods.compose.component.chip.OdsChoiceChip
import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow
import com.orange.ods.compose.component.menu.OdsDropdownMenu
import com.orange.ods.compose.text.OdsText
Expand Down Expand Up @@ -161,42 +160,31 @@ fun LargeTopAppBarBottomSheetContent() {
with(LocalTopAppBarCustomizationState.current) {
Subtitle(textRes = com.orange.ods.app.R.string.component_app_bars_top_large_scroll_behavior, horizontalPadding = true)
OdsChoiceChipsFlowRow(
value = scrollBehavior.value,
onValueChange = { value -> scrollBehavior.value = value },
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(
text = stringResource(id = com.orange.ods.app.R.string.component_app_bars_top_large_scroll_behavior_none),
value = TopAppBarCustomizationState.ScrollBehavior.None
),
OdsChoiceChip(
text = stringResource(com.orange.ods.app.R.string.component_app_bars_top_large_scroll_behavior_collapsible),
value = TopAppBarCustomizationState.ScrollBehavior.Collapsible
)
)
selectedChoiceChipIndex = TopAppBarCustomizationState.ScrollBehavior.entries.indexOf(scrollBehavior.value),
choiceChips = TopAppBarCustomizationState.ScrollBehavior.entries.map { scrollBehavior ->
val textResId = when (scrollBehavior) {
TopAppBarCustomizationState.ScrollBehavior.None -> com.orange.ods.app.R.string.component_app_bars_top_large_scroll_behavior_none
TopAppBarCustomizationState.ScrollBehavior.Collapsible -> com.orange.ods.app.R.string.component_app_bars_top_large_scroll_behavior_collapsible
}
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = textResId), { this.scrollBehavior.value = scrollBehavior })
}
)

RegularTopAppBarBottomSheetContent()

Subtitle(textRes = com.orange.ods.app.R.string.component_element_title, horizontalPadding = true)
OdsChoiceChipsFlowRow(
value = title.value,
onValueChange = { value -> title.value = value },
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(
text = stringResource(id = com.orange.ods.app.R.string.component_app_bars_top_large_title_one_line),
value = TopAppBarCustomizationState.Title.Short
),
OdsChoiceChip(
text = stringResource(id = com.orange.ods.app.R.string.component_app_bars_top_large_title_two_lines),
value = TopAppBarCustomizationState.Title.TwoLines
),
OdsChoiceChip(
text = stringResource(id = com.orange.ods.app.R.string.component_app_bars_top_large_title_truncated),
value = TopAppBarCustomizationState.Title.Long
)
)
selectedChoiceChipIndex = TopAppBarCustomizationState.Title.entries.indexOf(title.value),
choiceChips = TopAppBarCustomizationState.Title.entries.map { title ->
val textResId = when (title) {
TopAppBarCustomizationState.Title.Short -> com.orange.ods.app.R.string.component_app_bars_top_large_title_one_line
TopAppBarCustomizationState.Title.TwoLines -> com.orange.ods.app.R.string.component_app_bars_top_large_title_two_lines
TopAppBarCustomizationState.Title.Long -> com.orange.ods.app.R.string.component_app_bars_top_large_title_truncated
}
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = textResId), { this.title.value = title })
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.app.ui.utilities.extension.buildImageRequest
import com.orange.ods.compose.OdsComposable
import com.orange.ods.compose.component.banner.OdsBanner
import com.orange.ods.compose.component.chip.OdsChoiceChip
import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow
import com.orange.ods.compose.component.listitem.OdsListItem
import com.orange.ods.extension.ifNotNull
Expand All @@ -67,15 +66,11 @@ fun ComponentBanners() {
bottomSheetContent = {
Subtitle(textRes = R.string.component_banner_message_example, horizontalPadding = true)
OdsChoiceChipsFlowRow(
value = shortMessage.value,
onValueChange = { value -> shortMessage.value = value },
selectedChoiceChipIndex = if (shortMessage.value) 0 else 1,
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(
text = stringResource(id = R.string.component_banner_message_example_short),
value = true
),
OdsChoiceChip(text = stringResource(id = R.string.component_banner_message_example_long), value = false)
choiceChips = listOf(
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = R.string.component_banner_message_example_short), { shortMessage.value = true }),
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = R.string.component_banner_message_example_long), { shortMessage.value = false })
)
)
ComponentCountRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.orange.ods.app.ui.components.utilities.ComponentCustomizationBottomSh
import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.compose.component.button.OdsButton
import com.orange.ods.compose.component.button.OdsTextButton
import com.orange.ods.compose.component.chip.OdsChoiceChip
import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow
import com.orange.ods.compose.component.listitem.OdsListItem
import com.orange.ods.compose.text.OdsText
Expand Down Expand Up @@ -64,32 +63,29 @@ fun ComponentButtons(variant: Variant) {
when (variant) {
Variant.ButtonsFunctional -> {
Subtitle(textRes = R.string.component_button_style_functional, horizontalPadding = true)
val buttonStyles = listOf(OdsButton.Style.FunctionalPositive, OdsButton.Style.FunctionalNegative)
OdsChoiceChipsFlowRow(
value = buttonStyle.value,
onValueChange = { value -> buttonStyle.value = value },
selectedChoiceChipIndex = buttonStyles.indexOf(buttonStyle.value),
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(
text = stringResource(id = R.string.component_button_style_functional_positive),
value = OdsButton.Style.FunctionalPositive
),
OdsChoiceChip(
text = stringResource(id = R.string.component_button_style_functional_negative),
value = OdsButton.Style.FunctionalNegative
)
)
choiceChips = buttonStyles.map { buttonStyle ->
val textResId =
if (buttonStyle == OdsButton.Style.FunctionalPositive) R.string.component_button_style_functional_positive else R.string.component_button_style_functional_negative
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = textResId), { this.buttonStyle.value = buttonStyle })
}
)
}
Variant.ButtonsText -> {
Subtitle(textRes = R.string.component_style, horizontalPadding = true)
OdsChoiceChipsFlowRow(
value = textButtonStyle.value,
onValueChange = { value -> textButtonStyle.value = value },
selectedChoiceChipIndex = OdsTextButton.Style.entries.indexOf(textButtonStyle.value),
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(text = stringResource(id = R.string.component_button_style_primary), value = OdsTextButton.Style.Primary),
OdsChoiceChip(text = stringResource(id = R.string.component_button_style_default), value = OdsTextButton.Style.Default)
)
choiceChips = OdsTextButton.Style.entries.map { textButtonStyle ->
val textResId = when (textButtonStyle) {
OdsTextButton.Style.Default -> R.string.component_button_style_default
OdsTextButton.Style.Primary -> R.string.component_button_style_primary
}
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = textResId), { this.textButtonStyle.value = textButtonStyle })
}
)
}
Variant.ButtonsTextToggleGroup -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.orange.ods.app.ui.components.utilities.ComponentCountRow
import com.orange.ods.app.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.compose.component.card.OdsCard
import com.orange.ods.compose.component.chip.OdsChoiceChip
import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow
import com.orange.ods.compose.component.listitem.OdsListItem

Expand All @@ -50,19 +49,15 @@ fun ComponentCard(variant: Variant) {
} else if (variant == Variant.CardHorizontal) {
Subtitle(textRes = R.string.component_card_horizontal_image_position, horizontalPadding = true)
OdsChoiceChipsFlowRow(
value = imagePosition.value,
onValueChange = { value -> imagePosition.value = value },
selectedChoiceChipIndex = OdsCard.Image.Position.entries.indexOf(imagePosition.value),
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(
text = stringResource(id = R.string.component_card_horizontal_image_position_start),
value = OdsCard.Image.Position.Start
),
OdsChoiceChip(
text = stringResource(id = R.string.component_card_horizontal_image_position_end),
value = OdsCard.Image.Position.End
)
)
choiceChips = OdsCard.Image.Position.entries.map { imagePosition ->
val textResId = when (imagePosition) {
OdsCard.Image.Position.Start -> R.string.component_card_horizontal_image_position_start
OdsCard.Image.Position.End -> R.string.component_card_horizontal_image_position_end
}
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = textResId), { this.imagePosition.value = imagePosition })
}
)
}
OdsListItem(
Expand Down
38 changes: 19 additions & 19 deletions app/src/main/java/com/orange/ods/app/ui/components/chips/Chip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.app.ui.utilities.extension.buildImageRequest
import com.orange.ods.compose.OdsComposable
import com.orange.ods.compose.component.chip.OdsChip
import com.orange.ods.compose.component.chip.OdsChoiceChip
import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow
import com.orange.ods.compose.component.listitem.OdsListItem
import com.orange.ods.compose.text.OdsText
import com.orange.ods.extension.orElse
import com.orange.ods.theme.typography.OdsTextStyle

@OptIn(ExperimentalMaterialApi::class)
Expand All @@ -61,14 +61,16 @@ fun Chip(variant: Variant) {
if (isInputChip) {
Subtitle(textRes = R.string.component_element_leading, horizontalPadding = true)
OdsChoiceChipsFlowRow(
value = leadingElement.value,
onValueChange = { value -> leadingElement.value = value },
selectedChoiceChipIndex = ChipCustomizationState.LeadingElement.entries.indexOf(leadingElement.value),
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(text = stringResource(id = R.string.component_element_none), value = LeadingElement.None),
OdsChoiceChip(text = stringResource(id = R.string.component_element_avatar), value = LeadingElement.Avatar),
OdsChoiceChip(text = stringResource(id = R.string.component_element_icon), value = LeadingElement.Icon)
)
choiceChips = ChipCustomizationState.LeadingElement.entries.map { leadingElement ->
val textResId = when (leadingElement) {
LeadingElement.None -> R.string.component_element_none
LeadingElement.Avatar -> R.string.component_element_avatar
LeadingElement.Icon -> R.string.component_element_icon
}
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = textResId), { this.leadingElement.value = leadingElement })
}
)
} else {
resetLeadingElement()
Expand Down Expand Up @@ -114,13 +116,12 @@ private fun Chip(chipCustomizationState: ChipCustomizationState) {
with(chipCustomizationState) {
if (isChoiceChip) {
OdsChoiceChipsFlowRow(
value = choiceChipIndexSelected.value,
onValueChange = { value -> choiceChipIndexSelected.value = value },
selectedChoiceChipIndex = selectedChoiceChipIndex.value.orElse { 0 },
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)),
chips = recipes.mapIndexed { index, recipe ->
OdsChoiceChip(
choiceChips = recipes.mapIndexed { index, recipe ->
OdsChoiceChipsFlowRow.ChoiceChip(
text = recipe.title,
value = index,
{ selectedChoiceChipIndex.value = index },
enabled = isEnabled
)
}
Expand All @@ -132,14 +133,13 @@ private fun Chip(chipCustomizationState: ChipCustomizationState) {
FunctionCallCode(
name = OdsComposable.OdsChoiceChipsFlowRow.name,
parameters = {
stringRepresentation("value", choiceChipIndexSelected.value.toString())
lambda("onValueChange")
list("chips") {
recipes.forEachIndexed { index, recipe ->
classInstance<OdsChoiceChip<*>> {
stringRepresentation("selectedChoiceChipIndex", selectedChoiceChipIndex.value.toString())
list("choiceChips") {
recipes.forEach { recipe ->
classInstance<OdsChoiceChipsFlowRow.ChoiceChip> {
text(recipe.title)
stringRepresentation("value", index)
if (!isEnabled) enabled(false)
onClick()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ChipCustomizationState(
val chipType: MutableState<ChipType>,
val leadingElement: MutableState<LeadingElement>,
val enabled: MutableState<Boolean>,
val choiceChipIndexSelected: MutableState<Int?>
val selectedChoiceChipIndex: MutableState<Int?>
) {

enum class ChipType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import com.orange.ods.app.ui.utilities.composable.Subtitle
import com.orange.ods.app.ui.utilities.extension.buildImageRequest
import com.orange.ods.compose.OdsComposable
import com.orange.ods.compose.component.chip.OdsChip
import com.orange.ods.compose.component.chip.OdsChoiceChip
import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow
import com.orange.ods.compose.component.chip.OdsFilterChip
import com.orange.ods.compose.component.listitem.OdsListItem
Expand All @@ -60,16 +59,16 @@ fun ChipFilter() {
ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
bottomSheetContent = {

Subtitle(textRes = R.string.component_element_leading, horizontalPadding = true)
val leadingElements = listOf(ChipCustomizationState.LeadingElement.None, ChipCustomizationState.LeadingElement.Avatar)
OdsChoiceChipsFlowRow(
value = leadingElement.value,
onValueChange = { value -> leadingElement.value = value },
selectedChoiceChipIndex = leadingElements.indexOf(leadingElement.value),
modifier = Modifier.padding(horizontal = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)),
chips = listOf(
OdsChoiceChip(text = stringResource(id = R.string.component_element_none), value = ChipCustomizationState.LeadingElement.None),
OdsChoiceChip(text = stringResource(id = R.string.component_element_avatar), value = ChipCustomizationState.LeadingElement.Avatar),
)
choiceChips = leadingElements.map { leadingElement ->
val textResId =
if (leadingElement == ChipCustomizationState.LeadingElement.None) R.string.component_element_none else R.string.component_element_avatar
OdsChoiceChipsFlowRow.ChoiceChip(stringResource(id = textResId), { this.leadingElement.value = leadingElement })
}
)

OdsListItem(
Expand Down
Loading

0 comments on commit be324c4

Please sign in to comment.