11package app.revanced.manager.ui.component.patcher
22
33import androidx.compose.animation.AnimatedVisibility
4- import androidx.compose.animation.animateColorAsState
4+ import androidx.compose.animation.Crossfade
55import androidx.compose.foundation.background
66import androidx.compose.foundation.clickable
77import androidx.compose.foundation.layout.Arrangement
@@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.Spacer
1212import androidx.compose.foundation.layout.fillMaxWidth
1313import androidx.compose.foundation.layout.padding
1414import androidx.compose.foundation.layout.size
15- import androidx.compose.foundation.shape.RoundedCornerShape
1615import androidx.compose.material.icons.Icons
1716import androidx.compose.material.icons.filled.Cancel
1817import androidx.compose.material.icons.filled.CheckCircle
@@ -21,6 +20,7 @@ import androidx.compose.material3.Icon
2120import androidx.compose.material3.MaterialTheme
2221import androidx.compose.material3.Text
2322import androidx.compose.runtime.Composable
23+ import androidx.compose.runtime.LaunchedEffect
2424import androidx.compose.runtime.getValue
2525import androidx.compose.runtime.mutableStateOf
2626import androidx.compose.runtime.remember
@@ -53,20 +53,10 @@ fun Steps(
5353 category : StepCategory ,
5454 steps : List <Step >,
5555 stepCount : Pair <Int , Int >? = null,
56- stepProgressProvider : StepProgressProvider
56+ stepProgressProvider : StepProgressProvider ,
57+ isExpanded : Boolean = false,
58+ onExpand : () -> Unit
5759) {
58- var expanded by rememberSaveable { mutableStateOf(true ) }
59-
60- val categoryColor by animateColorAsState(
61- if (expanded) MaterialTheme .colorScheme.surfaceContainerHigh else Color .Transparent ,
62- label = " category"
63- )
64-
65- val cardColor by animateColorAsState(
66- if (expanded) MaterialTheme .colorScheme.surfaceContainer else Color .Transparent ,
67- label = " card"
68- )
69-
7060 val state = remember(steps) {
7161 when {
7262 steps.all { it.state == State .COMPLETED } -> State .COMPLETED
@@ -76,23 +66,25 @@ fun Steps(
7666 }
7767 }
7868
69+ LaunchedEffect (state) {
70+ if (state == State .RUNNING )
71+ onExpand()
72+ }
73+
7974 Column (
8075 modifier = Modifier
81- .clip(RoundedCornerShape ( 16 .dp) )
76+ .clip(MaterialTheme .shapes.large )
8277 .fillMaxWidth()
83- .background(cardColor )
78+ .background(MaterialTheme .colorScheme.surfaceContainerLow )
8479 ) {
8580 Row (
81+ verticalAlignment = Alignment .CenterVertically ,
82+ horizontalArrangement = Arrangement .spacedBy(14 .dp),
8683 modifier = Modifier
87- .clip( RoundedCornerShape ( 16 .dp) )
88- .clickable { expanded = ! expanded }
89- .background(categoryColor )
84+ .clickable( true , onClick = onExpand )
85+ .fillMaxWidth()
86+ .padding( 20 .dp )
9087 ) {
91- Row (
92- verticalAlignment = Alignment .CenterVertically ,
93- horizontalArrangement = Arrangement .spacedBy(12 .dp),
94- modifier = Modifier .padding(16 .dp)
95- ) {
9688 StepIcon (state = state, size = 24 .dp)
9789
9890 Text (stringResource(category.displayName))
@@ -109,13 +101,17 @@ fun Steps(
109101 style = MaterialTheme .typography.labelSmall
110102 )
111103
112- ArrowButton (modifier = Modifier .size(24 .dp), expanded = expanded, onClick = null )
113- }
104+ ArrowButton (modifier = Modifier .size(24 .dp), expanded = isExpanded, onClick = null )
114105 }
115106
116- AnimatedVisibility (visible = expanded ) {
107+ AnimatedVisibility (visible = isExpanded ) {
117108 Column (
118- modifier = Modifier .fillMaxWidth()
109+ verticalArrangement = Arrangement .spacedBy(16 .dp),
110+ modifier = Modifier
111+ .background(MaterialTheme .colorScheme.background.copy(0.6f ))
112+ .fillMaxWidth()
113+ .padding(start = 10 .dp, end = 10 .dp, top = 10 .dp, bottom = 20 .dp)
114+ .padding(start = 4 .dp)
119115 ) {
120116 steps.forEach { step ->
121117 val (progress, progressText) = when (step.progressKey) {
@@ -155,23 +151,21 @@ fun SubStep(
155151 if (message != null )
156152 clickable { messageExpanded = ! messageExpanded }
157153 else this
158- }
154+ }.add
159155 ) {
160156 Row (
161157 verticalAlignment = Alignment .CenterVertically ,
162- horizontalArrangement = Arrangement .spacedBy(12 .dp),
163- modifier = Modifier .padding(horizontal = 16 .dp, vertical = 8 .dp)
158+ horizontalArrangement = Arrangement .spacedBy(16 .dp),
164159 ) {
165- Box (
166- modifier = Modifier .size(24 .dp),
167- contentAlignment = Alignment .Center
168- ) {
169- StepIcon (state, progress, size = 20 .dp)
170- }
160+ StepIcon (
161+ size = 18 .dp,
162+ state = state,
163+ progress = progress,
164+ )
171165
172166 Text (
173167 text = name,
174- style = MaterialTheme .typography.titleSmall ,
168+ style = MaterialTheme .typography.labelLarge ,
175169 maxLines = 1 ,
176170 overflow = TextOverflow .Ellipsis ,
177171 modifier = Modifier .weight(1f , true ),
@@ -211,40 +205,44 @@ fun SubStep(
211205fun StepIcon (state : State , progress : Float? = null, size : Dp ) {
212206 val strokeWidth = Dp (floor(size.value / 10 ) + 1 )
213207
214- when (state) {
215- State .COMPLETED -> Icon (
216- Icons .Filled .CheckCircle ,
217- contentDescription = stringResource(R .string.step_completed),
218- tint = MaterialTheme .colorScheme.surfaceTint,
219- modifier = Modifier .size(size)
220- )
221-
222- State .FAILED -> Icon (
223- Icons .Filled .Cancel ,
224- contentDescription = stringResource(R .string.step_failed),
225- tint = MaterialTheme .colorScheme.error,
226- modifier = Modifier .size(size)
227- )
228-
229- State .WAITING -> Icon (
230- Icons .Outlined .Circle ,
231- contentDescription = stringResource(R .string.step_waiting),
232- tint = MaterialTheme .colorScheme.surfaceVariant,
233- modifier = Modifier .size(size)
234- )
235-
236- State .RUNNING ->
237- LoadingIndicator (
238- modifier = stringResource(R .string.step_running).let { description ->
239- Modifier
240- .size(size)
241- .semantics {
242- contentDescription = description
243- }
244- },
245- progress = { progress },
246- strokeWidth = strokeWidth
208+ Crossfade (targetState = state, label = " State CrossFade" ) { state ->
209+ when (state) {
210+ State .COMPLETED -> Icon (
211+ Icons .Filled .CheckCircle ,
212+ contentDescription = stringResource(R .string.step_completed),
213+ tint = Color (0xFF59B463 ),
214+ modifier = Modifier .size(size)
215+ )
216+
217+ State .FAILED -> Icon (
218+ Icons .Filled .Cancel ,
219+ contentDescription = stringResource(R .string.step_failed),
220+ tint = MaterialTheme .colorScheme.error,
221+ modifier = Modifier .size(size)
222+ )
223+
224+ State .WAITING -> Icon (
225+ Icons .Outlined .Circle ,
226+ contentDescription = stringResource(R .string.step_waiting),
227+ tint = MaterialTheme .colorScheme.onSurface.copy(.2f ),
228+ modifier = Modifier .size(size)
247229 )
230+
231+ State .RUNNING -> {
232+ LoadingIndicator (
233+ modifier = stringResource(R .string.step_running).let { description ->
234+ Modifier
235+ .size(size)
236+ .semantics {
237+ contentDescription = description
238+ }
239+ },
240+
241+ progress = { progress },
242+ strokeWidth = strokeWidth
243+ )
244+ }
245+ }
248246 }
249247}
250248
0 commit comments