manager: disabled save log and back instance untill flashing is completed, hide bottom navbar and add additional close button

This commit is contained in:
Rifat Azad
2024-12-28 14:11:22 +06:00
parent ced32e9280
commit 30ba05d8b4
3 changed files with 50 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState
import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationStyle
import com.ramcosta.composedestinations.generated.destinations.ExecuteModuleActionScreenDestination
import com.ramcosta.composedestinations.generated.destinations.FlashScreenDestination
import com.ramcosta.composedestinations.generated.NavGraphs
import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState
import com.ramcosta.composedestinations.utils.rememberDestinationsNavigator
@@ -83,6 +84,7 @@ class MainActivity : ComponentActivity() {
val currentDestination = navController.currentBackStackEntryAsState()?.value?.destination
val showBottomBar = when (currentDestination?.route) {
FlashScreenDestination.route -> false // Hide for FlashScreenDestination
ExecuteModuleActionScreenDestination.route -> false // Hide for ExecuteModuleActionScreen
else -> true
}

View File

@@ -66,7 +66,6 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String
BackHandler(enabled = isActionRunning) {
// Disable back button if action is running
// TODO: Disable Destination Navbar to evade hang on destonation change caused by runModuleAction() in ui.util.KsuCli, users shoudln't get out of actionScreen if action is running
}
LaunchedEffect(Unit) {

View File

@@ -3,6 +3,8 @@ package com.rifsxd.ksunext.ui.screen
import android.net.Uri
import android.os.Environment
import android.os.Parcelable
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
@@ -13,8 +15,8 @@ import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Save
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
@@ -35,6 +37,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.key
@@ -93,6 +96,10 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) {
mutableStateOf(FlashingStatus.FLASHING)
}
BackHandler(enabled = flashing == FlashingStatus.FLASHING) {
// Disable back button if flashing is running
}
LaunchedEffect(Unit) {
if (text.isNotEmpty()) {
return@LaunchedEffect
@@ -125,9 +132,6 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) {
topBar = {
TopBar(
flashing,
onBack = {
navigator.popBackStack()
},
onSave = {
scope.launch {
val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault())
@@ -143,22 +147,6 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) {
scrollBehavior = scrollBehavior
)
},
floatingActionButton = {
if (showFloatAction) {
val reboot = stringResource(id = R.string.reboot)
ExtendedFloatingActionButton(
onClick = {
scope.launch {
withContext(Dispatchers.IO) {
reboot()
}
}
},
icon = { Icon(Icons.Filled.Refresh, reboot) },
text = { Text(text = reboot) },
)
}
},
snackbarHost = { SnackbarHost(hostState = snackBarHost) },
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal)
) { innerPadding ->
@@ -183,6 +171,42 @@ fun FlashScreen(navigator: DestinationsNavigator, flashIt: FlashIt) {
lineHeight = MaterialTheme.typography.bodySmall.lineHeight,
)
}
// Floating Action Buttons
Box(modifier = Modifier.fillMaxSize()) {
// Reboot button (bottom left)
if (showFloatAction) {
val reboot = stringResource(id = R.string.reboot)
ExtendedFloatingActionButton(
onClick = {
scope.launch {
withContext(Dispatchers.IO) {
reboot()
}
}
},
icon = { Icon(Icons.Filled.Refresh, reboot) },
text = { Text(text = reboot) },
modifier = Modifier
.align(Alignment.BottomStart)
.padding(16.dp)
)
}
if (showFloatAction) {
// Back button (bottom right)
ExtendedFloatingActionButton(
onClick = {
navigator.popBackStack()
},
text = { Text(text = stringResource(R.string.close)) },
icon = { Icon(Icons.Filled.Close, contentDescription = null) },
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp)
)
}
}
}
}
@@ -225,7 +249,6 @@ fun flashIt(
@Composable
private fun TopBar(
status: FlashingStatus,
onBack: () -> Unit = {},
onSave: () -> Unit = {},
scrollBehavior: TopAppBarScrollBehavior? = null
) {
@@ -241,13 +264,11 @@ private fun TopBar(
)
)
},
navigationIcon = {
IconButton(
onClick = onBack
) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null) }
},
actions = {
IconButton(onClick = onSave) {
IconButton(
onClick = { if (status != FlashingStatus.FLASHING) onSave() },
enabled = status != FlashingStatus.FLASHING
) {
Icon(
imageVector = Icons.Filled.Save,
contentDescription = "Localized description"