feat(InstallScreen): prevent autoclosing if interacted with
This commit is contained in:
parent
1b1316d4dc
commit
0d8a04af62
3 changed files with 50 additions and 17 deletions
|
|
@ -31,6 +31,7 @@ class InstallModel(
|
||||||
) : StateScreenModel<InstallScreenState>(InstallScreenState.Pending) {
|
) : StateScreenModel<InstallScreenState>(InstallScreenState.Pending) {
|
||||||
private lateinit var startTime: Date
|
private lateinit var startTime: Date
|
||||||
private var installJob: Job? = null
|
private var installJob: Job? = null
|
||||||
|
private var autocloseCancelled: Boolean = false
|
||||||
|
|
||||||
var installSteps by mutableStateOf<ImmutableMap<StepGroup, ImmutableList<Step>>?>(null)
|
var installSteps by mutableStateOf<ImmutableMap<StepGroup, ImmutableList<Step>>?>(null)
|
||||||
private set
|
private set
|
||||||
|
|
@ -63,6 +64,13 @@ class InstallModel(
|
||||||
application.showToast(R.string.action_cleared_cache)
|
application.showToast(R.string.action_cleared_cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the screen auto-close once installation was completed
|
||||||
|
*/
|
||||||
|
fun cancelAutoclose() {
|
||||||
|
autocloseCancelled = true
|
||||||
|
}
|
||||||
|
|
||||||
fun restart() {
|
fun restart() {
|
||||||
installJob?.cancel("Manual cancellation")
|
installJob?.cancel("Manual cancellation")
|
||||||
installSteps = null
|
installSteps = null
|
||||||
|
|
@ -92,10 +100,13 @@ class InstallModel(
|
||||||
// At this point, the installation has successfully completed
|
// At this point, the installation has successfully completed
|
||||||
else {
|
else {
|
||||||
mutableState.value = InstallScreenState.Success
|
mutableState.value = InstallScreenState.Success
|
||||||
|
autocloseCancelled = false
|
||||||
|
|
||||||
// Wait 20s before returning to Home
|
// Wait 5s before returning to Home if screen hasn't been clicked
|
||||||
delay(5000)
|
delay(5000)
|
||||||
mutableState.value = InstallScreenState.CloseScreen
|
if (!autocloseCancelled) {
|
||||||
|
mutableState.value = InstallScreenState.CloseScreen
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ package com.aliucord.manager.ui.screens.install
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.foundation.*
|
import androidx.compose.foundation.*
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||||
|
|
@ -15,7 +16,6 @@ import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
@ -28,6 +28,7 @@ import com.aliucord.manager.installer.steps.StepGroup
|
||||||
import com.aliucord.manager.ui.components.Wakelock
|
import com.aliucord.manager.ui.components.Wakelock
|
||||||
import com.aliucord.manager.ui.components.back
|
import com.aliucord.manager.ui.components.back
|
||||||
import com.aliucord.manager.ui.components.dialogs.InstallerAbortDialog
|
import com.aliucord.manager.ui.components.dialogs.InstallerAbortDialog
|
||||||
|
import com.aliucord.manager.ui.screens.install.components.InstallAppBar
|
||||||
import com.aliucord.manager.ui.screens.install.components.StepGroupCard
|
import com.aliucord.manager.ui.screens.install.components.StepGroupCard
|
||||||
import com.aliucord.manager.ui.screens.installopts.InstallOptions
|
import com.aliucord.manager.ui.screens.installopts.InstallOptions
|
||||||
import org.koin.core.parameter.parametersOf
|
import org.koin.core.parameter.parametersOf
|
||||||
|
|
@ -76,19 +77,13 @@ class InstallScreen(private val data: InstallOptions) : Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = { InstallAppBar(onTryExit) },
|
||||||
TopAppBar(
|
modifier = Modifier
|
||||||
title = { Text(stringResource(R.string.installer)) },
|
.clickable(
|
||||||
navigationIcon = {
|
indication = null,
|
||||||
IconButton(onClick = onTryExit) {
|
onClick = model::cancelAutoclose,
|
||||||
Icon(
|
interactionSource = remember(::MutableInteractionSource),
|
||||||
painter = painterResource(R.drawable.ic_back),
|
),
|
||||||
contentDescription = stringResource(R.string.navigation_back),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Column(Modifier.padding(paddingValues)) {
|
Column(Modifier.padding(paddingValues)) {
|
||||||
if (state.value is InstallScreenState.Working) {
|
if (state.value is InstallScreenState.Working) {
|
||||||
|
|
@ -121,7 +116,10 @@ class InstallScreen(private val data: InstallOptions) : Screen {
|
||||||
name = stringResource(group.localizedName),
|
name = stringResource(group.localizedName),
|
||||||
subSteps = steps,
|
subSteps = steps,
|
||||||
isExpanded = expandedGroup == group,
|
isExpanded = expandedGroup == group,
|
||||||
onExpand = { expandedGroup = group },
|
onExpand = {
|
||||||
|
model.cancelAutoclose()
|
||||||
|
expandedGroup = group
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.aliucord.manager.ui.screens.install.components
|
||||||
|
|
||||||
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import com.aliucord.manager.R
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun InstallAppBar(
|
||||||
|
onTryExit: () -> Unit,
|
||||||
|
) {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text(stringResource(R.string.installer)) },
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = onTryExit) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(R.drawable.ic_back),
|
||||||
|
contentDescription = stringResource(R.string.navigation_back),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue