Skip to content

Commit b9b48cf

Browse files
committed
Add rich text to bullet list demo
1 parent 24923e5 commit b9b48cf

2 files changed

Lines changed: 85 additions & 38 deletions

File tree

app/src/main/java/com/orange/ouds/app/ui/components/bulletlist/BulletListDemoScreen.kt

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.compose.ui.res.stringResource
2222
import androidx.compose.ui.tooling.preview.PreviewLightDark
2323
import com.orange.ouds.app.R
2424
import com.orange.ouds.app.ui.components.Component
25+
import com.orange.ouds.app.ui.components.annotatedStringArgument
2526
import com.orange.ouds.app.ui.components.bulletlist.BulletListDemoState.Companion.MaxLevelCount
2627
import com.orange.ouds.app.ui.components.bulletlist.BulletListDemoState.Companion.MinLevelCount
2728
import com.orange.ouds.app.ui.components.iconArgument
@@ -44,6 +45,11 @@ import com.orange.ouds.core.component.OudsBulletListFontWeight
4445
import com.orange.ouds.core.component.OudsBulletListTextStyle
4546
import com.orange.ouds.core.component.OudsBulletListType
4647
import com.orange.ouds.core.component.OudsBulletListUnorderedAsset
48+
import com.orange.ouds.core.component.common.text.OudsAnnotatedBulletListLabel
49+
import com.orange.ouds.core.component.common.text.OudsLinkAnnotation
50+
import com.orange.ouds.core.component.common.text.buildOudsAnnotatedBulletListLabel
51+
import com.orange.ouds.core.component.common.text.withLink
52+
import com.orange.ouds.core.component.common.text.withStrong
4753
import com.orange.ouds.foundation.extensions.toSentenceCase
4854
import com.orange.ouds.foundation.extensions.tryOrNull
4955
import com.orange.ouds.theme.OudsVersion
@@ -113,32 +119,37 @@ private fun BulletListDemoBottomSheetContent(state: BulletListDemoState) {
113119
applyTopPadding = true,
114120
label = stringResource(R.string.app_components_common_label_tech),
115121
value = label,
116-
onValueChange = { value -> label = value }
122+
onValueChange = { value -> label = value },
123+
enabled = labelTextInputEnabled,
124+
helperText = stringResource(id = R.string.app_components_common_annotatedTextHelperText_tech)
125+
)
126+
CustomizationSwitchItem(
127+
label = stringResource(R.string.app_components_common_annotatedText_tech),
128+
checked = annotatedText,
129+
onCheckedChange = { annotatedText = it },
117130
)
118131
}
119132
}
120133

121134
@Composable
122135
private fun BulletListDemoContent(state: BulletListDemoState) {
123136
with(state) {
124-
val builder: OudsBulletListBuilder.() -> Unit = remember(levelCount, label) {
137+
val builder: OudsBulletListBuilder.() -> Unit = remember(levelCount, label, annotatedText) {
125138
{
126139
when (levelCount) {
127-
1 -> {
128-
item(label = label)
129-
item(label = label)
130-
item(label = label)
140+
1 -> repeat(3) { index ->
141+
bulletListDemoItem(index, this@with)
131142
}
132143
2 -> {
133-
item(label = label) {
134-
item(label = label)
135-
item(label = label)
144+
bulletListDemoItem(0, this@with) {
145+
bulletListDemoItem(1, this@with)
146+
bulletListDemoItem(2, this@with)
136147
}
137148
}
138149
else -> {
139-
item(label = label) {
140-
item(label = label) {
141-
item(label = label)
150+
bulletListDemoItem(0, this@with) {
151+
bulletListDemoItem(1, this@with) {
152+
bulletListDemoItem(2, this@with)
142153
}
143154
}
144155
}
@@ -155,10 +166,9 @@ private fun BulletListDemoContent(state: BulletListDemoState) {
155166
} else {
156167
type
157168
},
158-
textStyle = OudsBulletListTextStyle(fontSize, fontWeight)
159-
) {
160-
builder()
161-
}
169+
textStyle = OudsBulletListTextStyle(fontSize, fontWeight),
170+
builder = builder
171+
)
162172
}
163173
}
164174

@@ -190,19 +200,19 @@ private fun Code.Builder.bulletListDemoCodeSnippet(state: BulletListDemoState, t
190200
when (levelCount) {
191201
1 -> {
192202
repeat(3) {
193-
itemFunctionCall(label)
203+
itemFunctionCall(state)
194204
}
195205
}
196206
2 -> {
197-
itemFunctionCall(label) {
198-
itemFunctionCall(label)
199-
itemFunctionCall(label)
207+
itemFunctionCall(state) {
208+
itemFunctionCall(state)
209+
itemFunctionCall(state)
200210
}
201211
}
202212
else -> {
203-
itemFunctionCall(label) {
204-
itemFunctionCall(label) {
205-
itemFunctionCall(label)
213+
itemFunctionCall(state) {
214+
itemFunctionCall(state) {
215+
itemFunctionCall(state)
206216
}
207217
}
208218
}
@@ -212,10 +222,16 @@ private fun Code.Builder.bulletListDemoCodeSnippet(state: BulletListDemoState, t
212222
}
213223
}
214224

215-
private fun Code.Builder.itemFunctionCall(label: String, content: (Code.Builder.() -> Unit)? = null) = functionCall("item") {
225+
private fun Code.Builder.itemFunctionCall(state: BulletListDemoState, content: (Code.Builder.() -> Unit)? = null) = functionCall("item") {
216226
trailingLambda = true
217227
isMultiline = false
218-
labelArgument(label)
228+
with(state) {
229+
if (annotatedText) {
230+
annotatedStringArgument<OudsAnnotatedBulletListLabel>("label")
231+
} else {
232+
labelArgument(label)
233+
}
234+
}
219235
content?.let {
220236
lambdaArgument("builder") {
221237
content()
@@ -263,6 +279,36 @@ private fun getUnorderedAssetClasses() = if (LocalInspectionMode.current) {
263279
OudsBulletListUnorderedAsset::class.sealedSubclasses
264280
}
265281

282+
private fun OudsBulletListBuilder.bulletListDemoItem(index: Int, state: BulletListDemoState, builder: (OudsBulletListBuilder.() -> Unit)? = null) {
283+
with(state) {
284+
if (annotatedText) {
285+
val annotatedLabel = buildOudsAnnotatedBulletListLabel {
286+
when (index) {
287+
0 -> {
288+
append("Your payment was ")
289+
withStrong { append("declined") }
290+
append(".")
291+
}
292+
1 -> {
293+
append("Check your ")
294+
withStrong { append("available balance") }
295+
append(" before retrying.")
296+
}
297+
2 -> {
298+
append("Update your ")
299+
withLink(OudsLinkAnnotation.Url("https://unified-design-system.orange.com")) { append("declined") }
300+
append(" if needed.")
301+
}
302+
else -> {}
303+
}
304+
}
305+
item(label = annotatedLabel, builder = builder)
306+
} else {
307+
item(label = label, builder = builder)
308+
}
309+
}
310+
}
311+
266312
@PreviewLightDark
267313
@Composable
268314
private fun PreviewBulletListDemoScreen() = AppPreview {

app/src/main/java/com/orange/ouds/app/ui/components/bulletlist/BulletListDemoState.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ fun rememberBulletListDemoState(
3636
fontSize: OudsBulletListFontSize = OudsBulletListDefaults.TextStyle.fontSize,
3737
fontWeight: OudsBulletListFontWeight = OudsBulletListDefaults.TextStyle.fontWeight,
3838
levelCount: Int = BulletListDemoState.MinLevelCount,
39-
label: String = stringResource(R.string.app_components_common_label_label)
39+
label: String = stringResource(R.string.app_components_common_label_label),
40+
annotatedText: Boolean = false
4041
): BulletListDemoState {
4142
return rememberSaveable(
4243
type,
@@ -46,17 +47,10 @@ fun rememberBulletListDemoState(
4647
fontWeight,
4748
levelCount,
4849
label,
50+
annotatedText,
4951
saver = BulletListDemoState.Saver
5052
) {
51-
BulletListDemoState(
52-
type = type,
53-
unorderedAssetClassName = unorderedAssetClassName,
54-
unorderedAssetBrandColor = unorderedAssetBrandColor,
55-
fontSize = fontSize,
56-
fontWeight = fontWeight,
57-
levelCount = levelCount,
58-
label = label
59-
)
53+
BulletListDemoState(type, unorderedAssetClassName, unorderedAssetBrandColor, fontSize, fontWeight, levelCount, label, annotatedText)
6054
}
6155
}
6256

@@ -67,7 +61,8 @@ class BulletListDemoState(
6761
fontSize: OudsBulletListFontSize,
6862
fontWeight: OudsBulletListFontWeight,
6963
levelCount: Int,
70-
label: String
64+
label: String,
65+
annotatedText: Boolean
7166
) {
7267

7368
companion object {
@@ -84,7 +79,8 @@ class BulletListDemoState(
8479
fontSize,
8580
fontWeight,
8681
levelCount,
87-
label
82+
label,
83+
annotatedText
8884
)
8985
}
9086
},
@@ -97,7 +93,8 @@ class BulletListDemoState(
9793
list[3] as OudsBulletListFontSize,
9894
list[4] as OudsBulletListFontWeight,
9995
list[5] as Int,
100-
list[6] as String
96+
list[6] as String,
97+
list[7] as Boolean
10198
)
10299
}
103100
)
@@ -117,10 +114,14 @@ class BulletListDemoState(
117114

118115
var label: String by mutableStateOf(label)
119116

117+
var annotatedText: Boolean by mutableStateOf(annotatedText)
118+
120119
val unorderedAssetChipsEnabled: Boolean
121120
get() = type is OudsBulletListType.Unordered
122121

123122
val unorderedAssetBrandColorSwitchEnabled: Boolean
124123
get() = type is OudsBulletListType.Unordered
125124

125+
val labelTextInputEnabled: Boolean
126+
get() = !annotatedText
126127
}

0 commit comments

Comments
 (0)