Skip to content

Commit 321887e

Browse files
committed
Reuse OudsAlertStatus in list items and tags
1 parent 648f099 commit 321887e

4 files changed

Lines changed: 46 additions & 84 deletions

File tree

core/src/main/java/com/orange/ouds/core/component/OudsAlert.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,28 @@ internal sealed class OudsAlertStatus(
5656
class Warning(
5757
defaultIconPainterProvider: (@Composable (OudsAlertStatus) -> Painter?) = { getDefaultIconPainter(it) },
5858
defaultIconContentDescriptionProvider: (@Composable (OudsAlertStatus) -> String) = { stringResource(R.string.core_common_warning_a11y) }
59-
) :
60-
OudsAlertStatus(defaultIconPainterProvider, defaultIconContentDescriptionProvider)
59+
) : OudsAlertStatus(defaultIconPainterProvider, defaultIconContentDescriptionProvider)
6160

6261
companion object {
6362

6463
@Composable
65-
protected fun getDefaultIconPainter(status: OudsAlertStatus): Painter? {
64+
internal fun getDefaultIconPainter(status: OudsAlertStatus, layeredTintedWarningPainter: Boolean = true): Painter? {
6665
return when (status) {
6766
is Negative -> painterResource(OudsTheme.drawableResources.component.alert.importantFill)
6867
is Positive -> painterResource(OudsTheme.drawableResources.component.alert.tickConfirmationFill)
6968
is Info -> painterResource(OudsTheme.drawableResources.component.alert.infoFill)
7069
is Warning -> {
71-
val iconTokens = OudsTheme.componentsTokens.icon
72-
LayeredTintedPainter(
73-
backPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningExternalShape),
74-
backPainterColor = iconTokens.colorContentStatusWarningExternalShape.value,
75-
frontPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningInternalShape),
76-
frontPainterColor = iconTokens.colorContentStatusWarningInternalShape.value
77-
)
70+
if (!layeredTintedWarningPainter) {
71+
painterResource(id = OudsTheme.drawableResources.component.alert.warningExternalShape)
72+
} else {
73+
val iconTokens = OudsTheme.componentsTokens.icon
74+
LayeredTintedPainter(
75+
backPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningExternalShape),
76+
backPainterColor = iconTokens.colorContentStatusWarningExternalShape.value,
77+
frontPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningInternalShape),
78+
frontPainterColor = iconTokens.colorContentStatusWarningInternalShape.value
79+
)
80+
}
7881
}
7982
is Accent,
8083
is Neutral -> null

core/src/main/java/com/orange/ouds/core/component/OudsListItem.kt

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import com.orange.ouds.core.theme.LocalThemeSettings
6464
import com.orange.ouds.core.theme.OudsTheme
6565
import com.orange.ouds.core.theme.takeUnlessHairline
6666
import com.orange.ouds.core.utilities.CheckerboardPainter
67-
import com.orange.ouds.core.utilities.LayeredTintedPainter
6867
import com.orange.ouds.core.utilities.OudsPreview
6968
import com.orange.ouds.core.utilities.OudsPreviewDevice
7069
import com.orange.ouds.core.utilities.OudsPreviewLightDark
@@ -617,42 +616,25 @@ enum class OudsListItemIconSize {
617616
}
618617
}
619618

620-
enum class OudsListItemIconStatus(
621-
val painterProvider: @Composable () -> Painter,
622-
val contentDescriptionProvider: (@Composable () -> String) = { "" }
623-
) {
624-
Negative(
625-
{ painterResource(OudsTheme.drawableResources.component.alert.importantFill) },
626-
{ stringResource(R.string.core_common_error_a11y) }
627-
),
628-
629-
Positive({ painterResource(OudsTheme.drawableResources.component.alert.tickConfirmationFill) }),
630-
631-
Info({ painterResource(OudsTheme.drawableResources.component.alert.infoFill) }),
632-
633-
Warning(
634-
{
635-
val iconTokens = OudsTheme.components.icon
636-
LayeredTintedPainter(
637-
backPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningExternalShape),
638-
backPainterColor = iconTokens.color.content.status.warning.externalShape,
639-
frontPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningInternalShape),
640-
frontPainterColor = iconTokens.color.content.status.warning.internalShape
641-
)
642-
},
643-
{ stringResource(R.string.core_common_warning_a11y) }
644-
);
619+
enum class OudsListItemIconStatus(private val alertStatus: OudsAlertStatus, val contentDescriptionProvider: (@Composable () -> String) = { "" }) {
645620

646-
val tint
621+
Negative(OudsAlertStatus.Negative(), { stringResource(R.string.core_common_error_a11y) }),
622+
623+
Positive(OudsAlertStatus.Positive()),
624+
625+
Info(OudsAlertStatus.Info()),
626+
627+
Warning(OudsAlertStatus.Warning(), { stringResource(R.string.core_common_warning_a11y) });
628+
629+
val painter: Painter
647630
@Composable
648-
get() = with(OudsTheme.colorScheme.content) {
649-
when (this@OudsListItemIconStatus) {
650-
Positive -> status.positive
651-
Warning -> Color.Unspecified
652-
Negative -> status.negative
653-
Info -> status.info
654-
}
631+
get() = OudsAlertStatus.getDefaultIconPainter(alertStatus).orElse {
632+
error("No painter for status ${this::class.simpleName}")
655633
}
634+
635+
val tint
636+
@Composable
637+
get() = alertStatus.assetColor
656638
}
657639

658640
enum class OudsListItemImageFormat {
@@ -828,7 +810,7 @@ sealed interface OudsListItemLeading : OudsListItemLeadingTrailing {
828810
) : this({ bitmap as Any }, { contentDescription }, tinted, size, null)
829811

830812
private constructor(size: OudsListItemIconSize, status: OudsListItemIconStatus) : this(
831-
{ status.painterProvider() },
813+
{ status.painter },
832814
{ status.contentDescriptionProvider() },
833815
true,
834816
size,
@@ -987,7 +969,7 @@ sealed interface OudsListItemTrailing : OudsListItemLeadingTrailing {
987969
) : this({ bitmap as Any }, { contentDescription }, tinted, size, null)
988970

989971
private constructor(size: OudsListItemIconSize, status: OudsListItemIconStatus) : this(
990-
{ status.painterProvider() },
972+
{ status.painter },
991973
{ status.contentDescriptionProvider() },
992974
true,
993975
size,

core/src/main/java/com/orange/ouds/core/component/OudsSmallListItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ sealed interface OudsSmallListItemLeading : OudsListItemLeadingTrailing {
227227
) : this({ bitmap }, { contentDescription }, tinted, null)
228228

229229
private constructor(status: OudsListItemIconStatus) : this(
230-
{ status.painterProvider() },
230+
{ status.painter },
231231
{ status.contentDescriptionProvider() },
232232
true,
233233
status
@@ -361,7 +361,7 @@ sealed interface OudsSmallListItemTrailing : OudsListItemLeadingTrailing {
361361
bitmap: ImageBitmap, contentDescription: String, tinted: Boolean = true
362362
) : this({ bitmap }, { contentDescription }, tinted, null)
363363

364-
private constructor(status: OudsListItemIconStatus) : this(status.painterProvider, status.contentDescriptionProvider, true, status)
364+
private constructor(status: OudsListItemIconStatus) : this({ status.painter }, status.contentDescriptionProvider, true, status)
365365

366366
// TODO KDoc
367367
object Info : Icon(OudsListItemIconStatus.Info)

core/src/main/java/com/orange/ouds/core/component/OudsTag.kt

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import androidx.compose.ui.graphics.StrokeCap
3636
import androidx.compose.ui.graphics.painter.Painter
3737
import androidx.compose.ui.graphics.vector.ImageVector
3838
import androidx.compose.ui.platform.LocalConfiguration
39-
import androidx.compose.ui.res.painterResource
4039
import androidx.compose.ui.res.stringResource
4140
import androidx.compose.ui.semantics.hideFromAccessibility
4241
import androidx.compose.ui.semantics.semantics
@@ -55,7 +54,6 @@ import com.orange.ouds.core.extensions.iconSize
5554
import com.orange.ouds.core.theme.OudsTheme
5655
import com.orange.ouds.core.theme.value
5756
import com.orange.ouds.core.utilities.CheckedContent
58-
import com.orange.ouds.core.utilities.LayeredTintedPainter
5957
import com.orange.ouds.core.utilities.OudsPreview
6058
import com.orange.ouds.core.utilities.OudsPreviewLightDark
6159
import com.orange.ouds.core.utilities.PreviewGrid
@@ -565,10 +563,15 @@ enum class OudsTagSize {
565563
*
566564
* @property asset The asset to be displayed in the tag, or `null` if there is no asset.
567565
*/
568-
sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
566+
sealed class OudsTagStatus(private val alertStatus: OudsAlertStatus, val asset: OudsTagAsset? = null) {
569567

570568
@Composable
571-
internal open fun getDefaultIconPainter(appearance: OudsTagAppearance, enabled: Boolean): Painter? = null
569+
internal fun getDefaultIconPainter(appearance: OudsTagAppearance, enabled: Boolean): Painter? {
570+
return OudsAlertStatus.getDefaultIconPainter(
571+
status = alertStatus,
572+
layeredTintedWarningPainter = appearance != OudsTagAppearance.Emphasized && enabled
573+
)
574+
}
572575

573576
internal open val defaultIconContentDescription: String
574577
@Composable
@@ -578,7 +581,7 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
578581
* Default or inactive status. Used for standard labels, categories, or when no specific status needs to be communicated.
579582
* Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon] or `null` if no asset is needed.
580583
*/
581-
class Neutral internal constructor(asset: OudsTagAsset?) : OudsTagStatus(asset) {
584+
class Neutral internal constructor(asset: OudsTagAsset?) : OudsTagStatus(OudsAlertStatus.Neutral(), asset) {
582585
/**
583586
* Creates an instance of [OudsTagStatus.Neutral] with a bullet.
584587
*/
@@ -600,7 +603,7 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
600603
* Invites users to explore and engage with new offerings, creating an exciting and engaging experience.
601604
* Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon] or `null` if no asset is needed.
602605
*/
603-
class Accent internal constructor(asset: OudsTagAsset?) : OudsTagStatus(asset) {
606+
class Accent internal constructor(asset: OudsTagAsset?) : OudsTagStatus(OudsAlertStatus.Accent(), asset) {
604607
/**
605608
* Creates an instance of [OudsTagStatus.Accent] with a bullet.
606609
*/
@@ -621,7 +624,7 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
621624
* Indicates success, confirmation, or a positive status. This functional status is commonly used to highlight completed actions or approved items.
622625
* Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon.Default] or `null` if no asset is needed.
623626
*/
624-
class Positive internal constructor(asset: OudsTagAsset?) : OudsTagStatus(asset) {
627+
class Positive internal constructor(asset: OudsTagAsset?) : OudsTagStatus(OudsAlertStatus.Positive(), asset) {
625628
/**
626629
* Creates an instance of [OudsTagStatus.Positive] with a bullet.
627630
*/
@@ -636,17 +639,13 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
636639
* Creates an instance of [OudsTagStatus.Positive] with no asset.
637640
*/
638641
constructor() : this(null)
639-
640-
@Composable
641-
override fun getDefaultIconPainter(appearance: OudsTagAppearance, enabled: Boolean) =
642-
painterResource(OudsTheme.drawableResources.component.alert.tickConfirmationFill)
643642
}
644643

645644
/**
646645
* Conveys informational messages or supplementary details. This functional status is used for neutral, helpful, or contextual information.
647646
* Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon.Default] or `null` if no asset is needed.
648647
*/
649-
class Info internal constructor(asset: OudsTagAsset?) : OudsTagStatus(asset) {
648+
class Info internal constructor(asset: OudsTagAsset?) : OudsTagStatus(OudsAlertStatus.Info(), asset) {
650649
/**
651650
* Creates an instance of [OudsTagStatus.Info] with a bullet.
652651
*/
@@ -661,17 +660,13 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
661660
* Creates an instance of [OudsTagStatus.Info] with no asset.
662661
*/
663662
constructor() : this(null)
664-
665-
@Composable
666-
override fun getDefaultIconPainter(appearance: OudsTagAppearance, enabled: Boolean) =
667-
painterResource(OudsTheme.drawableResources.component.alert.infoFill)
668663
}
669664

670665
/**
671666
* Signals caution or a potentially risky situation. This functional status is used to draw attention to items requiring user awareness or intervention.
672667
* Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon.Default] or `null` if no asset is needed.
673668
*/
674-
class Warning internal constructor(asset: OudsTagAsset?) : OudsTagStatus(asset) {
669+
class Warning internal constructor(asset: OudsTagAsset?) : OudsTagStatus(OudsAlertStatus.Warning(), asset) {
675670
/**
676671
* Creates an instance of [OudsTagStatus.Warning] with a bullet.
677672
*/
@@ -687,20 +682,6 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
687682
*/
688683
constructor() : this(null)
689684

690-
@Composable
691-
override fun getDefaultIconPainter(appearance: OudsTagAppearance, enabled: Boolean): Painter {
692-
val iconTokens = OudsTheme.componentsTokens.icon
693-
return when {
694-
appearance == OudsTagAppearance.Emphasized || !enabled -> painterResource(id = OudsTheme.drawableResources.component.alert.warningExternalShape)
695-
else -> LayeredTintedPainter(
696-
backPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningExternalShape),
697-
backPainterColor = iconTokens.colorContentStatusWarningExternalShape.value,
698-
frontPainter = painterResource(id = OudsTheme.drawableResources.component.alert.warningInternalShape),
699-
frontPainterColor = iconTokens.colorContentStatusWarningInternalShape.value
700-
)
701-
}
702-
}
703-
704685
override val defaultIconContentDescription
705686
@Composable
706687
get() = stringResource(id = R.string.core_common_warning_a11y)
@@ -710,7 +691,7 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
710691
* Represents errors, critical issues, or urgent attention needed. This functional status is used to highlight problems or failed actions.
711692
* Its [asset] can be an [OudsTagAsset.Bullet], an [OudsTagAsset.Icon.Default] or `null` if no asset is needed.
712693
*/
713-
class Negative internal constructor(asset: OudsTagAsset?) : OudsTagStatus(asset) {
694+
class Negative internal constructor(asset: OudsTagAsset?) : OudsTagStatus(OudsAlertStatus.Negative(), asset) {
714695
/**
715696
* Creates an instance of [OudsTagStatus.Negative] with a bullet.
716697
*/
@@ -726,10 +707,6 @@ sealed class OudsTagStatus(val asset: OudsTagAsset? = null) {
726707
*/
727708
constructor() : this(null)
728709

729-
@Composable
730-
override fun getDefaultIconPainter(appearance: OudsTagAppearance, enabled: Boolean) =
731-
painterResource(OudsTheme.drawableResources.component.alert.importantFill)
732-
733710
override val defaultIconContentDescription
734711
@Composable
735712
get() = stringResource(id = R.string.core_common_error_a11y)

0 commit comments

Comments
 (0)