Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

607 - Update OdsLinearProgressIndicator API #608

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
)
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` and `OdsCircularProgressIndicator` APIs ([#607](https://github.com/Orange-OpenSource/ods-android/issues/607))

### Fixed

Expand Down
12 changes: 9 additions & 3 deletions docs/components/ProgressIndicators.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
```
Expand All @@ -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
)
```

Expand Down Expand Up @@ -133,7 +139,7 @@ You can use the `OdsCircularProgressIndicator` composable like this:

```kotlin
OdsCircularProgressIndicator(
progress = 0.9f,
progress = 0.9f,
label = "Downloading ..." // Optional
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ 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.foundation.layout.width
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
Expand All @@ -32,6 +37,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
Expand All @@ -45,24 +51,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 iconContentDescription The content description for 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,
florentmaitre marked this conversation as resolved.
Show resolved Hide resolved
icon: Painter? = null,
iconContentDescription: String? = null
icon: OdsLinearProgressIndicatorIcon? = null,
showCurrentValue: Boolean = false
) {
Column(
modifier = modifier
Expand All @@ -74,12 +78,9 @@ 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?.Content()
Spacer(Modifier.width(ButtonDefaults.IconSpacing))

if (label != null) {
Text(
text = label,
Expand Down Expand Up @@ -112,14 +113,50 @@ 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))
}
}

@UiModePreviews.Default
@Composable
private fun PreviewOdsLinearProgressIndicator(@PreviewParameter(OdsLinearProgressIndicatorPreviewParameterProvider::class) parameter: OdsLinearProgressIndicatorPreviewParameter) =
Preview {
with(parameter) {
OdsLinearProgressIndicator(
progress = progress,
icon = iconRes?.let { painterResource(id = it) },
icon = iconRes?.let { OdsLinearProgressIndicatorIcon(painterResource(id = it), "") },
label = label,
showCurrentValue = showCurrentValue
)
Expand Down