Skip to content

Commit

Permalink
[#597] Update OdsHorizontalCard, OdsSmallCard, OdsVerticalHeaderFirst…
Browse files Browse the repository at this point in the history
…Card and OdsVerticalImageFirstCard APIs
  • Loading branch information
florentmaitre committed Sep 7, 2023
1 parent 879a242 commit f5f62ac
Show file tree
Hide file tree
Showing 25 changed files with 557 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.ui.res.stringResource
import com.orange.ods.app.R
import com.orange.ods.app.ui.LocalMainTopAppBarManager
import com.orange.ods.app.ui.utilities.DrawableManager
import com.orange.ods.compose.component.card.OdsCardImage
import com.orange.ods.compose.component.card.OdsSmallCard
import com.orange.ods.extension.orElse

Expand Down Expand Up @@ -67,12 +68,13 @@ private fun RowScope.ComponentCard(component: Component, onComponentClick: (Long
OdsSmallCard(
modifier = Modifier.weight(0.5f),
title = stringResource(id = component.titleRes),
image = painterResource(id = smallImageResId.orElse { imageResId }),
imageBackgroundColor = Color(Component.ImageBackgroundColor),
imageContentScale = ContentScale.Fit,
imageAlignment = component.imageAlignment,
onCardClick = {
onComponentClick(component.id)
},
image = OdsCardImage(
painterResource(id = smallImageResId.orElse { imageResId }),
"",
component.imageAlignment,
ContentScale.Fit,
Color(Component.ImageBackgroundColor)
),
onClick = { onComponentClick(component.id) },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ fun rememberCardCustomizationState(
thumbnailChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
textChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
subtitleChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
actionButtonCount: MutableState<Int> = rememberSaveable { mutableStateOf(CardCustomizationState.MinActionButtonCount) },
buttonCount: MutableState<Int> = rememberSaveable { mutableStateOf(CardCustomizationState.MinButtonCount) },
dividerChecked: MutableState<Boolean> = rememberSaveable { mutableStateOf(true) },
imagePosition: MutableState<OdsHorizontalCardImagePosition> = rememberSaveable { mutableStateOf(OdsHorizontalCardImagePosition.Start) }
) =
remember(clickable, thumbnailChecked, textChecked, subtitleChecked, actionButtonCount, dividerChecked, imagePosition) {
CardCustomizationState(clickable, thumbnailChecked, textChecked, subtitleChecked, actionButtonCount, dividerChecked, imagePosition)
remember(clickable, thumbnailChecked, textChecked, subtitleChecked, buttonCount, dividerChecked, imagePosition) {
CardCustomizationState(clickable, thumbnailChecked, textChecked, subtitleChecked, buttonCount, dividerChecked, imagePosition)
}

class CardCustomizationState(
val clickable: MutableState<Boolean>,
val thumbnailChecked: MutableState<Boolean>,
val textChecked: MutableState<Boolean>,
val subtitleChecked: MutableState<Boolean>,
val actionButtonCount: MutableState<Int>,
val buttonCount: MutableState<Int>,
val dividerChecked: MutableState<Boolean>,
val imagePosition: MutableState<OdsHorizontalCardImagePosition>
) {

companion object {
const val MinActionButtonCount = 0
const val MaxActionButtonCount = 2
const val MinButtonCount = 0
const val MaxButtonCount = 2
}

val isClickable
Expand All @@ -58,12 +58,12 @@ class CardCustomizationState(
val hasSubtitle
get() = subtitleChecked.value

val hasButton1
get() = actionButtonCount.value > 0
val hasFirstButton
get() = buttonCount.value > 0

val hasButton2
get() = actionButtonCount.value > 1
val hasSecondButton
get() = buttonCount.value > 1

val hasDivider
get() = if (!hasButton1) false else dividerChecked.value
get() = if (!hasFirstButton) false else dividerChecked.value
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,46 @@ import com.orange.ods.app.ui.utilities.DrawableManager
import com.orange.ods.app.ui.utilities.composable.CodeImplementationColumn
import com.orange.ods.app.ui.utilities.composable.FunctionCallCode
import com.orange.ods.compose.OdsComposable
import com.orange.ods.compose.component.card.OdsCardButton
import com.orange.ods.compose.component.card.OdsCardImage
import com.orange.ods.compose.component.card.OdsHorizontalCard

@Composable
fun CardHorizontal(customizationState: CardCustomizationState) {
val context = LocalContext.current
val recipes = LocalRecipes.current
val recipe = rememberSaveable { recipes.filter { it.description.isNotBlank() }.random() }

with(customizationState) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(dimensionResource(id = com.orange.ods.R.dimen.spacing_m))
.verticalScroll(state = rememberScrollState()),
) {
val button1Text = stringResource(id = R.string.component_element_first_button)
val button2Text = stringResource(id = R.string.component_element_second_button)
val firstButtonText = stringResource(id = R.string.component_element_first_button)
val secondButtonText = stringResource(id = R.string.component_element_second_button)
val cardText = stringResource(id = R.string.component_card_element_card)

OdsHorizontalCard(
title = recipe.title,
image = rememberAsyncImagePainter(
model = recipe.imageUrl,
placeholder = painterResource(id = DrawableManager.getPlaceholderResId()),
error = painterResource(id = DrawableManager.getPlaceholderResId(error = true))
image = OdsCardImage(
rememberAsyncImagePainter(
model = recipe.imageUrl,
placeholder = painterResource(id = DrawableManager.getPlaceholderResId()),
error = painterResource(id = DrawableManager.getPlaceholderResId(error = true))
),
""
),
subtitle = if (hasSubtitle) recipe.subtitle else null,
text = if (hasText) recipe.description else null,
onCardClick = if (isClickable) {
onClick = if (isClickable) {
{ clickOnElement(context, cardText) }
} else null,
button1Text = if (hasButton1) button1Text else null,
onButton1Click = { clickOnElement(context, button1Text) },
button2Text = if (hasButton2) button2Text else null,
onButton2Click = { clickOnElement(context, button2Text) },
firstButton = if (hasFirstButton) OdsCardButton(firstButtonText) { clickOnElement(context, firstButtonText) } else null,
secondButton = if (hasSecondButton) OdsCardButton(secondButtonText) { clickOnElement(context, secondButtonText) } else null,
imagePosition = imagePosition.value,
dividerEnabled = hasDivider
divider = hasDivider
)

Spacer(modifier = Modifier.padding(top = dimensionResource(com.orange.ods.R.dimen.spacing_s)))
Expand All @@ -77,21 +80,28 @@ fun CardHorizontal(customizationState: CardCustomizationState) {
name = OdsComposable.OdsHorizontalCard.name,
exhaustiveParameters = false,
parameters = {
simple("imagePosition", imagePosition.value.name)
title(recipe.title)
image()
classInstance("image", OdsCardImage::class.java) {
painter()
contentDescription("")
}
if (hasSubtitle) subtitle(recipe.subtitle)
if (hasText) cardText()
if (isClickable) onCardClick()
if (hasButton1) {
button1Text(button1Text)
onButton1Click()
if (isClickable) onClick()
if (hasFirstButton) {
classInstance("firstButton", OdsCardButton::class.java) {
text(firstButtonText)
onClick()
}
}
if (hasButton2) {
button2Text(button2Text)
onButton2Click()
if (hasSecondButton) {
classInstance("secondButton", OdsCardButton::class.java) {
text(secondButtonText)
onClick()
}
}
if (!hasDivider && (hasButton1 || hasButton2)) stringRepresentation("dividerEnabled", hasDivider)
simple("imagePosition", imagePosition.value.name)
if (!hasDivider && (hasFirstButton || hasSecondButton)) stringRepresentation("divider", hasDivider)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.orange.ods.app.ui.utilities.DrawableManager
import com.orange.ods.app.ui.utilities.composable.CodeImplementationColumn
import com.orange.ods.app.ui.utilities.composable.FunctionCallCode
import com.orange.ods.compose.OdsComposable
import com.orange.ods.compose.component.card.OdsCardImage
import com.orange.ods.compose.component.card.OdsSmallCard

@Composable
Expand All @@ -58,14 +59,17 @@ fun CardSmall(customizationState: CardCustomizationState) {

OdsSmallCard(
modifier = Modifier.weight(0.5f),
image = rememberAsyncImagePainter(
model = recipe.imageUrl,
placeholder = painterResource(id = DrawableManager.getPlaceholderResId()),
error = painterResource(id = DrawableManager.getPlaceholderResId(error = true))
image = OdsCardImage(
rememberAsyncImagePainter(
model = recipe.imageUrl,
placeholder = painterResource(id = DrawableManager.getPlaceholderResId()),
error = painterResource(id = DrawableManager.getPlaceholderResId(error = true)),
),
""
),
title = recipe.title,
subtitle = if (subtitleChecked.value) recipe.subtitle else null,
onCardClick = if (isClickable) {
onClick = if (isClickable) {
{ clickOnElement(context, cardText) }
} else null
)
Expand All @@ -80,9 +84,12 @@ fun CardSmall(customizationState: CardCustomizationState) {
exhaustiveParameters = false,
parameters = {
title(recipe.title)
image()
classInstance("image", OdsCardImage::class.java) {
painter()
contentDescription("")
}
if (hasSubtitle) subtitle(recipe.subtitle)
if (isClickable) onCardClick()
if (isClickable) onClick()
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import com.orange.ods.app.ui.utilities.DrawableManager
import com.orange.ods.app.ui.utilities.composable.CodeImplementationColumn
import com.orange.ods.app.ui.utilities.composable.FunctionCallCode
import com.orange.ods.compose.OdsComposable
import com.orange.ods.compose.component.card.OdsCardButton
import com.orange.ods.compose.component.card.OdsCardImage
import com.orange.ods.compose.component.card.OdsCardThumbnail
import com.orange.ods.compose.component.card.OdsVerticalHeaderFirstCard

@Composable
Expand All @@ -48,8 +51,8 @@ fun CardVerticalHeaderFirst(customizationState: CardCustomizationState) {
.padding(dimensionResource(id = com.orange.ods.R.dimen.spacing_m))
.verticalScroll(state = rememberScrollState()),
) {
val button1Text = stringResource(id = R.string.component_element_first_button)
val button2Text = stringResource(id = R.string.component_element_second_button)
val firstButtonText = stringResource(id = R.string.component_element_first_button)
val secondButtonText = stringResource(id = R.string.component_element_second_button)
val cardText = stringResource(id = R.string.component_card_element_card)
val imagePainter = rememberAsyncImagePainter(
model = ImageRequest.Builder(context)
Expand All @@ -62,17 +65,15 @@ fun CardVerticalHeaderFirst(customizationState: CardCustomizationState) {

OdsVerticalHeaderFirstCard(
title = recipe.title,
image = imagePainter,
thumbnail = if (hasThumbnail) imagePainter else null,
image = OdsCardImage(imagePainter, ""),
thumbnail = if (hasThumbnail) OdsCardThumbnail(imagePainter, "") else null,
subtitle = if (hasSubtitle) recipe.subtitle else null,
text = if (hasText) recipe.description else null,
onCardClick = if (isClickable) {
onClick = if (isClickable) {
{ clickOnElement(context, cardText) }
} else null,
button1Text = if (hasButton1) button1Text else null,
onButton1Click = { clickOnElement(context, button1Text) },
button2Text = if (hasButton2) button2Text else null,
onButton2Click = { clickOnElement(context, button2Text) }
firstButton = if (hasFirstButton) OdsCardButton(firstButtonText) { clickOnElement(context, firstButtonText) } else null,
secondButton = if (hasSecondButton) OdsCardButton(secondButtonText) { clickOnElement(context, secondButtonText) } else null,
)

Spacer(modifier = Modifier.padding(top = dimensionResource(com.orange.ods.R.dimen.spacing_s)))
Expand All @@ -83,18 +84,30 @@ fun CardVerticalHeaderFirst(customizationState: CardCustomizationState) {
exhaustiveParameters = false,
parameters = {
title(recipe.title)
image()
if (hasThumbnail) simple("thumbnail", "<thumbnail painter>")
classInstance("image", OdsCardImage::class.java) {
painter()
contentDescription("")
}
if (hasThumbnail) {
classInstance("thumbnail", OdsCardThumbnail::class.java) {
painter()
contentDescription("")
}
}
if (hasSubtitle) subtitle(recipe.subtitle)
if (hasText) cardText()
if (isClickable) onCardClick()
if (hasButton1) {
button1Text(button1Text)
onButton1Click()
if (isClickable) onClick()
if (hasFirstButton) {
classInstance("firstButton", OdsCardButton::class.java) {
text(firstButtonText)
onClick()
}
}
if (hasButton2) {
button2Text(button2Text)
onButton2Click()
if (hasSecondButton) {
classInstance("secondButton", OdsCardButton::class.java) {
text(secondButtonText)
onClick()
}
}
}
)
Expand Down
Loading

0 comments on commit f5f62ac

Please sign in to comment.