From 46c0c7931ac55a5063f035b34bbdbb1db0f16ead Mon Sep 17 00:00:00 2001 From: Pauline Auvray Date: Fri, 18 Aug 2023 11:09:55 +0200 Subject: [PATCH 1/5] [#607] Update OdsLinearProgressIndicator API --- .../ui/components/progress/ProgressLinear.kt | 10 +++- docs/components/ProgressIndicators.md | 12 +++- .../OdsLinearProgressIndicator.kt | 57 +++++++++++++++---- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/orange/ods/app/ui/components/progress/ProgressLinear.kt b/app/src/main/java/com/orange/ods/app/ui/components/progress/ProgressLinear.kt index bf989a486..f9e834400 100644 --- a/app/src/main/java/com/orange/ods/app/ui/components/progress/ProgressLinear.kt +++ b/app/src/main/java/com/orange/ods/app/ui/components/progress/ProgressLinear.kt @@ -41,6 +41,7 @@ import com.orange.ods.compose.component.chip.OdsChoiceChipsFlowRow import com.orange.ods.compose.component.list.OdsListItem import com.orange.ods.compose.component.list.OdsSwitchTrailing import com.orange.ods.compose.component.progressindicator.OdsLinearProgressIndicator +import com.orange.ods.compose.component.progressindicator.OdsLinearProgressIndicatorIcon private const val DeterminateProgressTargetValue = 0.9f private const val DeterminateProgressAnimDuration = 5000 @@ -96,7 +97,7 @@ fun ProgressLinear() { progress = if (type.value == ProgressCustomizationState.Type.Determinate) determinateProgressAnimation else null, label = if (hasLabel) text else null, showCurrentValue = hasCurrentValue, - icon = if (hasIcon) painterResource(id = R.drawable.ic_arrow_down) else null, + icon = if (hasIcon) OdsLinearProgressIndicatorIcon(painterResource(id = R.drawable.ic_arrow_down), "") else null, modifier = Modifier .padding(top = dimensionResource(id = com.orange.ods.R.dimen.spacing_m)) .fillMaxWidth() @@ -114,7 +115,12 @@ fun ProgressLinear() { parameters = { if (type.value == ProgressCustomizationState.Type.Determinate) stringRepresentation("progress", determinateProgressValue) if (hasLabel) string("label", text) - if (hasIcon) icon() + if (hasIcon) { + classInstance("icon", OdsLinearProgressIndicatorIcon::class.java) { + painter() + contentDescription("") + } + } if (hasCurrentValue) stringRepresentation("showCurrentValue", hasCurrentValue) } ) diff --git a/docs/components/ProgressIndicators.md b/docs/components/ProgressIndicators.md index 7f250abd9..2732d7d92 100644 --- a/docs/components/ProgressIndicators.md +++ b/docs/components/ProgressIndicators.md @@ -65,7 +65,10 @@ For a **determinate** linear progress indicator, provide the progress value: OdsLinearProgressIndicator( progress = 0.9f, label = "Downloading ...", // Optional - icon = painterResource(id = R.drawable.ic_arrow_down), // Optional + icon = OdsLinearProgressIndicator( + painterResource(id = R.drawable.ic_arrow_down), + "" + ), // Optional showCurrentValue = true // Display the value in percent below the progress bar if set to true ) ``` @@ -75,7 +78,10 @@ For an **indeterminate** linear progress indicator, no need to provide a progres ```kotlin OdsLinearProgressIndicator( label = "Downloading ...", // Optional - icon = painterResource(id = R.drawable.ic_arrow_down) // Optional + icon = OdsLinearProgressIndicator( + painterResource(id = R.drawable.ic_arrow_down), + "" + ) // Optional ) ``` @@ -133,7 +139,7 @@ You can use the `OdsCircularProgressIndicator` composable like this: ```kotlin OdsCircularProgressIndicator( - progress = 0.9f, + progress = 0.9f, label = "Downloading ..." // Optional ) ``` diff --git a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt index 06e44017d..ef2abdc8c 100644 --- a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt +++ b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt @@ -13,16 +13,20 @@ package com.orange.ods.compose.component.progressindicator import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.material.Icon +import androidx.compose.foundation.layout.size +import androidx.compose.material.ButtonDefaults import androidx.compose.material.LinearProgressIndicator import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -32,6 +36,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.PreviewParameter import com.orange.ods.R import com.orange.ods.compose.component.OdsComposable +import com.orange.ods.compose.component.content.OdsComponentIcon import com.orange.ods.compose.component.utilities.BasicPreviewParameterProvider import com.orange.ods.compose.component.utilities.Preview import com.orange.ods.compose.component.utilities.UiModePreviews @@ -51,7 +56,6 @@ import com.orange.ods.extension.orElse * the progress indicator is indeterminate. * @param label The label displayed above the linear progress * @param icon The icon displayed above the linear progress - * @param iconContentDescription The content description for the icon displayed above the linear progress */ @OptIn(ExperimentalComposeUiApi::class) @Composable @@ -61,8 +65,7 @@ fun OdsLinearProgressIndicator( showCurrentValue: Boolean = false, progress: Float? = null, label: String? = null, - icon: Painter? = null, - iconContentDescription: String? = null + icon: OdsLinearProgressIndicatorIcon? = null ) { Column( modifier = modifier @@ -74,12 +77,7 @@ fun OdsLinearProgressIndicator( .padding(bottom = dimensionResource(id = R.dimen.spacing_xs)), horizontalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.spacing_s)) ) { - icon?.let { painter -> - Icon( - painter = painter, contentDescription = iconContentDescription, - tint = OdsTheme.colors.onSurface - ) - } + icon?.let { icon.Content() } if (label != null) { Text( text = label, @@ -112,6 +110,43 @@ fun OdsLinearProgressIndicator( } } +/** + * An icon in an [OdsLinearProgressIndicator]. + * It is a non-clickable button. + */ +class OdsLinearProgressIndicatorIcon : OdsComponentIcon { + + /** + * Creates an instance of [OdsLinearProgressIndicatorIcon]. + * + * @param painter Painter of the icon. + * @param contentDescription The content description associated to this [OdsLinearProgressIndicatorIcon]. + */ + constructor(painter: Painter, contentDescription: String) : super(painter as Any, contentDescription) + + /** + * Creates an instance of [OdsLinearProgressIndicatorIcon]. + * + * @param imageVector Image vector of the icon. + * @param contentDescription The content description associated to this [OdsLinearProgressIndicatorIcon]. + */ + constructor(imageVector: ImageVector, contentDescription: String) : super(imageVector as Any, contentDescription) + + /** + * Creates an instance of [OdsLinearProgressIndicatorIcon]. + * + * @param bitmap Image bitmap of the icon. + * @param contentDescription The content description associated to this [OdsLinearProgressIndicatorIcon]. + */ + constructor(bitmap: ImageBitmap, contentDescription: String) : super(bitmap as Any, contentDescription) + + @Composable + override fun Content(modifier: Modifier) { + super.Content(modifier = modifier.size(ButtonDefaults.IconSize)) + Spacer(Modifier.size(ButtonDefaults.IconSpacing)) + } +} + @UiModePreviews.Default @Composable private fun PreviewOdsLinearProgressIndicator(@PreviewParameter(OdsLinearProgressIndicatorPreviewParameterProvider::class) parameter: OdsLinearProgressIndicatorPreviewParameter) = @@ -119,7 +154,7 @@ private fun PreviewOdsLinearProgressIndicator(@PreviewParameter(OdsLinearProgres with(parameter) { OdsLinearProgressIndicator( progress = progress, - icon = iconRes?.let { painterResource(id = it) }, + icon = iconRes?.let { OdsLinearProgressIndicatorIcon(painterResource(id = it), "") }, label = label, showCurrentValue = showCurrentValue ) From f602ba722148323a852d1fea2748f160d36af01c Mon Sep 17 00:00:00 2001 From: Pauline Auvray Date: Fri, 18 Aug 2023 11:10:11 +0200 Subject: [PATCH 2/5] [#607] Update changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 2d1804f21..5b834f90b 100644 --- a/changelog.md +++ b/changelog.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - \[Lib\] Update `OdsIconButton`, `OdsIconToggleButton`and `OdsIconToggleButtonsRow` APIs ([#599](https://github.com/Orange-OpenSource/ods-android/issues/599)) - \[Lib\] Update `OdsAlertDialog` API ([#605](https://github.com/Orange-OpenSource/ods-android/issues/605)) - \[Lib\] Update `OdsFloatingActionButton` and `OdsExtendedFloatingActionButton` APIs ([#611](https://github.com/Orange-OpenSource/ods-android/issues/611)) +- \[Lib\] Update `OdsLinearProgressIndicator` API ([#607](https://github.com/Orange-OpenSource/ods-android/issues/607)) ### Fixed From 616f62fef3af8b253505d85a7771311186b6cdd5 Mon Sep 17 00:00:00 2001 From: Pauline Auvray Date: Fri, 8 Sep 2023 11:44:13 +0200 Subject: [PATCH 3/5] [#607] Review: Reorder parameters of OdsLinearProgressIndicator and OdsCircularProgressIndicator --- changelog.md | 2 +- .../progressindicator/OdsCircularProgressIndicator.kt | 6 +++--- .../progressindicator/OdsLinearProgressIndicator.kt | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index 5b834f90b..aace49df9 100644 --- a/changelog.md +++ b/changelog.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - \[Lib\] Update `OdsIconButton`, `OdsIconToggleButton`and `OdsIconToggleButtonsRow` APIs ([#599](https://github.com/Orange-OpenSource/ods-android/issues/599)) - \[Lib\] Update `OdsAlertDialog` API ([#605](https://github.com/Orange-OpenSource/ods-android/issues/605)) - \[Lib\] Update `OdsFloatingActionButton` and `OdsExtendedFloatingActionButton` APIs ([#611](https://github.com/Orange-OpenSource/ods-android/issues/611)) -- \[Lib\] Update `OdsLinearProgressIndicator` API ([#607](https://github.com/Orange-OpenSource/ods-android/issues/607)) +- \[Lib\] Update `OdsLinearProgressIndicator` and `OdsCircularProgressIndicator` APIs ([#607](https://github.com/Orange-OpenSource/ods-android/issues/607)) ### Fixed diff --git a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsCircularProgressIndicator.kt b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsCircularProgressIndicator.kt index 10b63fc85..1701f8c8a 100644 --- a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsCircularProgressIndicator.kt +++ b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsCircularProgressIndicator.kt @@ -33,17 +33,17 @@ import com.orange.ods.extension.orElse * @see androidx.compose.material.CircularProgressIndicator * * @param modifier The modifier applied to this progress indicator - * @param label The label displayed below the circular progress * @param progress The progress of this progress indicator, where 0.0 represents no progress and 1.0 * represents full progress. Values outside of this range are coerced into the range. If set to `null`, * the progress indicator is indeterminate. + * @param label The label displayed below the circular progress */ @Composable @OdsComposable fun OdsCircularProgressIndicator( modifier: Modifier = Modifier, - label: String? = null, - progress: Float? = null + progress: Float? = null, + label: String? = null ) { Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = modifier) { diff --git a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt index ef2abdc8c..24d20b3fb 100644 --- a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt +++ b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt @@ -50,22 +50,22 @@ import com.orange.ods.extension.orElse * @see androidx.compose.material.LinearProgressIndicator * * @param modifier The modifier applied to this progress indicator - * @param showCurrentValue To indicated if we have or not the current value * @param progress The value of this progress indicator, where 0.0 represents no progress and 1.0 * represents full progress. Values outside of this range are coerced into the range. If set to `null`, * the progress indicator is indeterminate. * @param label The label displayed above the linear progress * @param icon The icon displayed above the linear progress + * @param showCurrentValue Indicates whether the current value is displayed */ @OptIn(ExperimentalComposeUiApi::class) @Composable @OdsComposable fun OdsLinearProgressIndicator( modifier: Modifier = Modifier, - showCurrentValue: Boolean = false, progress: Float? = null, label: String? = null, - icon: OdsLinearProgressIndicatorIcon? = null + icon: OdsLinearProgressIndicatorIcon? = null, + showCurrentValue: Boolean = false ) { Column( modifier = modifier From c42618a1232a72088ee323d78ba21dd86f94927b Mon Sep 17 00:00:00 2001 From: Pauline Auvray Date: Fri, 8 Sep 2023 11:45:31 +0200 Subject: [PATCH 4/5] [#607] Review: Simplify code --- .../component/progressindicator/OdsLinearProgressIndicator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt index 24d20b3fb..9f2d0a3e7 100644 --- a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt +++ b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt @@ -77,7 +77,7 @@ fun OdsLinearProgressIndicator( .padding(bottom = dimensionResource(id = R.dimen.spacing_xs)), horizontalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.spacing_s)) ) { - icon?.let { icon.Content() } + icon?.Content() if (label != null) { Text( text = label, From ab5e17f5151e01282d5df33d99c4a357512c95ea Mon Sep 17 00:00:00 2001 From: Pauline Auvray Date: Fri, 8 Sep 2023 11:49:16 +0200 Subject: [PATCH 5/5] [#607] Review: Improve code --- .../component/progressindicator/OdsLinearProgressIndicator.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt index 9f2d0a3e7..badb35686 100644 --- a/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt +++ b/lib/src/main/java/com/orange/ods/compose/component/progressindicator/OdsLinearProgressIndicator.kt @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.material.ButtonDefaults import androidx.compose.material.LinearProgressIndicator import androidx.compose.material.Text @@ -78,6 +79,8 @@ fun OdsLinearProgressIndicator( horizontalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.spacing_s)) ) { icon?.Content() + Spacer(Modifier.width(ButtonDefaults.IconSpacing)) + if (label != null) { Text( text = label, @@ -143,7 +146,6 @@ class OdsLinearProgressIndicatorIcon : OdsComponentIcon { @Composable override fun Content(modifier: Modifier) { super.Content(modifier = modifier.size(ButtonDefaults.IconSize)) - Spacer(Modifier.size(ButtonDefaults.IconSpacing)) } }