Skip to content

A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.

feat(settings): re-section + Appearance group + button affordances

ExTv2216ce01d256
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt
index 0d7deb6..1665764 100644
--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt
+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt
@@ -5,10 +5,7 @@ import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.Settings
-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
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
@@ -19,37 +16,26 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
-import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
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.Add
import androidx.compose.material.icons.filled.Delete
-import androidx.compose.material.icons.filled.ExpandLess
-import androidx.compose.material.icons.filled.ExpandMore
-import androidx.compose.material.icons.filled.RestartAlt
-import androidx.compose.material.icons.filled.Share
-import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.AlertDialog
-import androidx.compose.material3.ButtonDefaults
-import androidx.compose.material3.Card
-import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.FilterChipDefaults
-import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
-import androidx.compose.material3.TopAppBar
+import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@@ -61,19 +47,26 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
-import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
-import androidx.compose.ui.unit.sp
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.excp.podroid.BuildConfig
import com.excp.podroid.data.repository.PortForwardRule
import com.excp.podroid.engine.VmState
import com.excp.podroid.ui.components.AdaptiveContainer
+import com.excp.podroid.ui.components.PodroidDestructiveButton
+import com.excp.podroid.ui.components.PodroidGhostButton
+import com.excp.podroid.ui.components.PodroidInlineAction
+import com.excp.podroid.ui.components.PodroidListRow
+import com.excp.podroid.ui.components.podroidChipColors
+import com.excp.podroid.ui.components.PodroidSectionLabel
+import com.excp.podroid.ui.components.PodroidSwitch
+import com.excp.podroid.ui.components.PodroidTopBar
+import com.excp.podroid.ui.theme.PodroidTokens
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -83,33 +76,19 @@ fun SettingsScreen(
onThemeOrFontChanged: () -> Unit = {},
viewModel: SettingsViewModel = hiltViewModel(),
) {
- // 8 form-style rows in one subscription via combine(...) in the ViewModel —
- // single recomposition wave per emit instead of one per source flow.
val ui by viewModel.uiState.collectAsStateWithLifecycle()
- val darkTheme = ui.darkTheme
- val vmRamMb = ui.vmRamMb
- val vmCpus = ui.vmCpus
- val storageSizeGb = ui.storageSizeGb
- val sshEnabled = ui.sshEnabled
- val storageAccessEnabled = ui.storageAccessEnabled
- val qemuExtraArgs = ui.qemuExtraArgs
- val kernelExtraCmdline = ui.kernelExtraCmdline
- // Kept separate — different cadence/consumer than the form rows.
val portForwardRules by viewModel.portForwardRules.collectAsStateWithLifecycle()
val vmState by viewModel.vmState.collectAsStateWithLifecycle()
+
var advancedExpanded by remember { mutableStateOf(false) }
var showAddDialog by remember { mutableStateOf(false) }
var showResetDialog by remember { mutableStateOf(false) }
- val context = LocalContext.current
-
- val ramOptions = listOf(512, 1024, 2048, 4096)
- val cpuOptions = listOf(1, 2, 4, 6, 8)
val vmNotRunning = vmState !is VmState.Running && vmState !is VmState.Starting
Scaffold(
topBar = {
- TopAppBar(
- title = { Text("Settings") },
+ PodroidTopBar(
+ title = "Settings",
navigationIcon = {
IconButton(onClick = onNavigateBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
@@ -117,308 +96,145 @@ fun SettingsScreen(
},
)
},
+ containerColor = MaterialTheme.colorScheme.background,
) { innerPadding ->
+ val isCompactHeight = windowSizeClass.heightSizeClass == WindowHeightSizeClass.Compact
AdaptiveContainer(
windowSizeClass = windowSizeClass,
modifier = Modifier
.fillMaxSize()
- .padding(innerPadding)
+ .padding(innerPadding),
+ maxWidth = if (isCompactHeight) 900 else 600,
) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
- .padding(horizontal = 16.dp),
+ .padding(horizontal = PodroidTokens.Spacing.XL),
) {
- Spacer(Modifier.height(16.dp))
+ // ── APPEARANCE ────────────────────────────────────────
+ PodroidSectionLabel("Appearance")
+ PodroidListRow(
+ label = "Dark theme",
+ rightSlot = {
+ PodroidSwitch(
+ checked = ui.darkTheme,
+ onCheckedChange = {
+ viewModel.setDarkTheme(it)
+ onThemeOrFontChanged()
+ },
+ )
+ },
+ )
+ PodroidListRow(
+ label = "Dynamic color (Material You)",
+ rightSlot = {
+ PodroidSwitch(
+ checked = ui.dynamicColorEnabled,
+ onCheckedChange = {
+ viewModel.setDynamicColorEnabled(it)
+ onThemeOrFontChanged()
+ },
+ )
+ },
+ )
- // ── VM Resources ─────────────────────────────────────────
- SettingsSection(title = "VM Resources") {
+ // ── VM RESOURCES ──────────────────────────────────────
+ PodroidSectionLabel("VM Resources")
if (!vmNotRunning) {
Text(
text = "Stop the VM to change these settings.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.error,
- modifier = Modifier.padding(bottom = 8.dp),
+ modifier = Modifier.padding(top = PodroidTokens.Spacing.SM),
)
}
-
- Text("Memory", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
- Text("$vmRamMb MB", style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
- Spacer(Modifier.height(8.dp))
- ChipRow(
- options = ramOptions,
- selected = vmRamMb,
+ RamSection(
+ currentMb = ui.vmRamMb,
+ onChange = viewModel::setVmRamMb,
enabled = vmNotRunning,
- label = { ram -> if (ram >= 1024) "${ram / 1024} GB" else "$ram MB" },
- onSelect = { viewModel.setVmRamMb(it) },
)
-
- Spacer(Modifier.height(16.dp))
-
- Text("CPU cores", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
- Text("$vmCpus", style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
- Spacer(Modifier.height(8.dp))
- ChipRow(
- options = cpuOptions,
- selected = vmCpus,
+ CpusSection(
+ currentCpus = ui.vmCpus,
+ onChange = viewModel::setVmCpus,
enabled = vmNotRunning,
- label = { cpu -> "$cpu" },
- onSelect = { viewModel.setVmCpus(it) },
)
- }
-
- Spacer(Modifier.height(8.dp))
-
-
-
- Spacer(Modifier.height(4.dp))
-
- // ── Storage ───────────────────────────────────────────────
- SettingsSection(title = "Storage") {
- Text("Persistent storage", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
- Text("$storageSizeGb GB", style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
- Text(
- text = "Set during initial setup. Reset the VM to change.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(top = 2.dp, bottom = 12.dp),
+ PodroidListRow(
+ label = "Storage",
+ value = "${ui.storageSizeGb} GB",
)
- DownloadsSharingCard(
- enabled = storageAccessEnabled,
- vmNotRunning = vmNotRunning,
- onToggle = { viewModel.setStorageAccessEnabled(it) },
- )
- }
- Spacer(Modifier.height(8.dp))
-
- // ── Network ───────────────────────────────────────────────
- SettingsSection(title = "Network") {
- val phoneIp = viewModel.phoneIp
- Text(
- text = "Phone IP: $phoneIp",
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.primary,
- fontWeight = FontWeight.SemiBold,
+ // ── NETWORK ───────────────────────────────────────────
+ PodroidSectionLabel("Network")
+ PodroidListRow(
+ label = "Phone IP",
+ value = viewModel.phoneIp,
+ mono = true,
)
- Text(
- text = "Point your devices here to reach the VM.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(bottom = 12.dp),
- )
- SettingsSwitchRow(
- title = "Enable SSH",
- subtitle = if (sshEnabled) "ssh root@<phone-ip> -p 9922 | password: podroid" else "Access the VM over your local network via SSH",
- checked = sshEnabled,
- onCheckedChange = { viewModel.setSshEnabled(it) },
+ PodroidListRow(
+ label = "SSH (port 9922, password \"podroid\")",
+ rightSlot = {
+ PodroidSwitch(
+ checked = ui.sshEnabled,
+ onCheckedChange = { viewModel.setSshEnabled(it) },
+ enabled = vmNotRunning,
+ )
+ },
)
- Spacer(Modifier.height(8.dp))
- HorizontalDivider()
- Spacer(Modifier.height(12.dp))
- Text("Port forwards", style = MaterialTheme.typography.titleSmall, fontWeight = FontWeight.SemiBold)
- Text(
- text = "Forward ports from your Android device into the VM. Active immediately when VM is running.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(top = 2.dp, bottom = 8.dp),
+ PortForwardSection(
+ rules = portForwardRules,
+ onAdd = { showAddDialog = true },
+ onRemove = { viewModel.removePortForward(it) },
)
- if (portForwardRules.isEmpty()) {
- Text(
- text = "No rules configured.",
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(vertical = 8.dp),
- )
- } else {
- portForwardRules.forEach { rule ->
- key(rule.hostPort, rule.protocol) {
- PortForwardRuleRow(
- rule = rule,
- onDelete = { viewModel.removePortForward(rule) },
- )
- }
- }
- }
- Spacer(Modifier.height(8.dp))
- FilledTonalButton(
- onClick = { showAddDialog = true },
- modifier = Modifier.fillMaxWidth(),
- shape = RoundedCornerShape(14.dp),
- ) {
- Icon(Icons.Default.Add, contentDescription = null)
- Spacer(Modifier.width(8.dp))
- Text("Add Port Forward")
- }
- if (vmState is VmState.Running) {
- Text(
- text = "VM is running — new rules take effect immediately.",
- style = MaterialTheme.typography.labelSmall,
- color = MaterialTheme.colorScheme.primary,
- modifier = Modifier.padding(top = 6.dp),
- )
- }
- }
-
- Spacer(Modifier.height(8.dp))
-
- // ── Appearance ────────────────────────────────────────────
- SettingsSection(title = "Appearance") {
- SettingsSwitchRow(
- title = "Dark theme",
- subtitle = "Use a dark color scheme",
- checked = darkTheme,
- onCheckedChange = { viewModel.setDarkTheme(it) },
- )
- }
-
- Spacer(Modifier.height(8.dp))
-
- // ── Diagnostics ───────────────────────────────────────────
- SettingsSection(title = "Diagnostics") {
- FilledTonalButton(
- onClick = { viewModel.exportConsoleLogs() },
- modifier = Modifier.fillMaxWidth(),
- shape = RoundedCornerShape(14.dp),
- ) {
- Icon(Icons.Default.Share, contentDescription = null)
- Spacer(Modifier.width(8.dp))
- Text("Export Diagnostic Log")
- }
- Text(
- text = "Shares log.txt with app info, settings, VM state, app logcat, and QEMU console output. Attach this when reporting bugs.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- modifier = Modifier.padding(top = 8.dp),
+ // ── STORAGE / SHARING ─────────────────────────────────
+ PodroidSectionLabel("Storage")
+ DownloadsSharingRow(
+ enabled = ui.storageAccessEnabled,
+ vmNotRunning = vmNotRunning,
+ onToggle = { viewModel.setStorageAccessEnabled(it) },
)
-
- Spacer(Modifier.height(12.dp))
-
- FilledTonalButton(
+ Spacer(Modifier.height(PodroidTokens.Spacing.MD))
+ PodroidDestructiveButton(
+ text = "Reset VM (deletes all data)",
onClick = { showResetDialog = true },
- enabled = vmNotRunning,
- modifier = Modifier.fillMaxWidth(),
- shape = RoundedCornerShape(14.dp),
- colors = ButtonDefaults.filledTonalButtonColors(
- containerColor = MaterialTheme.colorScheme.errorContainer,
- contentColor = MaterialTheme.colorScheme.onErrorContainer,
- ),
- ) {
- Icon(Icons.Default.RestartAlt, contentDescription = null)
- Spacer(Modifier.width(8.dp))
- Text("Full App Reset")
- }
- if (!vmNotRunning) {
- Text(
- text = "Stop the VM before resetting.",
- style = MaterialTheme.typography.labelSmall,
- color = MaterialTheme.colorScheme.error,
- modifier = Modifier.padding(top = 6.dp),
- )
- }
- }
-
- Spacer(Modifier.height(8.dp))
-
- // ── Advanced QEMU ─────────────────────────────────────────
- Row(
- modifier = Modifier
- .fillMaxWidth()
- .clickable { advancedExpanded = !advancedExpanded }
- .padding(vertical = 8.dp),
- verticalAlignment = Alignment.CenterVertically,
- ) {
- Text(
- text = "Advanced QEMU",
- style = MaterialTheme.typography.titleMedium,
- fontWeight = FontWeight.Bold,
- modifier = Modifier.weight(1f),
- )
- Icon(
- imageVector = if (advancedExpanded) Icons.Default.ExpandLess else Icons.Default.ExpandMore,
- contentDescription = if (advancedExpanded) "Collapse" else "Expand",
)
- }
- if (advancedExpanded) {
- Card(
- modifier = Modifier
- .fillMaxWidth()
- .padding(bottom = 8.dp),
- colors = CardDefaults.cardColors(
- containerColor = MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.4f),
- ),
- ) {
- Row(
- modifier = Modifier.padding(12.dp),
- verticalAlignment = Alignment.Top,
- ) {
- Icon(
- Icons.Default.Warning,
- contentDescription = null,
- tint = MaterialTheme.colorScheme.error,
- modifier = Modifier.padding(end = 8.dp, top = 2.dp),
- )
- Text(
- text = "Editing these may prevent the VM from booting. " +
- "RAM, CPU count, sockets, storage, and networking are " +
- "managed by the app and not exposed here. Use Reset if " +
- "the VM stops booting.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onErrorContainer,
- )
- }
- }
-
- if (!vmNotRunning) {
- Text(
- text = "Stop the VM before editing — changes apply on next boot.",
- style = MaterialTheme.typography.labelSmall,
- color = MaterialTheme.colorScheme.error,
- modifier = Modifier.padding(bottom = 8.dp),
+ // ── ADVANCED ──────────────────────────────────────────
+ PodroidSectionLabel("Advanced")
+ Spacer(Modifier.height(PodroidTokens.Spacing.SM))
+ PodroidGhostButton(
+ text = if (advancedExpanded) "Hide advanced" else "Show advanced",
+ onClick = { advancedExpanded = !advancedExpanded },
+ )
+ if (advancedExpanded) {
+ AdvancedFieldsBlock(
+ qemuExtraArgs = ui.qemuExtraArgs,
+ kernelExtraCmdline = ui.kernelExtraCmdline,
+ onQemuChange = viewModel::setQemuExtraArgs,
+ onKernelChange = viewModel::setKernelExtraCmdline,
+ onQemuReset = viewModel::resetQemuExtraArgs,
+ onKernelReset = viewModel::resetKernelExtraCmdline,
+ enabled = vmNotRunning,
)
}
- AdvancedTextSetting(
- label = "Extra QEMU args",
- helper = "-cpu, -accel, -object, -device, -overcommit, etc. Whitespace-separated.",
- value = qemuExtraArgs,
- enabled = vmNotRunning,
- onValueChange = viewModel::setQemuExtraArgs,
- onReset = viewModel::resetQemuExtraArgs,
- minLines = 4,
- )
-
- Spacer(Modifier.height(12.dp))
-
- AdvancedTextSetting(
- label = "Extra kernel cmdline",
- helper = "Appended after console=ttyAMA0 — controls scheduler, mitigations, log level, etc.",
- value = kernelExtraCmdline,
- enabled = vmNotRunning,
- onValueChange = viewModel::setKernelExtraCmdline,
- onReset = viewModel::resetKernelExtraCmdline,
- minLines = 2,
+ // ── ABOUT ─────────────────────────────────────────────
+ PodroidSectionLabel("About")
+ PodroidListRow(label = "Version", value = "v${BuildConfig.VERSION_NAME}", mono = true)
+ PodroidListRow(label = "QEMU", value = "v${BuildConfig.QEMU_VERSION}", mono = true)
+ PodroidListRow(label = "Architecture", value = "AArch64", mono = true)
+ PodroidListRow(label = "Linux distro", value = "Alpine 3.23", mono = true)
+ Spacer(Modifier.height(PodroidTokens.Spacing.MD))
+ PodroidGhostButton(
+ text = "Export diagnostic log",
+ onClick = { viewModel.exportConsoleLogs() },
)
- Spacer(Modifier.height(16.dp))
+ Spacer(Modifier.height(PodroidTokens.Spacing.XL2))
}
-
- // ── About ─────────────────────────────────────────────────
- SettingsSection(title = "About") {
- SettingsInfoRow("Version", BuildConfig.VERSION_NAME)
- SettingsInfoRow("QEMU", BuildConfig.QEMU_VERSION)
- SettingsInfoRow("Architecture", "AArch64 (ARM64)")
- SettingsInfoRow("Linux distro", "Alpine Linux 3.23")
- SettingsInfoRow("Storage", "$storageSizeGb GB persistent overlay")
- }
-
- Spacer(Modifier.height(32.dp))
}
}
-}
if (showAddDialog) {
AddPortForwardDialog(
@@ -437,8 +253,8 @@ fun SettingsScreen(
text = {
Text(
"This will clear ALL application data, including your VM storage, " +
- "settings, and port rules. The app will close and return to a " +
- "freshly-installed state."
+ "settings, and port rules. The app will close and return to a " +
+ "freshly-installed state."
)
},
confirmButton = {
@@ -458,45 +274,207 @@ fun SettingsScreen(
}
}
+@OptIn(ExperimentalLayoutApi::class)
@Composable
-private fun PortForwardRuleRow(rule: PortForwardRule, onDelete: () -> Unit) {
- Card(
- modifier = Modifier
- .fillMaxWidth()
- .padding(vertical = 4.dp),
- colors = CardDefaults.cardColors(
- containerColor = MaterialTheme.colorScheme.surfaceVariant,
- ),
- ) {
- Row(
- modifier = Modifier
- .fillMaxWidth()
- .padding(horizontal = 16.dp, vertical = 8.dp),
- verticalAlignment = Alignment.CenterVertically,
+private fun RamSection(currentMb: Int, onChange: (Int) -> Unit, enabled: Boolean) {
+ Column(modifier = Modifier.padding(bottom = PodroidTokens.Spacing.SM)) {
+ Text(
+ "RAM · ${if (currentMb >= 1024) "${currentMb / 1024} GB" else "$currentMb MB"}",
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurface,
+ modifier = Modifier.padding(
+ top = PodroidTokens.Spacing.MD,
+ bottom = PodroidTokens.Spacing.SM,
+ ),
+ )
+ FlowRow(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(PodroidTokens.Spacing.SM),
+ verticalArrangement = Arrangement.spacedBy(PodroidTokens.Spacing.SM),
) {
- Column(modifier = Modifier.weight(1f)) {
- Text(
- text = "localhost:${rule.hostPort} → VM:${rule.guestPort}",
- style = MaterialTheme.typography.bodyMedium,
- fontWeight = FontWeight.Medium,
+ listOf(512, 1024, 2048, 4096).forEach { mb ->
+ FilterChip(
+ selected = mb == currentMb,
+ enabled = enabled,
+ onClick = { onChange(mb) },
+ label = { Text(if (mb >= 1024) "${mb / 1024} GB" else "$mb MB") },
+ shape = RoundedCornerShape(PodroidTokens.Radius.Chip),
+ colors = podroidChipColors(),
)
- Text(
- text = rule.protocol.uppercase(),
- style = MaterialTheme.typography.labelSmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
+ }
+ }
+ HorizontalDivider(
+ color = MaterialTheme.colorScheme.outline,
+ thickness = 1.dp,
+ modifier = Modifier.padding(top = PodroidTokens.Spacing.MD),
+ )
+ }
+}
+
+@OptIn(ExperimentalLayoutApi::class)
+@Composable
+private fun CpusSection(currentCpus: Int, onChange: (Int) -> Unit, enabled: Boolean) {
+ Column(modifier = Modifier.padding(bottom = PodroidTokens.Spacing.SM)) {
+ Text(
+ "CPU cores · $currentCpus",
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurface,
+ modifier = Modifier.padding(
+ top = PodroidTokens.Spacing.MD,
+ bottom = PodroidTokens.Spacing.SM,
+ ),
+ )
+ FlowRow(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(PodroidTokens.Spacing.SM),
+ verticalArrangement = Arrangement.spacedBy(PodroidTokens.Spacing.SM),
+ ) {
+ listOf(1, 2, 4, 6, 8).forEach { n ->
+ FilterChip(
+ selected = n == currentCpus,
+ enabled = enabled,
+ onClick = { onChange(n) },
+ label = { Text("$n") },
+ shape = RoundedCornerShape(PodroidTokens.Radius.Chip),
+ colors = podroidChipColors(),
)
}
- IconButton(onClick = onDelete) {
- Icon(
- Icons.Default.Delete,
- contentDescription = "Remove rule",
- tint = MaterialTheme.colorScheme.error,
+ }
+ HorizontalDivider(
+ color = MaterialTheme.colorScheme.outline,
+ thickness = 1.dp,
+ modifier = Modifier.padding(top = PodroidTokens.Spacing.MD),
+ )
+ }
+}
+
+@Composable
+private fun PortForwardSection(
+ rules: List<PortForwardRule>,
+ onAdd: () -> Unit,
+ onRemove: (PortForwardRule) -> Unit,
+) {
+ PodroidListRow(
+ label = "Port forwards (${rules.size})",
+ rightSlot = { PodroidInlineAction(label = "+ Add", onClick = onAdd) },
+ )
+ rules.forEach { rule ->
+ key(rule.hostPort, rule.protocol) {
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(vertical = PodroidTokens.Spacing.SM),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.SpaceBetween,
+ ) {
+ Text(
+ text = "${rule.hostPort} → ${rule.guestPort} (${rule.protocol})",
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
+ fontFamily = PodroidTokens.mono(),
+ modifier = Modifier.weight(1f),
)
+ IconButton(onClick = { onRemove(rule) }) {
+ Icon(
+ Icons.Default.Delete,
+ contentDescription = "Remove",
+ tint = MaterialTheme.colorScheme.error,
+ )
+ }
}
+ HorizontalDivider(
+ color = MaterialTheme.colorScheme.outline,
+ thickness = 1.dp,
+ )
}
}
}
+/**
+ * Mirrors the setup wizard's storage-access toggle: turn it on and, if needed,
+ * jump straight to the system MANAGE_EXTERNAL_STORAGE grant screen.
+ */
+@Composable
+private fun DownloadsSharingRow(
+ enabled: Boolean,
+ vmNotRunning: Boolean,
+ onToggle: (Boolean) -> Unit,
+) {
+ val context = LocalContext.current
+ val canManageAllFiles = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
+
+ @androidx.annotation.RequiresApi(Build.VERSION_CODES.R)
+ fun openAllFilesAccessSettings() {
+ context.startActivity(
+ Intent(
+ Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
+ Uri.parse("package:${context.packageName}"),
+ )
+ )
+ }
+
+ PodroidListRow(
+ label = "Downloads sharing",
+ rightSlot = {
+ PodroidSwitch(
+ checked = enabled,
+ onCheckedChange = { checked ->
+ onToggle(checked)
+ if (checked && canManageAllFiles && !Environment.isExternalStorageManager()) {
+ openAllFilesAccessSettings()
+ }
+ },
+ enabled = vmNotRunning,
+ )
+ },
+ )
+}
+
+@Composable
+private fun AdvancedFieldsBlock(
+ qemuExtraArgs: String,
+ kernelExtraCmdline: String,
+ onQemuChange: (String) -> Unit,
+ onKernelChange: (String) -> Unit,
+ onQemuReset: () -> Unit,
+ onKernelReset: () -> Unit,
+ enabled: Boolean,
+) {
+ Column(
+ verticalArrangement = Arrangement.spacedBy(PodroidTokens.Spacing.MD),
+ modifier = Modifier.padding(
+ top = PodroidTokens.Spacing.SM,
+ bottom = PodroidTokens.Spacing.MD,
+ ),
+ ) {
+ if (!enabled) {
+ Text(
+ text = "Stop the VM before editing — changes apply on next boot.",
+ style = MaterialTheme.typography.labelSmall,
+ color = MaterialTheme.colorScheme.error,
+ )
+ }
+ AdvancedTextSetting(
+ label = "Extra QEMU args",
+ helper = "-cpu, -accel, -object, -device, -overcommit, etc. Whitespace-separated.",
+ value = qemuExtraArgs,
+ enabled = enabled,
+ onValueChange = onQemuChange,
+ onReset = onQemuReset,
+ minLines = 4,
+ )
+ AdvancedTextSetting(
+ label = "Extra kernel cmdline",
+ helper = "Appended after console=ttyAMA0 — controls scheduler, mitigations, log level, etc.",
+ value = kernelExtraCmdline,
+ enabled = enabled,
+ onValueChange = onKernelChange,
+ onReset = onKernelReset,
+ minLines = 2,
+ )
+ }
+}
+
@Composable
private fun AddPortForwardDialog(
onDismiss: () -> Unit,
@@ -535,7 +513,14 @@ private fun AddPortForwardDialog(
FilterChip(
selected = protocol == proto,
onClick = { protocol = proto },
- label = { Text(proto.uppercase(), style = MaterialTheme.typography.labelSmall) },
+ label = {
+ Text(
+ proto.uppercase(),
+ style = MaterialTheme.typography.labelSmall,
+ )
+ },
+ shape = RoundedCornerShape(PodroidTokens.Radius.Chip),
+ colors = podroidChipColors(),
)
}
}
@@ -567,229 +552,6 @@ private fun AddPortForwardDialog(
)
}
-@Composable
-private fun SettingsSectionHeader(title: String) {
- Column {
- Text(
- text = title,
- style = MaterialTheme.typography.labelLarge,
- color = MaterialTheme.colorScheme.primary,
- modifier = Modifier.padding(top = 16.dp, bottom = 4.dp),
- )
- HorizontalDivider()
- Spacer(Modifier.height(8.dp))
- }
-}
-
-/** Card-grouped section: header above + a surface-tinted card around the content. */
-@Composable
-private fun SettingsSection(
- title: String,
- content: @Composable () -> Unit,
-) {
- Text(
- text = title.uppercase(),
- style = MaterialTheme.typography.labelMedium,
- color = MaterialTheme.colorScheme.primary,
- fontWeight = FontWeight.SemiBold,
- modifier = Modifier.padding(start = 4.dp, top = 12.dp, bottom = 8.dp),
- )
- Card(
- modifier = Modifier.fillMaxWidth(),
- shape = RoundedCornerShape(20.dp),
- colors = CardDefaults.cardColors(
- containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.4f),
- ),
- ) {
- Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 16.dp)) {
- content()
- }
- }
-}
-
-/** Row of FilterChips for picking one value out of a list (RAM, CPUs, etc.). */
-@OptIn(ExperimentalLayoutApi::class)
-@Composable
-private fun <T> ChipRow(
- options: List<T>,
- selected: T,
- enabled: Boolean,
- label: (T) -> String,
- onSelect: (T) -> Unit,
-) {
- FlowRow(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- verticalArrangement = Arrangement.spacedBy(8.dp),
- ) {
- options.forEach { option ->
- FilterChip(
- selected = option == selected,
- enabled = enabled,
- onClick = { onSelect(option) },
- label = {
- Text(
- text = label(option),
- style = MaterialTheme.typography.labelLarge,
- fontWeight = if (option == selected) FontWeight.Bold else FontWeight.Normal,
- )
- },
- shape = RoundedCornerShape(14.dp),
- colors = FilterChipDefaults.filterChipColors(
- selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
- selectedLabelColor = MaterialTheme.colorScheme.onPrimaryContainer,
- ),
- )
- }
- }
-}
-
-@Composable
-private fun SettingsSwitchRow(
- title: String,
- subtitle: String,
- checked: Boolean,
- onCheckedChange: (Boolean) -> Unit,
-) {
- Row(
- modifier = Modifier
- .fillMaxWidth()
- .padding(vertical = 6.dp),
- verticalAlignment = Alignment.CenterVertically,
- ) {
- Column(modifier = Modifier.weight(1f)) {
- Text(title, style = MaterialTheme.typography.bodyMedium)
- Text(
- subtitle,
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
- Switch(checked = checked, onCheckedChange = onCheckedChange)
- }
-}
-
-@Composable
-private fun SettingsInfoRow(label: String, value: String) {
- Row(
- modifier = Modifier
- .fillMaxWidth()
- .padding(vertical = 8.dp),
- verticalAlignment = Alignment.CenterVertically,
- ) {
- Text(
- text = label,
- style = MaterialTheme.typography.bodyMedium,
- modifier = Modifier.weight(1f),
- )
- Text(
- text = value,
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
-}
-
-/**
- * Mirrors the setup-wizard's storage-access card: toggle, "may crash the VM"
- * warning, and a permission-grant button when MANAGE_EXTERNAL_STORAGE isn't held.
- */
-@Composable
-private fun DownloadsSharingCard(
- enabled: Boolean,
- vmNotRunning: Boolean,
- onToggle: (Boolean) -> Unit,
-) {
- val context = LocalContext.current
- val canManageAllFiles = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
- val hasStoragePermission = !canManageAllFiles || Environment.isExternalStorageManager()
-
- fun openAllFilesAccessSettings() {
- context.startActivity(
- Intent(
- Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
- Uri.parse("package:${context.packageName}"),
- )
- )
- }
-
- Card(
- modifier = Modifier.fillMaxWidth(),
- colors = CardDefaults.cardColors(
- containerColor = MaterialTheme.colorScheme.surfaceVariant,
- ),
- ) {
- Column(modifier = Modifier.padding(16.dp)) {
- Row(
- modifier = Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.SpaceBetween,
- verticalAlignment = Alignment.CenterVertically,
- ) {
- Column(modifier = Modifier.weight(1f)) {
- Text(
- text = "Downloads sharing",
- style = MaterialTheme.typography.titleMedium,
- fontWeight = FontWeight.SemiBold,
- )
- Spacer(Modifier.height(4.dp))
- Text(
- text = if (enabled)
- "Mounted as /mnt/downloads in the VM via virtio-9p."
- else
- "Share the Android Downloads folder with the VM.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
- Spacer(Modifier.width(12.dp))
- Switch(
- checked = enabled,
- onCheckedChange = { checked ->
- onToggle(checked)
- // Mirror SetupScreen behavior: when the user enables sharing
- // and we're on R+ without MANAGE_EXTERNAL_STORAGE held, jump
- // straight to the system grant screen so they can flip it.
- if (checked && canManageAllFiles && !Environment.isExternalStorageManager()) {
- openAllFilesAccessSettings()
- }
- },
- )
- }
-
- Spacer(Modifier.height(12.dp))
- Text(
- text = "On some devices this may crash the VM.",
- style = MaterialTheme.typography.bodyMedium,
- color = MaterialTheme.colorScheme.error,
- fontWeight = FontWeight.SemiBold,
- )
-
- if (enabled && canManageAllFiles && !hasStoragePermission) {
- Spacer(Modifier.height(12.dp))
- FilledTonalButton(onClick = ::openAllFilesAccessSettings) {
- Text("Grant storage access")
- }
- } else if (enabled && canManageAllFiles) {
- Spacer(Modifier.height(8.dp))
- Text(
- text = if (hasStoragePermission) "All files access granted." else "All files access not granted.",
- style = MaterialTheme.typography.bodySmall,
- color = MaterialTheme.colorScheme.onSurfaceVariant,
- )
- }
-
- if (!vmNotRunning) {
- Spacer(Modifier.height(8.dp))
- Text(
- text = "Restart the VM for changes to take effect.",
- style = MaterialTheme.typography.labelSmall,
- color = MaterialTheme.colorScheme.error,
- )
- }
- }
- }
-}
-
@Composable
private fun AdvancedTextSetting(
label: String,
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt
index a47a9a4..4e74932 100644
--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt
+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt
@@ -51,6 +51,7 @@ data class SettingsUiState(
val qemuExtraArgs: String = SettingsRepository.DEFAULT_QEMU_EXTRA_ARGS,
val kernelExtraCmdline: String = SettingsRepository.DEFAULT_KERNEL_EXTRA_CMDLINE,
val darkTheme: Boolean = false,
+ val dynamicColorEnabled: Boolean = false,
)
@HiltViewModel
@@ -105,8 +106,9 @@ class SettingsViewModel @Inject constructor(
settingsRepository.qemuExtraArgs,
settingsRepository.kernelExtraCmdline,
settingsRepository.darkTheme,
- ) { storageAccess, qemu, kernel, dark ->
- arrayOf(storageAccess, qemu, kernel, dark)
+ settingsRepository.dynamicColorEnabled,
+ ) { storageAccess, qemu, kernel, dark, dyn ->
+ arrayOf(storageAccess, qemu, kernel, dark, dyn)
},
) { a, b ->
SettingsUiState(
@@ -118,6 +120,7 @@ class SettingsViewModel @Inject constructor(
qemuExtraArgs = b[1] as String,
kernelExtraCmdline = b[2] as String,
darkTheme = b[3] as Boolean,
+ dynamicColorEnabled = b[4] as Boolean,
)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), SettingsUiState())
@@ -162,6 +165,10 @@ class SettingsViewModel @Inject constructor(
viewModelScope.launch { settingsRepository.setDarkTheme(value) }
}
+ fun setDynamicColorEnabled(value: Boolean) {
+ viewModelScope.launch { settingsRepository.setDynamicColorEnabled(value) }
+ }
+
fun setVmRamMb(value: Int) {
viewModelScope.launch { settingsRepository.setVmRamMb(value) }
}
@@ -213,13 +220,7 @@ class SettingsViewModel @Inject constructor(
fun resetVm() {
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as android.app.ActivityManager
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- activityManager.clearApplicationUserData()
- } else {
- // Fallback for extremely old devices (not applicable here but for completeness)
- val storageFile = File(context.filesDir, "storage.img")
- if (storageFile.exists()) storageFile.delete()
- }
+ activityManager.clearApplicationUserData()
}
/**