tap to request for root from mainscreen
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
package sh.sar.isodroid.ui.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -52,7 +53,9 @@ fun StatusCard(
|
||||
mountStatus: MountStatus,
|
||||
rootAvailable: Boolean?,
|
||||
deviceSupported: Boolean?,
|
||||
modifier: Modifier = Modifier
|
||||
rootDenied: Boolean = false,
|
||||
modifier: Modifier = Modifier,
|
||||
onRequestRoot: (() -> Unit)? = null
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
@@ -73,7 +76,15 @@ fun StatusCard(
|
||||
val isImg = fileName?.lowercase()?.endsWith(".img") == true
|
||||
|
||||
Card(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.then(
|
||||
if (showRootError && onRequestRoot != null) {
|
||||
Modifier.clickable(onClick = onRequestRoot)
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = when {
|
||||
hasError -> MaterialTheme.colorScheme.errorContainer
|
||||
@@ -121,7 +132,7 @@ fun StatusCard(
|
||||
)
|
||||
if (showRootError) {
|
||||
Text(
|
||||
text = "Grant root access to use ISODroid",
|
||||
text = if (rootDenied) "Grant root access to use ISO Droid" else "Tap to grant root access",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
|
||||
@@ -27,7 +27,6 @@ import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -157,7 +156,9 @@ fun MainScreen(
|
||||
StatusCard(
|
||||
mountStatus = uiState.mountStatus,
|
||||
rootAvailable = uiState.hasRoot,
|
||||
deviceSupported = uiState.isSupported
|
||||
deviceSupported = uiState.isSupported,
|
||||
rootDenied = uiState.rootDenied,
|
||||
onRequestRoot = { viewModel.requestRootAccess() }
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
@@ -184,31 +185,6 @@ fun MainScreen(
|
||||
canNavigateUp = viewModel.canNavigateUp(),
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
} else if (uiState.hasRoot != true) {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = "Root Access Required",
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(
|
||||
text = "Grant root access to use ISO Droid",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
TextButton(onClick = { viewModel.requestRootAccess() }) {
|
||||
Text("Grant Root Access")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user