You've already forked KernelSU-Next
mirror of
https://github.com/KernelSU-Next/KernelSU-Next.git
synced 2025-08-27 23:46:34 +00:00
manager: added module install confirmation
This commit is contained in:
@@ -35,6 +35,7 @@ import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.outlined.PlayArrow
|
||||
import androidx.compose.material.icons.outlined.Download
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
@@ -51,6 +52,7 @@ import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarResult
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
|
||||
@@ -124,6 +126,9 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
|
||||
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
|
||||
|
||||
var zipUri by remember { mutableStateOf<Uri?>(null) }
|
||||
var showConfirmDialog by remember { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
@@ -137,18 +142,16 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
val moduleInstall = stringResource(id = R.string.module_install)
|
||||
val selectZipLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.StartActivityForResult()
|
||||
) {
|
||||
if (it.resultCode != RESULT_OK) {
|
||||
) { result ->
|
||||
if (result.resultCode != RESULT_OK) {
|
||||
return@rememberLauncherForActivityResult
|
||||
}
|
||||
val data = it.data ?: return@rememberLauncherForActivityResult
|
||||
val data = result.data ?: return@rememberLauncherForActivityResult
|
||||
val uri = data.data ?: return@rememberLauncherForActivityResult
|
||||
|
||||
navigator.navigate(FlashScreenDestination(FlashIt.FlashModule(uri)))
|
||||
|
||||
viewModel.markNeedRefresh()
|
||||
|
||||
Log.i("ModuleScreen", "select zip result: ${it.data}")
|
||||
// save the selected Uri and trigger confirmation dialog
|
||||
zipUri = uri
|
||||
showConfirmDialog = true
|
||||
}
|
||||
|
||||
ExtendedFloatingActionButton(
|
||||
@@ -167,6 +170,35 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
|
||||
snackbarHost = { SnackbarHost(hostState = snackBarHost) }
|
||||
) { innerPadding ->
|
||||
// confirmation dialog
|
||||
if (showConfirmDialog && zipUri != null) {
|
||||
// extract the module name from the zipUri
|
||||
val moduleName = zipUri?.lastPathSegment?.substringAfterLast('/') ?: "Unknown Module"
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { showConfirmDialog = false },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
showConfirmDialog = false
|
||||
navigator.navigate(FlashScreenDestination(FlashIt.FlashModule(zipUri!!)))
|
||||
}) {
|
||||
Text(stringResource(R.string.confirm))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showConfirmDialog = false }) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
},
|
||||
title = { Text(stringResource(R.string.confirm_module_installation)) },
|
||||
text = {
|
||||
Text(
|
||||
stringResource(R.string.module_install_prompt_with_name, moduleName)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
when {
|
||||
hasMagisk -> {
|
||||
Box(
|
||||
@@ -181,7 +213,6 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
ModuleList(
|
||||
navigator,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="confirm">Confirm</string>
|
||||
<string name="app_name" translatable="false">KernelSU Next</string>
|
||||
<string name="home">Home</string>
|
||||
<string name="home_not_installed">Not installed</string>
|
||||
@@ -23,6 +24,8 @@
|
||||
<string name="module_failed_to_disable">Failed to disable module: %s</string>
|
||||
<string name="module_empty">No module installed</string>
|
||||
<string name="module">Module</string>
|
||||
<string name="confirm_module_installation">Confirm Installation</string>
|
||||
<string name="module_install_prompt_with_name">Do you want to continue installing this module?\nModule: %1$s</string>
|
||||
<string name="uninstall">Uninstall</string>
|
||||
<string name="module_install">Install</string>
|
||||
<string name="install">Install</string>
|
||||
|
||||
Reference in New Issue
Block a user