Skip to content

Commit

Permalink
[#247] Allow to enable or disabled click on card in customization sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinea committed Sep 6, 2022
1 parent 4e3992b commit 93797c5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,28 @@ import androidx.compose.runtime.saveable.rememberSaveable

@Composable
fun rememberCardCustomizationState(
clickable: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
thumbnailChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
textChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
subtitleChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
button1Checked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
button2Checked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) }
) =
remember(thumbnailChecked, textChecked, subtitleChecked, button1Checked, button2Checked) {
CardCustomizationState(thumbnailChecked, textChecked, subtitleChecked, button1Checked, button2Checked)
remember(clickable, thumbnailChecked, textChecked, subtitleChecked, button1Checked, button2Checked) {
CardCustomizationState(clickable, thumbnailChecked, textChecked, subtitleChecked, button1Checked, button2Checked)
}

class CardCustomizationState(
val clickable: MutableState<Boolean>,
val thumbnailChecked: MutableState<Boolean>,
val textChecked: MutableState<Boolean>,
val subtitleChecked: MutableState<Boolean>,
val button1Checked: MutableState<Boolean>,
val button2Checked: MutableState<Boolean>
) {
val isClickable
get() = clickable.value

val hasThumbnail
get() = thumbnailChecked.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import com.orange.ods.demo.ui.utilities.composable.SwitchListItem

@ExperimentalMaterialApi
@Composable
fun VariantCardImageFirst() {
fun CardImageFirst() {
val context = LocalContext.current
val cardCustomizationState = rememberCardCustomizationState()

with(cardCustomizationState) {
ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
bottomSheetContent = {
SwitchListItem(labelRes = R.string.component_card_clickable, checked = clickable)
SwitchListItem(labelRes = R.string.component_element_subtitle, checked = subtitleChecked)
SwitchListItem(labelRes = R.string.component_element_text, checked = textChecked)
SwitchListItem(labelRes = R.string.component_element_button1, checked = button1Checked)
Expand All @@ -61,7 +62,9 @@ fun VariantCardImageFirst() {
image = painterResource(id = R.drawable.placeholder),
subtitle = if (hasSubtitle) stringResource(id = R.string.component_element_subtitle) else null,
text = if (hasText) stringResource(id = R.string.component_element_text_value) else null,
onCardClick = { clickOnElement(context, cardContainerText) },
onCardClick = if (isClickable) {
{ clickOnElement(context, cardContainerText) }
} else null,
button1Text = if (hasButton1) button1Text else null,
onButton1Click = { clickOnElement(context, button1Text) },
button2Text = if (hasButton2) button2Text else null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
*
* Copyright 2021 Orange
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* /
*/

package com.orange.ods.demo.ui.components.cards

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import com.orange.ods.compose.component.card.OdsCardSmall
import com.orange.ods.demo.R
import com.orange.ods.demo.ui.components.utilities.ComponentCustomizationBottomSheetScaffold
import com.orange.ods.demo.ui.components.utilities.clickOnElement
import com.orange.ods.demo.ui.utilities.composable.SwitchListItem

@ExperimentalMaterialApi
@Composable
fun CardSmall() {
val context = LocalContext.current
val cardCustomizationState = rememberCardCustomizationState()

with(cardCustomizationState) {
ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
bottomSheetContent = {
SwitchListItem(labelRes = R.string.component_card_clickable, checked = clickable)
SwitchListItem(labelRes = R.string.component_element_subtitle, checked = subtitleChecked)
}) {
Row(
modifier = Modifier
.fillMaxSize()
.padding(dimensionResource(id = R.dimen.spacing_m)),
horizontalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.spacing_m)),
) {
val cardContainerText = stringResource(id = R.string.component_card_element_container)

OdsCardSmall(
modifier = Modifier.weight(0.5f),
imageRes = R.drawable.placeholder,
title = stringResource(id = R.string.component_element_title),
subtitle = if (subtitleChecked.value) stringResource(id = R.string.component_element_subtitle) else null,
onCardClick = if (isClickable) {
{ clickOnElement(context, cardContainerText) }
} else null
)
Box(modifier = Modifier.weight(0.5f))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import com.orange.ods.demo.ui.utilities.composable.SwitchListItem

@ExperimentalMaterialApi
@Composable
fun VariantCardTitleFirst() {
fun CardTitleFirst() {
val context = LocalContext.current
val cardCustomizationState = rememberCardCustomizationState()

with(cardCustomizationState) {
ComponentCustomizationBottomSheetScaffold(
bottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
bottomSheetContent = {
SwitchListItem(labelRes = R.string.component_card_clickable, checked = clickable)
SwitchListItem(labelRes = R.string.component_element_thumbnail, checked = thumbnailChecked)
SwitchListItem(labelRes = R.string.component_element_subtitle, checked = subtitleChecked)
SwitchListItem(labelRes = R.string.component_element_text, checked = textChecked)
Expand All @@ -63,7 +64,9 @@ fun VariantCardTitleFirst() {
thumbnail = if (hasThumbnail) painterResource(id = R.drawable.placeholder) else null,
subtitle = if (hasSubtitle) stringResource(id = R.string.component_element_subtitle) else null,
text = if (hasText) stringResource(id = R.string.component_element_text_value) else null,
onCardClick = { clickOnElement(context, cardContainerText) },
onCardClick = if (isClickable) {
{ clickOnElement(context, cardContainerText) }
} else null,
button1Text = if (hasButton1) button1Text else null,
onButton1Click = { clickOnElement(context, button1Text) },
button2Text = if (hasButton2) button2Text else null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import com.orange.ods.demo.ui.components.Variant
@Composable
fun ComponentCard(variant: Variant) {
when (variant) {
Variant.CardImageFirst -> VariantCardImageFirst()
Variant.CardSmall -> VariantCardSmall()
Variant.CardTitleFirst -> VariantCardTitleFirst()
Variant.CardImageFirst -> CardImageFirst()
Variant.CardSmall -> CardSmall()
Variant.CardTitleFirst -> CardTitleFirst()
else -> {}
}
}
2 changes: 2 additions & 0 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
<string name="component_card_small">Card small</string>
<string name="component_card_description">Cards are important components that can be used to organise and present a number of different types of related information.</string>
<string name="component_card_element_container">Card container</string>
<string name="component_card_clickable">Clickable card</string>


<!-- Component Checkboxes -->
<string name="component_checkboxes">Checkboxes</string>
Expand Down

0 comments on commit 93797c5

Please sign in to comment.