manager: ui state for safemode

This commit is contained in:
tiann
2023-02-13 22:41:32 +08:00
parent 42428345ff
commit 55602f1f16
12 changed files with 59 additions and 25 deletions

View File

@@ -21,4 +21,6 @@ public final class Natives {
public static native int[] getDenyList();
public static native boolean allowRoot(int uid, boolean allow);
public static native boolean isSafeMode();
}

View File

@@ -52,36 +52,42 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
}
}
val isSafeMode = Natives.isSafeMode()
Scaffold(
topBar = {
TopBar()
},
floatingActionButton = {
val moduleInstall = stringResource(id = R.string.module_install)
val selectZipLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) {
if (it.resultCode != RESULT_OK) {
return@rememberLauncherForActivityResult
floatingActionButton = if (isSafeMode) {
{ /* Empty */ }
} else {
{
val moduleInstall = stringResource(id = R.string.module_install)
val selectZipLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) {
if (it.resultCode != RESULT_OK) {
return@rememberLauncherForActivityResult
}
val data = it.data ?: return@rememberLauncherForActivityResult
val uri = data.data ?: return@rememberLauncherForActivityResult
navigator.navigate(InstallScreenDestination(uri))
Log.i("ModuleScreen", "select zip result: ${it.data}")
}
val data = it.data ?: return@rememberLauncherForActivityResult
val uri = data.data ?: return@rememberLauncherForActivityResult
navigator.navigate(InstallScreenDestination(uri))
Log.i("ModuleScreen", "select zip result: ${it.data}")
ExtendedFloatingActionButton(
onClick = {
// select the zip file to install
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "application/zip"
selectZipLauncher.launch(intent)
},
icon = { Icon(Icons.Filled.Add, moduleInstall) },
text = { Text(text = moduleInstall) },
)
}
ExtendedFloatingActionButton(
onClick = {
// select the zip file to install
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "application/zip"
selectZipLauncher.launch(intent)
},
icon = { Icon(Icons.Filled.Add, moduleInstall) },
text = { Text(text = moduleInstall) },
)
}
) { innerPadding ->
val failedEnable = stringResource(R.string.module_failed_to_enable)
@@ -96,6 +102,12 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
}
return@Scaffold
}
if (isSafeMode) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(stringResource(R.string.safe_mode_disable_module))
}
return@Scaffold
}
SwipeRefresh(
state = swipeState,
onRefresh = {
@@ -123,7 +135,7 @@ fun ModuleScreen(navigator: DestinationsNavigator) {
} else {
LazyColumn(
verticalArrangement = Arrangement.spacedBy(15.dp),
contentPadding = remember { PaddingValues(bottom = 16.dp + 56.dp /* Scaffold Fab Spacing + Fab container height */ ) }
contentPadding = remember { PaddingValues(bottom = 16.dp + 56.dp /* Scaffold Fab Spacing + Fab container height */) }
) {
items(viewModel.moduleList) { module ->
var isChecked by rememberSaveable(module) { mutableStateOf(module.enabled) }