Skip to content

Commit 2f8aa4c

Browse files
committed
Review: Content of different chips in demo screen is now different
1 parent 0a15317 commit 2f8aa4c

7 files changed

Lines changed: 49 additions & 39 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ fun FunctionCall.Builder.painterArgument(@DrawableRes id: Int) {
3636
}
3737
}
3838

39-
fun FunctionCall.Builder.contentDescriptionArgument(@StringRes id: Int) = stringResourceArgument("contentDescription", id)
39+
fun FunctionCall.Builder.contentDescriptionArgument(@StringRes id: Int, vararg formatArgs: Any) = stringResourceArgument("contentDescription", id, formatArgs)
4040

4141
fun FunctionCall.Builder.onClickArgument(init: Code.Builder.() -> Unit = {}) = lambdaArgument("onClick", init)
4242

4343
fun FunctionCall.Builder.labelArgument(label: String?) = typedArgument("label", label)
4444

45-
fun FunctionCall.Builder.labelArgument(@StringRes id: Int) = stringResourceArgument("label", id)
46-
4745
fun FunctionCall.Builder.enabledArgument(boolean: Boolean) = typedArgument("enabled", boolean)

app/src/main/java/com/orange/ouds/app/ui/components/chip/ChipDemoScreen.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import androidx.annotation.StringRes
1616
import androidx.compose.foundation.layout.Arrangement
1717
import androidx.compose.foundation.layout.FlowRow
1818
import androidx.compose.foundation.layout.padding
19+
import androidx.compose.material.icons.Icons
20+
import androidx.compose.material.icons.filled.Person
21+
import androidx.compose.material.icons.filled.Phone
1922
import androidx.compose.runtime.Composable
2023
import androidx.compose.ui.Modifier
21-
import androidx.compose.ui.res.painterResource
2224
import androidx.compose.ui.res.stringResource
2325
import com.orange.ouds.app.R
2426
import com.orange.ouds.app.ui.components.contentDescriptionArgument
@@ -51,33 +53,32 @@ fun ChipDemoBottomSheetContent(state: ChipDemoState) {
5153
}
5254

5355
@Composable
54-
fun ChipDemoContent(
55-
state: ChipDemoState,
56-
content: @Composable (index: Int, icon: OudsChip.Icon) -> Unit
57-
) {
56+
fun ChipDemoContent(content: @Composable (index: Int, icon: OudsChip.Icon) -> Unit) {
57+
val icons = listOf(
58+
Icons.Filled.Person,
59+
Icons.Filled.Phone
60+
)
5861
FlowRow(horizontalArrangement = Arrangement.spacedBy(OudsTheme.spaces.fixed.small)) {
59-
val icon = OudsChip.Icon(
60-
painter = painterResource(id = R.drawable.ic_heart),
61-
contentDescription = stringResource(id = R.string.app_components_common_icon_a11y)
62-
)
63-
with(state) {
64-
repeat(ChipDemoState.ChipCount) { index ->
65-
content(index, icon)
66-
}
62+
repeat(ChipDemoState.ChipCount) { index ->
63+
val icon = OudsChip.Icon(
64+
imageVector = icons[index % icons.count()],
65+
contentDescription = stringResource(id = R.string.app_components_common_icon_a11y)
66+
)
67+
content(index, icon)
6768
}
6869
}
6970
}
7071

71-
fun FunctionCall.Builder.chipArguments(state: ChipDemoState, @StringRes labelResId: Int) = with(state) {
72+
fun FunctionCall.Builder.chipArguments(state: ChipDemoState, label: String) = with(state) {
7273
onClickArgument()
7374
if (layout in listOf(ChipDemoState.Layout.IconOnly, ChipDemoState.Layout.TextAndIcon)) {
7475
constructorCallArgument<OudsChip.Icon>("icon") {
75-
painterArgument(R.drawable.ic_heart)
76+
rawArgument("imageVector", "Icons.Filled.Person")
7677
contentDescriptionArgument(R.string.app_components_common_icon_a11y)
7778
}
7879
}
7980
if (layout in listOf(ChipDemoState.Layout.TextOnly, ChipDemoState.Layout.TextAndIcon)) {
80-
labelArgument(labelResId)
81+
labelArgument(label)
8182
}
8283
enabledArgument(enabled)
8384
}

app/src/main/java/com/orange/ouds/app/ui/components/chip/FilterChipDemoScreen.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
package com.orange.ouds.app.ui.components.chip
1414

15+
import android.content.Context
1516
import androidx.compose.runtime.Composable
17+
import androidx.compose.ui.platform.LocalContext
1618
import androidx.compose.ui.res.stringResource
1719
import androidx.compose.ui.tooling.preview.PreviewLightDark
1820
import com.orange.ouds.app.R
@@ -24,17 +26,18 @@ import com.orange.ouds.core.utilities.OudsPreview
2426
@Composable
2527
fun FilterChipDemoScreen() {
2628
val state = rememberFilterChipDemoState()
29+
val context = LocalContext.current
2730
DemoScreen(
2831
bottomSheetContent = { ChipDemoBottomSheetContent(state = state) },
29-
codeSnippet = { filterChipDemoCodeSnippet(state = state) },
32+
codeSnippet = { filterChipDemoCodeSnippet(state = state, context = context) },
3033
demoContent = { FilterChipDemoContent(state = state) }
3134
)
3235
}
3336

3437
@Composable
3538
private fun FilterChipDemoContent(state: FilterChipDemoState) {
36-
val label = stringResource(R.string.app_components_chip_filterChip_label)
37-
ChipDemoContent(state = state) { index, icon ->
39+
ChipDemoContent { index, icon ->
40+
val label = stringResource(R.string.app_components_chip_filterChip_filterChip_label, index + 1)
3841
with(state) {
3942
val selected = selectedValues[index]
4043
val onClick = { selectedValues = selectedValues.toMutableList().also { it[index] = !it[index] } }
@@ -69,12 +72,12 @@ private fun FilterChipDemoContent(state: FilterChipDemoState) {
6972
}
7073
}
7174

72-
private fun Code.Builder.filterChipDemoCodeSnippet(state: FilterChipDemoState) {
75+
private fun Code.Builder.filterChipDemoCodeSnippet(state: FilterChipDemoState, context: Context) {
7376
with(state) {
7477
comment("First filter chip")
7578
functionCall("OudsFilterChip") {
7679
typedArgument("selected", selectedValues[0])
77-
chipArguments(state, R.string.app_components_chip_filterChip_label)
80+
chipArguments(state, context.getString(R.string.app_components_chip_filterChip_filterChip_label, 1))
7881
}
7982
}
8083
}

app/src/main/java/com/orange/ouds/app/ui/components/chip/SuggestionChipDemoScreen.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
package com.orange.ouds.app.ui.components.chip
1414

15+
import android.content.Context
1516
import androidx.compose.runtime.Composable
17+
import androidx.compose.ui.platform.LocalContext
1618
import androidx.compose.ui.res.stringResource
1719
import androidx.compose.ui.tooling.preview.PreviewLightDark
1820
import com.orange.ouds.app.R
@@ -24,17 +26,18 @@ import com.orange.ouds.core.utilities.OudsPreview
2426
@Composable
2527
fun SuggestionChipDemoScreen() {
2628
val state = rememberSuggestionChipDemoState()
29+
val context = LocalContext.current
2730
DemoScreen(
2831
bottomSheetContent = { ChipDemoBottomSheetContent(state = state) },
29-
codeSnippet = { suggestionChipDemoCodeSnippet(state = state) },
32+
codeSnippet = { suggestionChipDemoCodeSnippet(state = state, context = context) },
3033
demoContent = { SuggestionChipDemoContent(state = state) }
3134
)
3235
}
3336

3437
@Composable
3538
private fun SuggestionChipDemoContent(state: SuggestionChipDemoState) {
36-
ChipDemoContent(state = state) { index, icon ->
37-
val label = stringResource(R.string.app_components_chip_suggestionChip_label)
39+
ChipDemoContent { index, icon ->
40+
val label = stringResource(R.string.app_components_chip_suggestionChip_suggestionChip_label, index + 1)
3841
with(state) {
3942
when (layout) {
4043
ChipDemoState.Layout.TextOnly -> {
@@ -64,11 +67,12 @@ private fun SuggestionChipDemoContent(state: SuggestionChipDemoState) {
6467
}
6568
}
6669

67-
private fun Code.Builder.suggestionChipDemoCodeSnippet(state: SuggestionChipDemoState) {
70+
private fun Code.Builder.suggestionChipDemoCodeSnippet(state: SuggestionChipDemoState, context: Context) {
6871
with(state) {
6972
comment("First suggestion chip")
7073
functionCall("OudsSuggestionChip") {
71-
chipArguments(state, R.string.app_components_chip_suggestionChip_label)
74+
val label = context.getString(R.string.app_components_chip_suggestionChip_suggestionChip_label, 1)
75+
chipArguments(state, label)
7276
}
7377
}
7478
}

app/src/main/java/com/orange/ouds/app/ui/utilities/Code.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ data class FunctionCall(val name: String, val elements: List<Formattable>, val i
136136

137137
fun rawArgument(name: String?, value: String) = formattableArgument(name) { value }
138138

139-
fun stringResourceArgument(name: String?, @StringRes id: Int) {
140-
formattableArgument(name) { "\"${it.getString(id)}\"" }
139+
fun stringResourceArgument(name: String?, @StringRes id: Int, vararg formatArgs: Any) {
140+
formattableArgument(name) { "\"${it.getString(id, formatArgs)}\"" }
141141
}
142142

143143
fun lambdaArgument(name: String?, init: Code.Builder.() -> Unit = {}) {

app/src/main/res/values-ar/strings.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,9 @@
112112
<string name="app_components_button_description_text">الأزرار تسمح للمستخدمين باتخاذ قرارات أو أداء إجراء. لها عدة أنماط لتلبية احتياجات مختلفة.</string>
113113
<string name="app_components_button_hierarchy_label">التسلسل</string>
114114

115-
<!-- Components: link -->
116-
<string name="app_components_link_label">رابط</string>
117-
<string name="app_components_link_description_text">تُستخدم الروابط لتوجيه المستخدمين إلى موارد أو أقسام إضافية، سواء كانت داخلية (ضمن نفس التطبيق) أو خارجية (مثل موقع إلكتروني أو مستند).</string>
118-
<string name="app_components_link_backLayout_label">عوده</string>
119-
<string name="app_components_link_nextLayout_label">التالي</string>
120-
<string name="app_components_link_size_label">حجم</string>
115+
<!-- Components: checkbox -->
121116
<string name="app_components_checkbox_label">مربع اختيار</string>
122117
<string name="app_components_checkbox_description_text"> تتيح خانات الاختيار للمستخدمين تحديد خيار واحد أو عدة خيارات من قائمة، أو تفعيل/تعطيل إعدادات، أو تأكيد إجراء معين.</string>
123-
124-
<!-- Components: checkbox -->
125118
<string name="app_components_checkbox_checkbox_label">خانة اختيار</string>
126119
<string name="app_components_checkbox_checkboxItem_label">عنصر خانة اختيار</string>
127120
<string name="app_components_checkbox_indeterminateCheckbox_label">خانة اختيار غير محدد</string>
@@ -131,7 +124,9 @@
131124
<string name="app_components_chip_label">Chip</string>
132125
<string name="app_components_chip_description_text">Chips help people enter information, make selections, filter content, or trigger actions.</string>
133126
<string name="app_components_chip_filterChip_label">Filter chip</string>
127+
<string name="app_components_chip_filterChip_filterChip_label">Filter %d</string>
134128
<string name="app_components_chip_suggestionChip_label">Suggestion chip</string>
129+
<string name="app_components_chip_suggestionChip_suggestionChip_label">Suggestion %d</string>
135130

136131
<!-- Components: control item (common strings for checkbox/radio/switch items) -->
137132
<string name="app_components_controlItem_helperText_label">نص المساعدة</string>
@@ -146,6 +141,13 @@
146141
<string name="app_components_divider_horizontalDivider_label">فاصل أفقي</string>
147142
<string name="app_components_divider_verticalDivider_label">فاصل عمودي</string>
148143

144+
<!-- Components: link -->
145+
<string name="app_components_link_label">رابط</string>
146+
<string name="app_components_link_description_text">تُستخدم الروابط لتوجيه المستخدمين إلى موارد أو أقسام إضافية، سواء كانت داخلية (ضمن نفس التطبيق) أو خارجية (مثل موقع إلكتروني أو مستند).</string>
147+
<string name="app_components_link_backLayout_label">عوده</string>
148+
<string name="app_components_link_nextLayout_label">التالي</string>
149+
<string name="app_components_link_size_label">حجم</string>
150+
149151
<!-- Components: radio button -->
150152
<string name="app_components_radioButton_label">زر الاختيار</string>
151153
<string name="app_components_radioButton_description_text">يُستخدم زر الاختيار لتمكين المستخدم من تحديد خيار واحد فقط من بين مجموعة خيارات حصرية. يُعرض عادةً كدائرة صغيرة مع تسمية، وتُملأ عند التحديد.</string>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@
135135
<string name="app_components_chip_label">Chip</string>
136136
<string name="app_components_chip_description_text">Chips help people enter information, make selections, filter content, or trigger actions.</string>
137137
<string name="app_components_chip_filterChip_label">Filter chip</string>
138+
<string name="app_components_chip_filterChip_filterChip_label">Filter %d</string>
138139
<string name="app_components_chip_suggestionChip_label">Suggestion chip</string>
140+
<string name="app_components_chip_suggestionChip_suggestionChip_label">Suggestion %d</string>
139141

140142
<!-- Components: control item (common strings for checkbox/radio/switch items) -->
141143
<string name="app_components_controlItem_helperText_label">Helper text</string>

0 commit comments

Comments
 (0)