From d4c575f496cba7b9ac5bbdfe30feeeee19bc6273 Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Tue, 6 Feb 2024 23:34:47 -0800 Subject: [PATCH] feat(StepStatusIcon): show progress --- .../ui/screens/install/components/StepItem.kt | 6 ++- .../install/components/StepStatusIcon.kt | 40 +++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepItem.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepItem.kt index 95507357..911223cf 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepItem.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepItem.kt @@ -22,7 +22,11 @@ fun StepItem( horizontalArrangement = Arrangement.spacedBy(16.dp), modifier = modifier, ) { - StepStatusIcon(step.state, size = 18.dp) + StepStatusIcon( + size = 18.dp, + status = step.state, + stepProgress = step.progress, + ) Text( text = stringResource(step.localizedName), diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepStatusIcon.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepStatusIcon.kt index 983c52a8..b6ba0f8f 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepStatusIcon.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepStatusIcon.kt @@ -1,8 +1,10 @@ package com.aliucord.manager.ui.screens.install.components +import androidx.compose.animation.core.* import androidx.compose.foundation.layout.size import androidx.compose.material3.* import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext @@ -14,9 +16,14 @@ import androidx.compose.ui.unit.Dp import com.aliucord.manager.R import com.aliucord.manager.installer.steps.base.StepState import kotlin.math.floor +import kotlin.math.roundToInt @Composable -fun StepStatusIcon(status: StepState, size: Dp) { +fun StepStatusIcon( + status: StepState, + size: Dp, + stepProgress: Float = -1f, +) { val strokeWidth = Dp(floor(size.value / 10) + 1) val context = LocalContext.current @@ -28,12 +35,31 @@ fun StepStatusIcon(status: StepState, size: Dp) { modifier = Modifier.size(size) ) - StepState.Running -> CircularProgressIndicator( - strokeWidth = strokeWidth, - modifier = Modifier - .size(size) - .semantics { contentDescription = context.getString(R.string.status_ongoing) } - ) + StepState.Running -> { + val animatedProgress by animateFloatAsState( + targetValue = stepProgress, + animationSpec = spring(stiffness = Spring.StiffnessVeryLow), + label = "Progress", + ) + + if (stepProgress > .1f) { + CircularProgressIndicator( + progress = { animatedProgress }, + strokeWidth = strokeWidth, + modifier = Modifier + .size(size) + .semantics { contentDescription = "${(stepProgress * 100).roundToInt()}%" }, + ) + } else { + // Infinite spinner + CircularProgressIndicator( + strokeWidth = strokeWidth, + modifier = Modifier + .size(size) + .semantics { contentDescription = context.getString(R.string.status_ongoing) }, + ) + } + } StepState.Success -> Icon( painter = painterResource(R.drawable.ic_check_circle),