Skip to content

Commit cd517b8

Browse files
committed
feat: animate step state icon changes
1 parent fd702b6 commit cd517b8

File tree

4 files changed

+91
-88
lines changed

4 files changed

+91
-88
lines changed

app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepGroupCard.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fun StepGroupCard(
6262
.fillMaxWidth()
6363
.padding(16.dp)
6464
) {
65-
StepStatusIcon(groupState, 24.dp)
65+
StepStateIcon(groupState, 24.dp)
6666

6767
Text(text = name)
6868

app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepItem.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ fun StepItem(
2222
horizontalArrangement = Arrangement.spacedBy(16.dp),
2323
modifier = modifier,
2424
) {
25-
StepStatusIcon(
25+
StepStateIcon(
2626
size = 18.dp,
27-
status = step.state,
27+
state = step.state,
2828
stepProgress = step.progress,
2929
)
3030

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.aliucord.manager.ui.screens.install.components
2+
3+
import androidx.compose.animation.Crossfade
4+
import androidx.compose.animation.core.*
5+
import androidx.compose.foundation.layout.size
6+
import androidx.compose.material3.*
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.runtime.getValue
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.graphics.Color
11+
import androidx.compose.ui.res.painterResource
12+
import androidx.compose.ui.res.stringResource
13+
import androidx.compose.ui.semantics.contentDescription
14+
import androidx.compose.ui.semantics.semantics
15+
import androidx.compose.ui.unit.Dp
16+
import com.aliucord.manager.R
17+
import com.aliucord.manager.installer.steps.base.StepState
18+
import kotlin.math.floor
19+
import kotlin.math.roundToInt
20+
21+
@Composable
22+
fun StepStateIcon(
23+
state: StepState,
24+
size: Dp,
25+
stepProgress: Float = -1f,
26+
) {
27+
val animatedProgress by animateFloatAsState(
28+
targetValue = stepProgress,
29+
animationSpec = spring(stiffness = Spring.StiffnessVeryLow),
30+
label = "Progress",
31+
)
32+
33+
Crossfade(targetState = state, label = "State CrossFade") { animatedState ->
34+
when (animatedState) {
35+
StepState.Pending -> Icon(
36+
painter = painterResource(R.drawable.ic_circle),
37+
contentDescription = stringResource(R.string.status_queued),
38+
tint = MaterialTheme.colorScheme.onSurface.copy(0.4f),
39+
modifier = Modifier.size(size)
40+
)
41+
42+
StepState.Running -> {
43+
val strokeWidth = Dp(floor(size.value / 10) + 1)
44+
45+
if (stepProgress > .05f) {
46+
CircularProgressIndicator(
47+
progress = { animatedProgress },
48+
strokeWidth = strokeWidth,
49+
modifier = Modifier
50+
.size(size)
51+
.semantics { contentDescription = "${(stepProgress * 100).roundToInt()}%" },
52+
)
53+
} else {
54+
val description = stringResource(R.string.status_ongoing)
55+
56+
// Infinite spinner
57+
CircularProgressIndicator(
58+
strokeWidth = strokeWidth,
59+
modifier = Modifier
60+
.size(size)
61+
.semantics { contentDescription = description },
62+
)
63+
}
64+
}
65+
66+
StepState.Success -> Icon(
67+
painter = painterResource(R.drawable.ic_check_circle),
68+
contentDescription = stringResource(R.string.status_success),
69+
tint = Color(0xFF59B463),
70+
modifier = Modifier.size(size)
71+
)
72+
73+
StepState.Error -> Icon(
74+
painter = painterResource(R.drawable.ic_canceled),
75+
contentDescription = stringResource(R.string.status_failed),
76+
tint = MaterialTheme.colorScheme.error,
77+
modifier = Modifier.size(size)
78+
)
79+
80+
StepState.Skipped -> Icon(
81+
painter = painterResource(R.drawable.ic_check_circle),
82+
contentDescription = stringResource(R.string.status_skipped),
83+
tint = Color(0xFFAEAEAE),
84+
modifier = Modifier.size(size)
85+
)
86+
}
87+
}
88+
}

app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepStatusIcon.kt

-85
This file was deleted.

0 commit comments

Comments
 (0)