feat(PatchingScreen): cleanup layout

This commit is contained in:
rushiiMachine 2024-08-04 11:49:08 -07:00
parent 9dc08bd1d0
commit baad8d4a94
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
6 changed files with 91 additions and 56 deletions

View file

@ -27,7 +27,6 @@ class CopyDependenciesStep : Step(), KoinComponent {
override suspend fun execute(container: StepRunner) { override suspend fun execute(container: StepRunner) {
val dir = paths.patchingWorkingDir() val dir = paths.patchingWorkingDir()
// TODO: move this to a prepare step
if (!dir.deleteRecursively()) if (!dir.deleteRecursively())
throw Error("Failed to clear existing patched dir") throw Error("Failed to clear existing patched dir")

View file

@ -8,7 +8,6 @@ package com.aliucord.manager.ui.screens.patching
import android.os.Parcelable import android.os.Parcelable
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.animation.* import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
@ -21,7 +20,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen import cafe.adriel.voyager.core.screen.Screen
@ -47,7 +45,7 @@ import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
import org.koin.core.parameter.parametersOf import org.koin.core.parameter.parametersOf
private val VERTICAL_PADDING: Dp = 18.dp val VERTICAL_PADDING: Dp = 18.dp
@Parcelize @Parcelize
class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable { class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
@ -64,15 +62,6 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
val listState = rememberLazyListState() val listState = rememberLazyListState()
val showMinimizationWarning = remember { !context.isIgnoringBatteryOptimizations() } val showMinimizationWarning = remember { !context.isIgnoringBatteryOptimizations() }
// Go home directly if screen model mandates so (usually caused by cancelled PackageInstaller dialog)
LaunchedEffect(state) {
if (state is PatchingScreenState.CloseScreen)
navigator.popUntilRoot()
}
// Prevent screen from turning off while working
Wakelock(active = state is PatchingScreenState.Working)
// Exit warning dialog (dismiss itself if install process state changes, esp. for Success) // Exit warning dialog (dismiss itself if install process state changes, esp. for Success)
var showAbortWarning by remember(model.state.collectAsState()) { mutableStateOf(false) } var showAbortWarning by remember(model.state.collectAsState()) { mutableStateOf(false) }
@ -97,10 +86,21 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
} }
} }
// Close all groups when successfully finished everything // Prevent screen from turning off while working
Wakelock(active = state is PatchingScreenState.Working)
LaunchedEffect(state) { LaunchedEffect(state) {
if (state == PatchingScreenState.Success) when (state) {
expandedGroup = null // Go home directly if screen model mandates so (usually caused by cancelled PackageInstaller dialog)
PatchingScreenState.CloseScreen -> navigator.popUntilRoot()
// Close all groups when successfully finished everything
PatchingScreenState.Success -> {
expandedGroup = null
}
else -> {}
}
listState.animateScrollToItem(0) listState.animateScrollToItem(0)
} }
@ -210,7 +210,7 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
modifier = Modifier modifier = Modifier
.padding(bottom = VERTICAL_PADDING) .padding(bottom = VERTICAL_PADDING)
.fillMaxWidth() .fillMaxWidth()
.thenIf(state is PatchingScreenState.Success) { alpha(.6f) } .thenIf(state is PatchingScreenState.Success) { alpha(.5f) }
) )
} }
} }
@ -251,47 +251,33 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
icon = painterResource(R.drawable.ic_refresh), icon = painterResource(R.drawable.ic_refresh),
onClick = model::restart, onClick = model::restart,
) )
MainActionButton(
text = stringResource(R.string.setting_clear_cache),
icon = painterResource(R.drawable.ic_delete_forever),
enabled = !cacheCleared,
colors = IconButtonDefaults.filledTonalIconButtonColors(
containerColor = MaterialTheme.colorScheme.error,
),
onClick = {
cacheCleared = true
model.clearCache()
},
modifier = Modifier
.padding(top = 14.dp)
.fillMaxWidth()
)
} }
} }
MainActionButton(
text = stringResource(R.string.setting_clear_cache),
icon = painterResource(R.drawable.ic_delete_forever),
enabled = !cacheCleared,
colors = IconButtonDefaults.filledTonalIconButtonColors(
containerColor = MaterialTheme.colorScheme.error,
),
onClick = {
cacheCleared = true
model.clearCache()
},
modifier = Modifier
.padding(top = 14.dp)
.fillMaxWidth()
)
} }
} }
} }
item(key = "FUN_FACT") { item(key = "FUN_FACT") {
AnimatedContent( FunFact(
targetState = model.funFact, text = stringResource(model.funFact),
label = "fun fact transition", state = state,
transitionSpec = { )
(fadeIn(tween(220, delayMillis = 90)) + slideInHorizontally { it * -2 }) togetherWith
(fadeOut(tween(90)) + slideOutHorizontally { it * 2 })
}
) { text ->
Text(
text = stringResource(R.string.fun_fact_prefix, stringResource(text)),
style = MaterialTheme.typography.bodySmall,
textAlign = TextAlign.Center,
modifier = Modifier
.padding(top = VERTICAL_PADDING, bottom = 25.dp, start = VERTICAL_PADDING, end = VERTICAL_PADDING)
.fillMaxWidth()
.alpha(.6f)
)
}
} }
} }
} }

View file

@ -55,11 +55,11 @@ class PatchingScreenModel(
init { init {
restart() restart()
// Rotate fun facts every 20s // Rotate fun facts every so often
screenModelScope.launch { screenModelScope.launch {
while (true) { while (true) {
funFact = FUN_FACTS.random() funFact = FUN_FACTS.random()
delay(20.seconds) delay(8.seconds)
} }
} }
} }

View file

@ -0,0 +1,50 @@
package com.aliucord.manager.ui.screens.patching.components
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.aliucord.manager.R
import com.aliucord.manager.ui.screens.patching.PatchingScreenState
import com.aliucord.manager.ui.screens.patching.VERTICAL_PADDING
@Composable
fun FunFact(
text: String,
state: PatchingScreenState,
) {
AnimatedVisibility(
visible = state !is PatchingScreenState.Failed,
enter = fadeIn() + slideInVertically { it * 2 },
exit = fadeOut() + slideOutVertically { it * 2 },
label = "fun fact visibility"
) {
AnimatedContent(
targetState = text,
label = "fun fact change",
transitionSpec = {
val inSpec = fadeIn(tween(220, delayMillis = 90)) + slideInHorizontally { it * -2 }
val outSpec = fadeOut(tween(90)) + slideOutHorizontally { it * 2 }
inSpec togetherWith outSpec
}
) { text ->
Text(
text = stringResource(R.string.fun_fact_prefix, text),
style = MaterialTheme.typography.bodySmall,
textAlign = TextAlign.Center,
modifier = Modifier
.padding(top = VERTICAL_PADDING, bottom = 25.dp, start = VERTICAL_PADDING, end = VERTICAL_PADDING)
.fillMaxWidth()
.alpha(.6f)
)
}
}
}

View file

@ -8,12 +8,12 @@ import com.aliucord.manager.R
@Composable @Composable
fun PatchingAppBar( fun PatchingAppBar(
onTryExit: () -> Unit, onBack: () -> Unit,
) { ) {
TopAppBar( TopAppBar(
title = { Text(stringResource(R.string.installer)) }, title = { Text(stringResource(R.string.installer)) },
navigationIcon = { navigationIcon = {
IconButton(onClick = onTryExit) { IconButton(onClick = onBack) {
Icon( Icon(
painter = painterResource(R.drawable.ic_back), painter = painterResource(R.drawable.ic_back),
contentDescription = stringResource(R.string.navigation_back), contentDescription = stringResource(R.string.navigation_back),

View file

@ -51,7 +51,7 @@ fun StepGroupCard(
} }
LaunchedEffect(groupState) { LaunchedEffect(groupState) {
if (groupState != StepState.Pending) if (groupState == StepState.Running)
onExpand() onExpand()
} }