feat(StepStatusIcon): show progress
This commit is contained in:
parent
e118757543
commit
d4c575f496
2 changed files with 38 additions and 8 deletions
|
|
@ -22,7 +22,11 @@ fun StepItem(
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
) {
|
) {
|
||||||
StepStatusIcon(step.state, size = 18.dp)
|
StepStatusIcon(
|
||||||
|
size = 18.dp,
|
||||||
|
status = step.state,
|
||||||
|
stepProgress = step.progress,
|
||||||
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(step.localizedName),
|
text = stringResource(step.localizedName),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package com.aliucord.manager.ui.screens.install.components
|
package com.aliucord.manager.ui.screens.install.components
|
||||||
|
|
||||||
|
import androidx.compose.animation.core.*
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
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.R
|
||||||
import com.aliucord.manager.installer.steps.base.StepState
|
import com.aliucord.manager.installer.steps.base.StepState
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@Composable
|
@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 strokeWidth = Dp(floor(size.value / 10) + 1)
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
|
@ -28,12 +35,31 @@ fun StepStatusIcon(status: StepState, size: Dp) {
|
||||||
modifier = Modifier.size(size)
|
modifier = Modifier.size(size)
|
||||||
)
|
)
|
||||||
|
|
||||||
StepState.Running -> CircularProgressIndicator(
|
StepState.Running -> {
|
||||||
strokeWidth = strokeWidth,
|
val animatedProgress by animateFloatAsState(
|
||||||
modifier = Modifier
|
targetValue = stepProgress,
|
||||||
.size(size)
|
animationSpec = spring(stiffness = Spring.StiffnessVeryLow),
|
||||||
.semantics { contentDescription = context.getString(R.string.status_ongoing) }
|
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(
|
StepState.Success -> Icon(
|
||||||
painter = painterResource(R.drawable.ic_check_circle),
|
painter = painterResource(R.drawable.ic_check_circle),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue