Skip to content

Commit

Permalink
feat(StepStatusIcon): show progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Feb 7, 2024
1 parent e118757 commit d4c575f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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),
Expand Down

0 comments on commit d4c575f

Please sign in to comment.