Skip to content

Commit

Permalink
[#388] Replace content of checkboxes and radio buttons component demo…
Browse files Browse the repository at this point in the history
…s with recipes and ingredients
  • Loading branch information
florentmaitre committed Jan 4, 2023
1 parent 778d76d commit 3bcf2da
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import com.orange.ods.demo.R
import com.orange.ods.demo.domain.recipes.LocalRecipes
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.demo.ui.utilities.composable.CheckboxListItem
import com.orange.ods.demo.ui.utilities.composable.SwitchListItem
Expand All @@ -31,6 +32,8 @@ import com.orange.ods.demo.ui.utilities.composable.SwitchListItem
@Composable
fun ComponentCheckboxes() {
val enabled = rememberSaveable { mutableStateOf(true) }
val recipes = LocalRecipes.current
val recipe = remember { recipes.filter { it.ingredients.count() >= 3 }.random() }

ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
Expand All @@ -42,23 +45,13 @@ fun ComponentCheckboxes() {
.verticalScroll(rememberScrollState())
.padding(bottom = dimensionResource(id = R.dimen.spacing_m))
) {
CheckboxListItem(
labelRes = R.string.component_element_item1,
checked = remember { mutableStateOf(true) },
enabled = enabled.value
)

CheckboxListItem(
labelRes = R.string.component_element_item2,
checked = remember { mutableStateOf(false) },
enabled = enabled.value
)

CheckboxListItem(
labelRes = R.string.component_element_item3,
checked = remember { mutableStateOf(true) },
enabled = enabled.value
)
recipe.ingredients.forEachIndexed { index, ingredient ->
CheckboxListItem(
label = ingredient.name,
checked = remember { mutableStateOf(index == 0) },
enabled = enabled.value
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import com.orange.ods.demo.R
import com.orange.ods.demo.domain.recipes.LocalRecipes
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.demo.ui.utilities.composable.RadioButtonListItem
import com.orange.ods.demo.ui.utilities.composable.SwitchListItem
Expand All @@ -44,28 +44,17 @@ fun ComponentRadioButtons() {
.verticalScroll(rememberScrollState())
.padding(bottom = dimensionResource(id = R.dimen.spacing_m))
) {
val selectedRadio = remember { mutableStateOf(R.string.component_element_item1) }
val recipes = LocalRecipes.current.take(5)
val selectedRadio = remember { mutableStateOf(recipes.firstOrNull()?.title) }
Column(modifier = Modifier.selectableGroup()) {
RadioButtonListItem(
label = stringResource(id = R.string.component_element_item1),
selectedRadio = selectedRadio,
currentRadio = R.string.component_element_item1,
enabled = enabled.value
)

RadioButtonListItem(
label = stringResource(id = R.string.component_element_item2),
selectedRadio = selectedRadio,
currentRadio = R.string.component_element_item2,
enabled = enabled.value
)

RadioButtonListItem(
label = stringResource(id = R.string.component_element_item3),
selectedRadio = selectedRadio,
currentRadio = R.string.component_element_item3,
enabled = enabled.value
)
recipes.forEach { recipe ->
RadioButtonListItem(
label = recipe.title,
selectedRadio = selectedRadio,
currentRadio = recipe.title,
enabled = enabled.value
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import com.orange.ods.compose.component.control.OdsSwitch
import com.orange.ods.compose.component.list.OdsListItem

@Composable
fun CheckboxListItem(@StringRes labelRes: Int, checked: MutableState<Boolean>, enabled: Boolean = true) {
fun CheckboxListItem(label: String, checked: MutableState<Boolean>, enabled: Boolean = true) {
OdsListItem(
modifier = Modifier.toggleable(
value = checked.value,
role = Role.Checkbox,
enabled = enabled,
onValueChange = { checked.value = !checked.value }
),
text = stringResource(id = labelRes),
text = label,
trailing = {
OdsCheckbox(
checked = checked.value,
Expand All @@ -43,6 +43,11 @@ fun CheckboxListItem(@StringRes labelRes: Int, checked: MutableState<Boolean>, e
)
}

@Composable
fun CheckboxListItem(@StringRes labelRes: Int, checked: MutableState<Boolean>, enabled: Boolean = true) {
CheckboxListItem(label = stringResource(id = labelRes), checked = checked, enabled = enabled)
}

@Composable
fun <T> RadioButtonListItem(label: String, selectedRadio: MutableState<T>, currentRadio: T, onClick: () -> Unit = {}, enabled: Boolean = true) {
val selected = selectedRadio.value == currentRadio
Expand Down
3 changes: 0 additions & 3 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@
<string name="component_element_trailing">Trailing element</string>
<string name="component_element_leading">Leading element</string>
<string name="component_element_leading_icon">Leading icon</string>
<string name="component_element_item1">Item 1</string>
<string name="component_element_item2">Item 2</string>
<string name="component_element_item3">Item 3</string>
<string name="component_element_cancel_cross">Cancel cross</string>
<string name="component_demo">%s demo</string>

Expand Down

0 comments on commit 3bcf2da

Please sign in to comment.