-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: animate step state icon changes
- Loading branch information
1 parent
fd702b6
commit cd517b8
Showing
4 changed files
with
91 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepStateIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.aliucord.manager.ui.screens.install.components | ||
|
||
import androidx.compose.animation.Crossfade | ||
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.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.semantics.contentDescription | ||
import androidx.compose.ui.semantics.semantics | ||
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 StepStateIcon( | ||
state: StepState, | ||
size: Dp, | ||
stepProgress: Float = -1f, | ||
) { | ||
val animatedProgress by animateFloatAsState( | ||
targetValue = stepProgress, | ||
animationSpec = spring(stiffness = Spring.StiffnessVeryLow), | ||
label = "Progress", | ||
) | ||
|
||
Crossfade(targetState = state, label = "State CrossFade") { animatedState -> | ||
when (animatedState) { | ||
StepState.Pending -> Icon( | ||
painter = painterResource(R.drawable.ic_circle), | ||
contentDescription = stringResource(R.string.status_queued), | ||
tint = MaterialTheme.colorScheme.onSurface.copy(0.4f), | ||
modifier = Modifier.size(size) | ||
) | ||
|
||
StepState.Running -> { | ||
val strokeWidth = Dp(floor(size.value / 10) + 1) | ||
|
||
if (stepProgress > .05f) { | ||
CircularProgressIndicator( | ||
progress = { animatedProgress }, | ||
strokeWidth = strokeWidth, | ||
modifier = Modifier | ||
.size(size) | ||
.semantics { contentDescription = "${(stepProgress * 100).roundToInt()}%" }, | ||
) | ||
} else { | ||
val description = stringResource(R.string.status_ongoing) | ||
|
||
// Infinite spinner | ||
CircularProgressIndicator( | ||
strokeWidth = strokeWidth, | ||
modifier = Modifier | ||
.size(size) | ||
.semantics { contentDescription = description }, | ||
) | ||
} | ||
} | ||
|
||
StepState.Success -> Icon( | ||
painter = painterResource(R.drawable.ic_check_circle), | ||
contentDescription = stringResource(R.string.status_success), | ||
tint = Color(0xFF59B463), | ||
modifier = Modifier.size(size) | ||
) | ||
|
||
StepState.Error -> Icon( | ||
painter = painterResource(R.drawable.ic_canceled), | ||
contentDescription = stringResource(R.string.status_failed), | ||
tint = MaterialTheme.colorScheme.error, | ||
modifier = Modifier.size(size) | ||
) | ||
|
||
StepState.Skipped -> Icon( | ||
painter = painterResource(R.drawable.ic_check_circle), | ||
contentDescription = stringResource(R.string.status_skipped), | ||
tint = Color(0xFFAEAEAE), | ||
modifier = Modifier.size(size) | ||
) | ||
} | ||
} | ||
} |
85 changes: 0 additions & 85 deletions
85
app/src/main/kotlin/com/aliucord/manager/ui/screens/install/components/StepStatusIcon.kt
This file was deleted.
Oops, something went wrong.