Skip to content

Commit

Permalink
feat(PatchingScreen): cleanup layout
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Aug 4, 2024
1 parent 9dc08bd commit baad8d4
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CopyDependenciesStep : Step(), KoinComponent {
override suspend fun execute(container: StepRunner) {
val dir = paths.patchingWorkingDir()

// TODO: move this to a prepare step
if (!dir.deleteRecursively())
throw Error("Failed to clear existing patched dir")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package com.aliucord.manager.ui.screens.patching
import android.os.Parcelable
import androidx.activity.compose.BackHandler
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
Expand All @@ -21,7 +20,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
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 cafe.adriel.voyager.core.screen.Screen
Expand All @@ -47,7 +45,7 @@ import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import org.koin.core.parameter.parametersOf

private val VERTICAL_PADDING: Dp = 18.dp
val VERTICAL_PADDING: Dp = 18.dp

@Parcelize
class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
Expand All @@ -64,15 +62,6 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
val listState = rememberLazyListState()
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)
var showAbortWarning by remember(model.state.collectAsState()) { mutableStateOf(false) }

Expand All @@ -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) {
if (state == PatchingScreenState.Success)
expandedGroup = null
when (state) {
// 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)
}
Expand Down Expand Up @@ -210,7 +210,7 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
modifier = Modifier
.padding(bottom = VERTICAL_PADDING)
.fillMaxWidth()
.thenIf(state is PatchingScreenState.Success) { alpha(.6f) }
.thenIf(state is PatchingScreenState.Success) { alpha(.5f) }
)
}
}
Expand Down Expand Up @@ -251,47 +251,33 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable {
icon = painterResource(R.drawable.ic_refresh),
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") {
AnimatedContent(
targetState = model.funFact,
label = "fun fact transition",
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)
)
}
FunFact(
text = stringResource(model.funFact),
state = state,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class PatchingScreenModel(
init {
restart()

// Rotate fun facts every 20s
// Rotate fun facts every so often
screenModelScope.launch {
while (true) {
funFact = FUN_FACTS.random()
delay(20.seconds)
delay(8.seconds)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import com.aliucord.manager.R

@Composable
fun PatchingAppBar(
onTryExit: () -> Unit,
onBack: () -> Unit,
) {
TopAppBar(
title = { Text(stringResource(R.string.installer)) },
navigationIcon = {
IconButton(onClick = onTryExit) {
IconButton(onClick = onBack) {
Icon(
painter = painterResource(R.drawable.ic_back),
contentDescription = stringResource(R.string.navigation_back),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun StepGroupCard(
}

LaunchedEffect(groupState) {
if (groupState != StepState.Pending)
if (groupState == StepState.Running)
onExpand()
}

Expand Down

0 comments on commit baad8d4

Please sign in to comment.