-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
manager: hides navbar on action screen, disable back gesture and save… #2321
Changes from 4 commits
2525643
db64764
967e850
f31a90f
dea8abd
8a69478
b2e98a8
0d17801
64a367e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
package me.weishu.kernelsu.ui.screen | ||
|
||
import android.os.Environment | ||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.navigationBarsPadding | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.WindowInsetsSides | ||
import androidx.compose.foundation.layout.defaultMinSize | ||
import androidx.compose.foundation.layout.safeDrawing | ||
import androidx.compose.foundation.layout.only | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
import androidx.compose.material.icons.filled.Close | ||
import androidx.compose.material.icons.filled.Save | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.ExtendedFloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
|
@@ -49,12 +57,17 @@ import java.util.Locale | |
@Destination<RootGraph> | ||
fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String) { | ||
var text by rememberSaveable { mutableStateOf("") } | ||
var tempText : String | ||
var tempText: String | ||
val logContent = rememberSaveable { StringBuilder() } | ||
val snackBarHost = LocalSnackbarHost.current | ||
val scope = rememberCoroutineScope() | ||
val scrollState = rememberScrollState() | ||
var actionResult: Boolean | ||
var isActionRunning by rememberSaveable { mutableStateOf(true) } | ||
|
||
BackHandler(enabled = isActionRunning) { | ||
// Disable back button if action is running | ||
} | ||
|
||
LaunchedEffect(Unit) { | ||
if (text.isNotEmpty()) { | ||
|
@@ -79,29 +92,43 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String | |
actionResult = it | ||
} | ||
} | ||
if (actionResult) navigator.popBackStack() | ||
isActionRunning = false | ||
} | ||
|
||
Scaffold( | ||
topBar = { | ||
TopBar( | ||
onBack = { | ||
navigator.popBackStack() | ||
}, | ||
isActionRunning = isActionRunning, | ||
onSave = { | ||
scope.launch { | ||
val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault()) | ||
val date = format.format(Date()) | ||
val file = File( | ||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), | ||
"KernelSU_module_action_log_${date}.log" | ||
) | ||
file.writeText(logContent.toString()) | ||
snackBarHost.showSnackbar("Log saved to ${file.absolutePath}") | ||
if (!isActionRunning) { | ||
scope.launch { | ||
val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault()) | ||
val date = format.format(Date()) | ||
val file = File( | ||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), | ||
"KernelSU_Next_module_action_log_${date}.log" | ||
) | ||
file.writeText(logContent.toString()) | ||
snackBarHost.showSnackbar("Log saved to ${file.absolutePath}") | ||
} | ||
} | ||
} | ||
) | ||
}, | ||
floatingActionButton = { | ||
if (!isActionRunning) { | ||
ExtendedFloatingActionButton( | ||
text = { Text(text = stringResource(R.string.close)) }, | ||
icon = { Icon(Icons.Filled.Close, contentDescription = null) }, | ||
onClick = { | ||
navigator.popBackStack() | ||
}, | ||
modifier = Modifier | ||
.navigationBarsPadding() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think change the contentWindowInsets (line 131 for now ) to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the system to decide? Sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It was for when |
||
) | ||
} | ||
}, | ||
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal), | ||
snackbarHost = { SnackbarHost(snackBarHost) } | ||
) { innerPadding -> | ||
KeyEventBlocker { | ||
|
@@ -129,16 +156,14 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String | |
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun TopBar(onBack: () -> Unit = {}, onSave: () -> Unit = {}) { | ||
private fun TopBar(isActionRunning: Boolean, onSave: () -> Unit = {}) { | ||
TopAppBar( | ||
title = { Text(stringResource(R.string.action)) }, | ||
navigationIcon = { | ||
IconButton( | ||
onClick = onBack | ||
) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null) } | ||
}, | ||
actions = { | ||
IconButton(onClick = onSave) { | ||
IconButton( | ||
onClick = onSave, | ||
enabled = !isActionRunning | ||
) { | ||
Icon( | ||
imageVector = Icons.Filled.Save, | ||
contentDescription = stringResource(id = R.string.save_log), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the
Next
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lmao I forgot to get rid of it, it's from my branch xD