From 47afcb722b224bc14bebfe021690bb8b00fc166b Mon Sep 17 00:00:00 2001 From: Pauline Auvray Date: Fri, 26 Aug 2022 16:31:54 +0200 Subject: [PATCH] [#254] Apply same structure for components detail screens --- .../com/orange/ods/demo/ui/OdsDemoAppState.kt | 4 +- .../ods/demo/ui/components/Component.kt | 32 +----- .../demo/ui/components/ComponentDemoScreen.kt | 48 +++++++++ .../ui/components/ComponentDetailScreen.kt | 102 ++++++++---------- ...ailScreen.kt => ComponentVariantScreen.kt} | 4 +- .../demo/ui/components/ComponentsNavGraph.kt | 23 +++- .../ComponentBottomNavigation.kt | 23 ++-- .../checkboxes/ComponentCheckboxes.kt | 22 +++- .../ui/components/dialogs/ComponentDialogs.kt | 71 ++++++------ .../components/progress/ComponentProgress.kt | 5 +- .../radiobuttons/ComponentRadioButtons.kt | 20 +++- .../ui/components/sliders/ComponentSliders.kt | 5 +- .../components/switches/ComponentSwitches.kt | 46 +++++--- demo/src/main/res/values/strings.xml | 1 + 14 files changed, 247 insertions(+), 159 deletions(-) create mode 100644 demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDemoScreen.kt rename demo/src/main/java/com/orange/ods/demo/ui/components/{VariantDetailScreen.kt => ComponentVariantScreen.kt} (93%) diff --git a/demo/src/main/java/com/orange/ods/demo/ui/OdsDemoAppState.kt b/demo/src/main/java/com/orange/ods/demo/ui/OdsDemoAppState.kt index f42680071..8cb99abd2 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/OdsDemoAppState.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/OdsDemoAppState.kt @@ -37,7 +37,9 @@ object MainDestinations { const val COMPONENT_DETAIL_ROUTE = "component" const val COMPONENT_ID_KEY = "componentId" - const val COMPONENT_SUBTYPE_ROUTE = "component/subtype" + const val COMPONENT_VARIANT_ROUTE = "component/variant" + const val COMPONENT_VARIANT_ID_KEY = "componentVariantId" + const val COMPONENT_DEMO_ROUTE = "component/demo" const val ABOUT_ITEM_DETAIL_ROUTE = "aboutItem" const val ABOUT_ITEM_ID_KEY = "aboutItemId" diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/Component.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/Component.kt index ba2a2b066..1c645782b 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/Component.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/Component.kt @@ -12,17 +12,8 @@ package com.orange.ods.demo.ui.components import androidx.annotation.DrawableRes import androidx.annotation.StringRes -import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import com.orange.ods.demo.R -import com.orange.ods.demo.ui.components.bottomnavigation.ComponentBottomNavigation -import com.orange.ods.demo.ui.components.checkboxes.ComponentCheckboxesContent -import com.orange.ods.demo.ui.components.dialogs.ComponentDialogsContent -import com.orange.ods.demo.ui.components.progress.ComponentProgressContent -import com.orange.ods.demo.ui.components.radiobuttons.ComponentRadioButtonsContent -import com.orange.ods.demo.ui.components.sliders.ComponentSlidersContent -import com.orange.ods.demo.ui.components.switches.ComponentSwitchesContent sealed class Component( @StringRes val titleRes: Int, @@ -32,7 +23,6 @@ sealed class Component( val variants: List = emptyList() ) { companion object { - const val ImageBackgroundColor = 0xff1b1b1b } @@ -88,8 +78,7 @@ sealed class Component( R.string.component_lists, R.drawable.il_lists, null, - R.string.component_lists_description, - listOf(Variant.Lists) + R.string.component_lists_description ) object Progress : Component(R.string.component_progress, R.drawable.il_progress, null, R.string.component_progress_description) @@ -111,21 +100,6 @@ sealed class Component( R.string.component_tabs_description, listOf(Variant.TabsFixed, Variant.TabsScrollable) ) - - @ExperimentalMaterialApi - @Composable - fun Detail(onVariantClick: (Long) -> Unit) { - return when (this) { - BottomNavigation -> ComponentBottomNavigation() - Checkboxes -> ComponentDetail(component = this) { ComponentCheckboxesContent() } - Dialogs -> ComponentDetail(component = this) { ComponentDialogsContent() } - Progress -> ComponentDetail(component = this) { ComponentProgressContent() } - RadioButtons -> ComponentDetail(component = this) { ComponentRadioButtonsContent() } - Sliders -> ComponentDetail(component = this) { ComponentSlidersContent() } - Switches -> ComponentDetail(component = this) { ComponentSwitchesContent() } - AppBarsTop, Buttons, Cards, Chips, Lists, TextFields, Tabs -> ComponentDetailWithVariants(component = this, onVariantClick = onVariantClick) - } - } } val components = Component::class.sealedSubclasses.mapNotNull { it.objectInstance } @@ -139,7 +113,7 @@ sealed class Variant( TextFieldOutlined(R.string.component_text_field_outlined), TextFieldFilled(R.string.component_text_field_filled) } - + val id: Long = Variant::class.sealedSubclasses.indexOf(this::class).toLong() object AppBarsTopRegular : Variant(R.string.component_app_bars_top_regular) @@ -156,8 +130,6 @@ sealed class Variant( object Chip : Variant(R.string.component_chip) object ChipFilter : Variant(R.string.component_chip_filter) - object Lists : Variant(R.string.component_lists_demo) - object TextFieldFilledText : Variant(R.string.component_text_field_text, Section.TextFieldFilled) object TextFieldFilledPassword : Variant(R.string.component_text_field_password, Section.TextFieldFilled) object TextFieldOutlinedText : Variant(R.string.component_text_field_text, Section.TextFieldOutlined) diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDemoScreen.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDemoScreen.kt new file mode 100644 index 000000000..99f4297cd --- /dev/null +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDemoScreen.kt @@ -0,0 +1,48 @@ +/* + * + * 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 + +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import com.orange.ods.demo.ui.components.bottomnavigation.ComponentBottomNavigation +import com.orange.ods.demo.ui.components.checkboxes.ComponentCheckboxes +import com.orange.ods.demo.ui.components.dialogs.ComponentDialogs +import com.orange.ods.demo.ui.components.lists.ComponentLists +import com.orange.ods.demo.ui.components.progress.ComponentProgress +import com.orange.ods.demo.ui.components.radiobuttons.ComponentRadioButtons +import com.orange.ods.demo.ui.components.sliders.ComponentSliders +import com.orange.ods.demo.ui.components.switches.ComponentSwitches + +@ExperimentalMaterialApi +@Composable +fun ComponentDemoScreen( + componentId: Long, + updateTopBarTitle: (Int) -> Unit, +) { + val component = remember { components.firstOrNull { it.id == componentId } } + + component?.let { + updateTopBarTitle(component.titleRes) + when (component) { + Component.BottomNavigation -> ComponentBottomNavigation() + Component.Checkboxes -> ComponentCheckboxes() + Component.Dialogs -> ComponentDialogs() + Component.Lists -> ComponentLists() + Component.Progress -> ComponentProgress() + Component.RadioButtons -> ComponentRadioButtons() + Component.Sliders -> ComponentSliders() + Component.Switches -> ComponentSwitches() + else -> {} + } + } + +} diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDetailScreen.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDetailScreen.kt index faa8459ca..6cd687996 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDetailScreen.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentDetailScreen.kt @@ -19,11 +19,14 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.Divider import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.Scaffold +import androidx.compose.material.Icon +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment 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.list.OdsListItem @@ -36,32 +39,53 @@ import com.orange.ods.demo.ui.components.utilities.ComponentHeader fun ComponentDetailScreen( componentId: Long, onVariantClick: (Long) -> Unit, + onDemoClick: () -> Unit, updateTopBarTitle: (Int) -> Unit ) { + val context = LocalContext.current val component = remember { components.firstOrNull { component -> component.id == componentId } } component?.let { updateTopBarTitle(component.titleRes) - component.Detail(onVariantClick = onVariantClick) - } -} -@ExperimentalMaterialApi -@Composable -fun ComponentDetail(component: Component, bottomBar: @Composable () -> Unit = {}, content: @Composable () -> Unit) { - Scaffold(bottomBar = bottomBar) { innerPadding -> - Box(modifier = Modifier.padding(innerPadding)) { + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(bottom = dimensionResource(id = R.dimen.ods_screen_vertical_margin)) + ) { + ComponentHeader( + imageRes = component.imageRes, + imageAlignment = component.imageAlignment, + description = component.descriptionRes + ) Column( - modifier = Modifier - .verticalScroll(rememberScrollState()) - .padding(bottom = dimensionResource(id = R.dimen.spacing_m)) + modifier = Modifier.padding(top = dimensionResource(id = R.dimen.spacing_m)) ) { - ComponentHeader( - imageRes = component.imageRes, - imageAlignment = component.imageAlignment, - description = component.descriptionRes - ) - content() + if (component.variants.isEmpty()) { + ComponentDetailLinkItem( + context.getString( + R.string.component_demo, + context.getString(component.titleRes) + ) + ) { onDemoClick() } + } else { + component.variants.groupBy { it.section }.forEach { (section, variants) -> + section?.let { + Divider(modifier = Modifier.padding(top = dimensionResource(id = R.dimen.spacing_s))) + Box(modifier = Modifier.height(dimensionResource(id = R.dimen.list_single_line_item_height)), contentAlignment = Alignment.Center) { + OdsTextSubtitle2( + modifier = Modifier + .padding(horizontal = dimensionResource(id = R.dimen.ods_screen_horizontal_margin)), + text = stringResource(id = section.titleRes) + ) + } + + } + variants.forEach { variant -> + ComponentDetailLinkItem(stringResource(id = variant.titleRes)) { onVariantClick(variant.id) } + } + } + } } } } @@ -69,41 +93,9 @@ fun ComponentDetail(component: Component, bottomBar: @Composable () -> Unit = {} @ExperimentalMaterialApi @Composable -fun ComponentDetailWithVariants(component: Component, onVariantClick: (Long) -> Unit) { - Column( - modifier = Modifier - .verticalScroll(rememberScrollState()) - .padding(bottom = dimensionResource(id = R.dimen.ods_screen_vertical_margin)) - ) { - ComponentHeader( - imageRes = component.imageRes, - imageAlignment = component.imageAlignment, - description = component.descriptionRes - ) - Column( - modifier = Modifier.padding(top = dimensionResource(id = R.dimen.spacing_m)) - ) { - component.variants.groupBy { it.section }.onEachIndexed { index, (section, variants) -> - section?.let { - if (index > 0) { - Divider(modifier = Modifier.padding(top = dimensionResource(id = R.dimen.spacing_s))) - } - Box(modifier = Modifier.height(dimensionResource(id = R.dimen.list_single_line_item_height)), contentAlignment = Alignment.Center) { - OdsTextSubtitle2( - modifier = Modifier - .padding(horizontal = dimensionResource(id = R.dimen.ods_screen_horizontal_margin)), - text = stringResource(id = section.titleRes) - ) - } - - } - variants.forEach { variant -> - OdsListItem(text = stringResource(id = variant.titleRes), modifier = Modifier.clickable { - onVariantClick(variant.id) - }) - } - - } - } - } +private fun ComponentDetailLinkItem(label: String, onClick: () -> Unit) { + OdsListItem( + icon = { Icon(imageVector = Icons.Filled.PlayArrow, contentDescription = null) }, + text = label, + modifier = Modifier.clickable { onClick() }) } \ No newline at end of file diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/VariantDetailScreen.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentVariantScreen.kt similarity index 93% rename from demo/src/main/java/com/orange/ods/demo/ui/components/VariantDetailScreen.kt rename to demo/src/main/java/com/orange/ods/demo/ui/components/ComponentVariantScreen.kt index 928378455..7b6254454 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/VariantDetailScreen.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentVariantScreen.kt @@ -20,7 +20,6 @@ import com.orange.ods.demo.ui.components.buttons.ComponentButtons import com.orange.ods.demo.ui.components.cards.ComponentCard import com.orange.ods.demo.ui.components.chips.VariantChip import com.orange.ods.demo.ui.components.chips.VariantChipFilter -import com.orange.ods.demo.ui.components.lists.ComponentLists import com.orange.ods.demo.ui.components.tabs.ComponentTabs import com.orange.ods.demo.ui.components.tabs.TabsConfiguration import com.orange.ods.demo.ui.components.textfields.ComponentTextField @@ -28,7 +27,7 @@ import com.orange.ods.demo.ui.components.textfields.ComponentTextField @ExperimentalMaterialApi @ExperimentalPagerApi @Composable -fun VariantDetailScreen( +fun ComponentVariantScreen( variantId: Long, updateTopBarTitle: (Int) -> Unit, updateTopAppBar: (TopAppBarConfiguration) -> Unit, @@ -44,7 +43,6 @@ fun VariantDetailScreen( Component.Buttons -> ComponentButtons(variant = variant) Component.Cards -> ComponentCard(variant = variant) Component.Chips -> if (variant == Variant.ChipFilter) VariantChipFilter() else VariantChip() - Component.Lists -> ComponentLists() Component.TextFields -> ComponentTextField(variant = variant) Component.Tabs -> ComponentTabs(variant, updateTopAppBarTabs) else -> {} diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentsNavGraph.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentsNavGraph.kt index 3bab11f2f..059c4da9a 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentsNavGraph.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/ComponentsNavGraph.kt @@ -43,22 +43,35 @@ fun NavGraphBuilder.addComponentsGraph( val componentId = arguments.getLong(MainDestinations.COMPONENT_ID_KEY) ComponentDetailScreen( componentId, - onVariantClick = { id -> onNavElementClick(MainDestinations.COMPONENT_SUBTYPE_ROUTE, id, from) }, + onVariantClick = { variantId -> onNavElementClick(MainDestinations.COMPONENT_VARIANT_ROUTE, variantId, from) }, + onDemoClick = { onNavElementClick(MainDestinations.COMPONENT_DEMO_ROUTE, componentId, from) }, updateTopBarTitle = updateTopBarTitle ) } composable( - "${MainDestinations.COMPONENT_SUBTYPE_ROUTE}/{${MainDestinations.COMPONENT_ID_KEY}}", - arguments = listOf(navArgument(MainDestinations.COMPONENT_ID_KEY) { type = NavType.LongType }) + "${MainDestinations.COMPONENT_VARIANT_ROUTE}/{${MainDestinations.COMPONENT_VARIANT_ID_KEY}}", + arguments = listOf(navArgument(MainDestinations.COMPONENT_VARIANT_ID_KEY) { type = NavType.LongType }) ) { from -> val arguments = requireNotNull(from.arguments) - val variantId = arguments.getLong(MainDestinations.COMPONENT_ID_KEY) - VariantDetailScreen( + val variantId = arguments.getLong(MainDestinations.COMPONENT_VARIANT_ID_KEY) + ComponentVariantScreen( variantId = variantId, updateTopBarTitle = updateTopBarTitle, updateTopAppBar = updateTopAppBar, updateTopAppBarTabs = updateTopAppBarTabs ) } + + composable( + "${MainDestinations.COMPONENT_DEMO_ROUTE}/{${MainDestinations.COMPONENT_ID_KEY}}", + arguments = listOf(navArgument(MainDestinations.COMPONENT_ID_KEY) { type = NavType.LongType }) + ) { from -> + val arguments = requireNotNull(from.arguments) + val componentId = arguments.getLong(MainDestinations.COMPONENT_ID_KEY) + ComponentDemoScreen( + componentId = componentId, + updateTopBarTitle = updateTopBarTitle + ) + } } \ No newline at end of file diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt index 4fc0f97a1..71a3c6eb2 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/bottomnavigation/ComponentBottomNavigation.kt @@ -11,9 +11,14 @@ package com.orange.ods.demo.ui.components.bottomnavigation import androidx.annotation.DrawableRes +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.Icon +import androidx.compose.material.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf @@ -27,8 +32,6 @@ import androidx.compose.ui.res.stringResource import com.orange.ods.compose.component.bottomnavigation.OdsBottomNavigation import com.orange.ods.compose.component.bottomnavigation.OdsBottomNavigationItem import com.orange.ods.demo.R -import com.orange.ods.demo.ui.components.Component -import com.orange.ods.demo.ui.components.ComponentDetail import com.orange.ods.demo.ui.components.bottomnavigation.ComponentBottomNavigation.MaxNavigationItemCount import com.orange.ods.demo.ui.components.bottomnavigation.ComponentBottomNavigation.MinNavigationItemCount import com.orange.ods.demo.ui.components.utilities.ComponentCountRow @@ -43,10 +46,18 @@ private object ComponentBottomNavigation { @ExperimentalMaterialApi fun ComponentBottomNavigation() { val selectedNavigationItemCount = rememberSaveable { mutableStateOf(MinNavigationItemCount) } - ComponentDetail( - component = Component.BottomNavigation, - bottomBar = { ComponentBottomNavigationBottomBar(selectedNavigationItemCount = selectedNavigationItemCount) }, - content = { ComponentBottomNavigationContent(selectedNavigationItemCount = selectedNavigationItemCount) }) + + Scaffold(bottomBar = { ComponentBottomNavigationBottomBar(selectedNavigationItemCount = selectedNavigationItemCount) }) { innerPadding -> + Box(modifier = Modifier.padding(innerPadding)) { + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(bottom = dimensionResource(id = R.dimen.spacing_m)) + ) { + ComponentBottomNavigationContent(selectedNavigationItemCount = selectedNavigationItemCount) + } + } + } } @Composable diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/checkboxes/ComponentCheckboxes.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/checkboxes/ComponentCheckboxes.kt index 46d131a75..501ef0a8b 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/checkboxes/ComponentCheckboxes.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/checkboxes/ComponentCheckboxes.kt @@ -10,22 +10,34 @@ package com.orange.ods.demo.ui.components.checkboxes +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.dimensionResource import com.orange.ods.demo.R import com.orange.ods.demo.ui.utilities.composable.CheckboxListItem import com.orange.ods.demo.ui.utilities.composable.Title @ExperimentalMaterialApi @Composable -fun ComponentCheckboxesContent() { - Title(textRes = R.string.component_checkboxes_enabled, withHorizontalPadding = true) - Checkboxes(enabled = true) +fun ComponentCheckboxes() { + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(bottom = dimensionResource(id = R.dimen.spacing_m)) + ) { + Title(textRes = R.string.component_checkboxes_enabled, withHorizontalPadding = true) + Checkboxes(enabled = true) - Title(textRes = R.string.component_checkboxes_disabled, withHorizontalPadding = true) - Checkboxes(enabled = false) + Title(textRes = R.string.component_checkboxes_disabled, withHorizontalPadding = true) + Checkboxes(enabled = false) + } } @ExperimentalMaterialApi diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/dialogs/ComponentDialogs.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/dialogs/ComponentDialogs.kt index 4593e2fe7..77c0cea86 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/dialogs/ComponentDialogs.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/dialogs/ComponentDialogs.kt @@ -12,8 +12,12 @@ package com.orange.ods.demo.ui.components.dialogs import androidx.annotation.StringRes import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState @@ -36,44 +40,51 @@ import com.orange.ods.demo.ui.utilities.composable.Title @ExperimentalMaterialApi @Composable -fun ComponentDialogsContent() { +fun ComponentDialogs() { val customizationState = rememberComponentDialogsContentState() val openDialog = rememberSaveable { mutableStateOf(false) } val closeDialogAction = { openDialog.value = false } val confirmActionRes = if (customizationState.isDismissButtonChecked) R.string.component_dialog_action_confirm else R.string.component_dialog_action_ok val context = LocalContext.current - Title(textRes = R.string.component_dialogs_customize, withHorizontalPadding = true) - Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.spacing_s))) - SwitchListItem(labelRes = R.string.component_element_title, checked = customizationState.titleChecked) - SwitchListItem(labelRes = R.string.component_dialog_element_dismiss_button, checked = customizationState.dismissButtonChecked) - OdsButton( - modifier = Modifier.fullWidthButton(), - text = stringResource(id = R.string.component_dialogs_open_dialog), - style = OdsButtonContainedStyle.Primary, - onClick = { - openDialog.value = true - } - ) - - if (openDialog.value) { - val confirmButtonText = stringResource(id = confirmActionRes) - val dismissButtonText = stringResource(id = R.string.component_dialog_action_dismiss) + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(bottom = dimensionResource(id = R.dimen.spacing_m)) + ) { - OdsAlertDialog( - titleText = if (customizationState.isTitleChecked) stringResource(id = R.string.component_element_title) else null, - text = stringResource(id = R.string.component_dialog_text), - confirmButtonText = confirmButtonText, - onConfirmButtonClick = { - clickOnElement(context = context, clickedElement = confirmButtonText) - closeDialogAction() - }, - dismissButtonText = if (customizationState.isDismissButtonChecked) dismissButtonText else null, - onDismissButtonClick = { - clickOnElement(context = context, clickedElement = dismissButtonText) - closeDialogAction() - }, + Title(textRes = R.string.component_dialogs_customize, withHorizontalPadding = true) + Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.spacing_s))) + SwitchListItem(labelRes = R.string.component_element_title, checked = customizationState.titleChecked) + SwitchListItem(labelRes = R.string.component_dialog_element_dismiss_button, checked = customizationState.dismissButtonChecked) + OdsButton( + modifier = Modifier.fullWidthButton(), + text = stringResource(id = R.string.component_dialogs_open_dialog), + style = OdsButtonContainedStyle.Primary, + onClick = { + openDialog.value = true + } ) + + if (openDialog.value) { + val confirmButtonText = stringResource(id = confirmActionRes) + val dismissButtonText = stringResource(id = R.string.component_dialog_action_dismiss) + + OdsAlertDialog( + titleText = if (customizationState.isTitleChecked) stringResource(id = R.string.component_element_title) else null, + text = stringResource(id = R.string.component_dialog_text), + confirmButtonText = confirmButtonText, + onConfirmButtonClick = { + clickOnElement(context = context, clickedElement = confirmButtonText) + closeDialogAction() + }, + dismissButtonText = if (customizationState.isDismissButtonChecked) dismissButtonText else null, + onDismissButtonClick = { + clickOnElement(context = context, clickedElement = dismissButtonText) + closeDialogAction() + }, + ) + } } } diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/progress/ComponentProgress.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/progress/ComponentProgress.kt index 82c31a0d7..533c1b806 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/progress/ComponentProgress.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/progress/ComponentProgress.kt @@ -16,6 +16,8 @@ import androidx.compose.animation.core.tween import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.LinearProgressIndicator import androidx.compose.runtime.Composable @@ -35,7 +37,7 @@ private const val DeterminateProgressTargetValue = 0.9f private const val DeterminateProgressAnimDuration = 5000 @Composable -fun ComponentProgressContent() { +fun ComponentProgress() { var determinateProgressValue by remember { mutableStateOf(0f) } val determinateProgressAnimation by animateFloatAsState( targetValue = determinateProgressValue, @@ -44,6 +46,7 @@ fun ComponentProgressContent() { Column( modifier = Modifier + .verticalScroll(rememberScrollState()) .padding(horizontal = dimensionResource(id = R.dimen.ods_screen_horizontal_margin)) .padding(bottom = dimensionResource(id = R.dimen.spacing_m)) ) { diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/radiobuttons/ComponentRadioButtons.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/radiobuttons/ComponentRadioButtons.kt index 24ff966a0..d568d5d6a 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/radiobuttons/ComponentRadioButtons.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/radiobuttons/ComponentRadioButtons.kt @@ -11,24 +11,34 @@ package com.orange.ods.demo.ui.components.radiobuttons import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.selection.selectableGroup +import androidx.compose.foundation.verticalScroll import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.res.dimensionResource import com.orange.ods.demo.R import com.orange.ods.demo.ui.utilities.composable.RadioButtonListItem import com.orange.ods.demo.ui.utilities.composable.Title @ExperimentalMaterialApi @Composable -fun ComponentRadioButtonsContent() { - Title(textRes = R.string.component_radio_buttons_enabled, withHorizontalPadding = true) - RadioButtons(enabled = true) +fun ComponentRadioButtons() { + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(bottom = dimensionResource(id = R.dimen.spacing_m)) + ) { + Title(textRes = R.string.component_radio_buttons_enabled, withHorizontalPadding = true) + RadioButtons(enabled = true) - Title(textRes = R.string.component_radio_buttons_disabled, withHorizontalPadding = true) - RadioButtons(enabled = false) + Title(textRes = R.string.component_radio_buttons_disabled, withHorizontalPadding = true) + RadioButtons(enabled = false) + } } @ExperimentalMaterialApi diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/sliders/ComponentSliders.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/sliders/ComponentSliders.kt index eb5d46963..5b13732ab 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/sliders/ComponentSliders.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/sliders/ComponentSliders.kt @@ -12,6 +12,8 @@ package com.orange.ods.demo.ui.components.sliders import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -27,11 +29,12 @@ import com.orange.ods.demo.R import com.orange.ods.demo.ui.utilities.composable.Subtitle @Composable -fun ComponentSlidersContent() { +fun ComponentSliders() { var discreteSliderPosition by remember { mutableStateOf(0f) } Column( modifier = Modifier + .verticalScroll(rememberScrollState()) .padding(horizontal = dimensionResource(id = R.dimen.spacing_m)) ) { Subtitle(R.string.component_slider_discrete, withHorizontalPadding = false) diff --git a/demo/src/main/java/com/orange/ods/demo/ui/components/switches/ComponentSwitches.kt b/demo/src/main/java/com/orange/ods/demo/ui/components/switches/ComponentSwitches.kt index e6866ae7b..d7e0f99d2 100644 --- a/demo/src/main/java/com/orange/ods/demo/ui/components/switches/ComponentSwitches.kt +++ b/demo/src/main/java/com/orange/ods/demo/ui/components/switches/ComponentSwitches.kt @@ -10,32 +10,44 @@ package com.orange.ods.demo.ui.components.switches +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.dimensionResource import com.orange.ods.demo.R import com.orange.ods.demo.ui.utilities.composable.SwitchListItem import com.orange.ods.demo.ui.utilities.composable.Title @ExperimentalMaterialApi @Composable -fun ComponentSwitchesContent() { - Title(textRes = R.string.component_switches_enabled, withHorizontalPadding = true) - SwitchListItem( - labelRes = R.string.component_element_item1, - checked = remember { mutableStateOf(true) } - ) +fun ComponentSwitches() { + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .padding(bottom = dimensionResource(id = R.dimen.spacing_m)) + ) { + Title(textRes = R.string.component_switches_enabled, withHorizontalPadding = true) + SwitchListItem( + labelRes = R.string.component_element_item1, + checked = remember { mutableStateOf(true) } + ) - Title(textRes = R.string.component_switches_disabled, withHorizontalPadding = true) - SwitchListItem( - labelRes = R.string.component_element_item1, - checked = remember { mutableStateOf(true) }, - enabled = false - ) - SwitchListItem( - labelRes = R.string.component_element_item2, - checked = remember { mutableStateOf(false) }, - enabled = false - ) + Title(textRes = R.string.component_switches_disabled, withHorizontalPadding = true) + SwitchListItem( + labelRes = R.string.component_element_item1, + checked = remember { mutableStateOf(true) }, + enabled = false + ) + SwitchListItem( + labelRes = R.string.component_element_item2, + checked = remember { mutableStateOf(false) }, + enabled = false + ) + } } diff --git a/demo/src/main/res/values/strings.xml b/demo/src/main/res/values/strings.xml index 943989b8e..6e83665f0 100644 --- a/demo/src/main/res/values/strings.xml +++ b/demo/src/main/res/values/strings.xml @@ -73,6 +73,7 @@ Item 2 Item 3 Cancel cross + %s demo