Settings as a menu of pages

Settings was one long page (the line, the modem, the bridges, fax,
dial-up, appearance, the terminal, SSH keys, Linux). Now a menu: a row
for each, what it's set to beneath (the line's account or kind, the
modem's country, speaker and answering); each its own page with its
title and a back arrow. Back from a page: the menu; from the menu: Home.
The Settings tab again from within: the menu. Home's Set up SIP and its
line card open the line's page, its ISP settings the dial-up page.

The line's and the modem's settings keep one set of edits across their
two pages and a Save on each ("Not saved yet" until then, the menu's
line row too).

BackNavigationTest: the menu, a page and back, Set up SIP to the line's
page, the tab back to the menu. The UI tests that used Settings open
their page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
Claude committed 2026-10-25 06:59:34 +00:00
1 parent 42a50110ee
commit 66efb03f7e
8 files changed
+235 -85

No files matched your search

@@ -129,7 +129,7 @@ fun DashboardScreen(
onStop = { ModemService.stop(context) },
onHangUp = { scope.launch { Terminal.session.hangUp(status.link == NativeModem.Link.ONLINE) } },
onTerminal = onOpenTerminal,
onSetUp = onOpenSettings,
onSetUp = { SettingsNav.open(SettingsPage.LINE); onOpenSettings() },
onStartNoLine = {
scope.launch {
SettingsStore(context).save(settings.copy(line = ModemSettings.LINE_NONE))
@@ -140,7 +140,7 @@ fun DashboardScreen(
if (appearance != null && !lightsOnTop) ModemLights()
LineCard(settings, run, network, onOpenSettings)
LineCard(settings, run, network) { SettingsNav.open(SettingsPage.LINE); onOpenSettings() }
SectionTitle("Quick dial", action = "Directory", onAction = onOpenDirectory)
val recent = entries.sortedWith(compareByDescending<DialEntry> { it.lastDialed }.thenBy { it.name }).take(4)
@@ -167,7 +167,7 @@ fun DashboardScreen(
}
SectionTitle("Internet")
InternetCard(onSetUp = onOpenSettings)
InternetCard(onSetUp = { SettingsNav.open(SettingsPage.INTERNET); onOpenSettings() })
SectionTitle("Fax")
FaxSection()
@@ -52,6 +52,8 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// (a fresh start: Settings at its menu)
if (savedInstanceState == null) SettingsNav.open(null)
enableEdgeToEdge()
// notifications, and the LAN (a SIP server, an SSH host, a bridge's client there: Android 17 asks)
val wanted = buildList {
@@ -127,7 +129,11 @@ class MainActivity : ComponentActivity() {
Item(tab == TAB_MODEM, "Home", { Icon(Icons.Filled.Home, null) }) { tab = TAB_MODEM }
Item(tab == TAB_TERMINAL, "Terminal", { Text(">_") }) { tab = TAB_TERMINAL }
Item(tab == TAB_DIRECTORY, "Dial", { Icon(Icons.Filled.Call, null) }) { tab = TAB_DIRECTORY }
Item(tab == TAB_SETTINGS, "Settings", { Icon(Icons.Filled.Settings, null) }) { tab = TAB_SETTINGS }
Item(tab == TAB_SETTINGS, "Settings", { Icon(Icons.Filled.Settings, null) }) {
// (Settings again from within it: its menu)
if (tab == TAB_SETTINGS) SettingsNav.open(null)
tab = TAB_SETTINGS
}
Item(tab == TAB_LOG, "Log", { Icon(Icons.AutoMirrored.Filled.List, null) }) { tab = TAB_LOG }
}
}
@@ -13,6 +13,7 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.heightIn
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.AlertDialog
@@ -43,115 +44,207 @@ import com.neodesktop.dmodem.settings.ModemSettings
import com.neodesktop.dmodem.settings.SettingsStore
import kotlinx.coroutines.launch
/** The SIP account and the modem's options; they apply when the modem next starts. */
/** Settings' pages: the menu's rows, each a page of its own. */
enum class SettingsPage(val title: String) {
LINE("Line"),
MODEM("Modem"),
BRIDGES("Serial bridges"),
FAX("Fax"),
INTERNET("Dial-up internet"),
APPEARANCE("Appearance"),
TERMINAL("Terminal"),
SSH("SSH keys"),
LINUX("Linux"),
}
/** which settings page is open (null: the menu); Home's buttons open theirs */
object SettingsNav {
val page = kotlinx.coroutines.flow.MutableStateFlow<SettingsPage?>(null)
fun open(p: SettingsPage?) {
page.value = p
}
}
/**
* Settings: a menu of its pages (the line, the modem, the bridges, fax,
* dial-up, appearance, the terminal, SSH keys, Linux), each with what it
* is set to; back from a page to the menu. The line's and the modem's
* settings are saved with their Save button, and apply when the modem next
* starts; their edits are kept across the two pages until then.
*/
@Composable
fun SettingsScreen(modifier: Modifier = Modifier, onOpenTerminal: () -> Unit = {}) {
val context = LocalContext.current
val store = remember { SettingsStore(context.applicationContext) }
val scope = rememberCoroutineScope()
val run by ModemState.run.collectAsStateWithLifecycle()
val page by SettingsNav.page.collectAsStateWithLifecycle()
var loaded by remember { mutableStateOf<ModemSettings?>(null) }
LaunchedEffect(Unit) { loaded = store.current() }
val initial = loaded ?: return
var s by remember(initial) { mutableStateOf(initial) }
var savedAs by remember(initial) { mutableStateOf(initial) }
var login by remember { mutableStateOf("") }
var saved by remember { mutableStateOf(false) }
Column(
modifier.fillMaxSize().padding(16.dp).verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
LineChoice(s) { s = it }
if (s.peer) {
PeerLineFields(s) { s = it }
} else if (s.usb) {
UsbLineFields()
} else {
Text("SIP account (saved with the button below)", style = MaterialTheme.typography.titleSmall)
OutlinedTextField(
value = login,
onValueChange = { v ->
login = v
ModemSettings.parseLogin(v.trim())?.let { (u, p, d) ->
s = s.copy(user = u, password = p, domain = d)
}
},
label = { Text("Paste user:password@host (optional)") },
singleLine = true,
modifier = Modifier.fillMaxWidth(),
)
Field("User", s.user) { s = s.copy(user = it) }
OutlinedTextField(
value = s.password,
onValueChange = { s = s.copy(password = it) },
label = { Text("Password") },
singleLine = true,
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
modifier = Modifier.fillMaxWidth(),
)
Field("Server (host[:port])", s.domain) { s = s.copy(domain = it) }
NumberField("Local SIP port", s.sipPort) { s = s.copy(sipPort = it) }
Toggle("Take incoming calls (register)", s.listen) { s = s.copy(listen = it) }
Toggle("Fax over T.38", s.t38) { s = s.copy(t38 = it) }
}
// back: a page to the menu (the menu's own back is the app's: Home)
androidx.activity.compose.BackHandler(enabled = page != null) { SettingsNav.open(null) }
Text("Modem", style = MaterialTheme.typography.titleMedium)
Toggle("Speaker: hear the dialling and the handshake", s.speaker) { s = s.copy(speaker = it) }
Toggle("Fax or data, as each call turns out", s.adaptiveAnswer) { s = s.copy(adaptiveAnswer = it) }
Text(
"A call answered (ATA) is a fax machine's or a modem's by what it sends (adaptive answer, AT+FAA=1): " +
"a fax goes to the fax receiver by itself, a modem's call to the terminal.",
style = MaterialTheme.typography.bodySmall,
)
Text(
"As a modem's speaker: on from off hook until CONNECT (ATM1). ATM0 keeps it quiet, ATM2 on all the call; " +
"ATL1-3 its volume, on top of the phone's media volume.",
style = MaterialTheme.typography.bodySmall,
)
Field("Init commands (sent at start)", s.initCommands) { s = s.copy(initCommands = it) }
CountryPicker(s.country) { s = s.copy(country = it) }
Toggle("Call progress tones: dial, ringing, busy, congestion", s.callTones) { s = s.copy(callTones = it) }
Text(
"The country's tones, as its phone network plays them: a second of dial tone as an entry is dialled, " +
"the ringing tone while the other phone rings, the busy or congestion tone when a call can't be made.",
style = MaterialTheme.typography.bodySmall,
)
NumberField("Modem log level (0-5)", s.logLevel) { s = s.copy(logLevel = it.coerceIn(0, 5)) }
if (s.sip) NumberField("SIP log level (0-4)", s.sipLogLevel) { s = s.copy(sipLogLevel = it.coerceIn(0, 4)) }
val p = page
if (p == null) {
SettingsMenu(modifier, s, s != savedAs)
return
}
@Composable
fun SaveRow() {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Button(onClick = {
scope.launch {
store.save(s)
savedAs = s
saved = true
}
}) { Text("Save") }
if (saved) {
}, enabled = s != savedAs) { Text("Save") }
if (s != savedAs) {
Text("Not saved yet", style = MaterialTheme.typography.bodyMedium)
} else if (saved) {
Text(
if (run == ModemState.Run.STOPPED) "Saved" else "Saved: restart the modem to apply",
style = MaterialTheme.typography.bodyMedium,
)
}
}
androidx.compose.material3.HorizontalDivider(Modifier.padding(vertical = 8.dp))
BridgeSection()
androidx.compose.material3.HorizontalDivider(Modifier.padding(vertical = 8.dp))
FaxSettingsSection()
androidx.compose.material3.HorizontalDivider(Modifier.padding(vertical = 8.dp))
IspSettingsSection()
androidx.compose.material3.HorizontalDivider(Modifier.padding(vertical = 8.dp))
AppearanceSection()
androidx.compose.material3.HorizontalDivider(Modifier.padding(vertical = 8.dp))
TerminalSettingsSection()
androidx.compose.material3.HorizontalDivider(Modifier.padding(vertical = 8.dp))
SshKeysSection()
androidx.compose.material3.HorizontalDivider(Modifier.padding(vertical = 8.dp))
LinuxSection(onOpened = onOpenTerminal)
}
Column(modifier.fillMaxSize()) {
// the page's title, and back to the menu
Row(Modifier.fillMaxWidth().padding(start = 4.dp, end = 16.dp, top = 4.dp), verticalAlignment = Alignment.CenterVertically) {
androidx.compose.material3.IconButton(onClick = { SettingsNav.open(null) }) {
androidx.compose.material3.Icon(
androidx.compose.material.icons.Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Back to settings",
)
}
Text(p.title, style = MaterialTheme.typography.titleLarge)
}
Column(
Modifier.fillMaxSize().padding(horizontal = 16.dp).padding(bottom = 16.dp).verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
when (p) {
SettingsPage.LINE -> {
LineChoice(s) { s = it }
if (s.peer) {
PeerLineFields(s) { s = it }
} else if (s.usb) {
UsbLineFields()
} else {
Text("SIP account", style = MaterialTheme.typography.titleSmall)
OutlinedTextField(
value = login,
onValueChange = { v ->
login = v
ModemSettings.parseLogin(v.trim())?.let { (u, pw, d) ->
s = s.copy(user = u, password = pw, domain = d)
}
},
label = { Text("Paste user:password@host (optional)") },
singleLine = true,
modifier = Modifier.fillMaxWidth(),
)
Field("User", s.user) { s = s.copy(user = it) }
OutlinedTextField(
value = s.password,
onValueChange = { s = s.copy(password = it) },
label = { Text("Password") },
singleLine = true,
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
modifier = Modifier.fillMaxWidth(),
)
Field("Server (host[:port])", s.domain) { s = s.copy(domain = it) }
NumberField("Local SIP port", s.sipPort) { s = s.copy(sipPort = it) }
Toggle("Take incoming calls (register)", s.listen) { s = s.copy(listen = it) }
Toggle("Fax over T.38", s.t38) { s = s.copy(t38 = it) }
NumberField("SIP log level (0-4)", s.sipLogLevel) { s = s.copy(sipLogLevel = it.coerceIn(0, 4)) }
}
SaveRow()
}
SettingsPage.MODEM -> {
Toggle("Speaker: hear the dialling and the handshake", s.speaker) { s = s.copy(speaker = it) }
Text(
"As a modem's speaker: on from off hook until CONNECT (ATM1). ATM0 keeps it quiet, ATM2 on all the call; " +
"ATL1-3 its volume, on top of the phone's media volume.",
style = MaterialTheme.typography.bodySmall,
)
Toggle("Fax or data, as each call turns out", s.adaptiveAnswer) { s = s.copy(adaptiveAnswer = it) }
Text(
"A call answered (ATA) is a fax machine's or a modem's by what it sends (adaptive answer, AT+FAA=1): " +
"a fax goes to the fax receiver by itself, a modem's call to the terminal.",
style = MaterialTheme.typography.bodySmall,
)
Field("Init commands (sent at start)", s.initCommands) { s = s.copy(initCommands = it) }
CountryPicker(s.country) { s = s.copy(country = it) }
Toggle("Call progress tones: dial, ringing, busy, congestion", s.callTones) { s = s.copy(callTones = it) }
Text(
"The country's tones, as its phone network plays them: a second of dial tone as an entry is dialled, " +
"the ringing tone while the other phone rings, the busy or congestion tone when a call can't be made.",
style = MaterialTheme.typography.bodySmall,
)
NumberField("Modem log level (0-5)", s.logLevel) { s = s.copy(logLevel = it.coerceIn(0, 5)) }
SaveRow()
}
SettingsPage.BRIDGES -> BridgeSection()
SettingsPage.FAX -> FaxSettingsSection()
SettingsPage.INTERNET -> IspSettingsSection()
SettingsPage.APPEARANCE -> AppearanceSection()
SettingsPage.TERMINAL -> TerminalSettingsSection()
SettingsPage.SSH -> SshKeysSection()
SettingsPage.LINUX -> LinuxSection(onOpened = onOpenTerminal)
}
}
}
}
/** Settings' menu: a row for each page, what it's set to beneath */
@Composable
private fun SettingsMenu(modifier: Modifier, s: ModemSettings, unsaved: Boolean) {
val rows = listOf(
SettingsPage.LINE to lineSummary(s) + if (unsaved) " (not saved)" else "",
SettingsPage.MODEM to "${CountryTones.find(s.country)?.label ?: s.country}; speaker " +
(if (s.speaker) "on" else "off") + "; " + (if (s.adaptiveAnswer) "fax or data as calls turn out" else "calls answered as data"),
SettingsPage.BRIDGES to "The modem for another computer: TCP, Bluetooth, USB serial",
SettingsPage.FAX to "This fax's number and name, answering, the rates",
SettingsPage.INTERNET to "The ISP to dial; dial-in for callers",
SettingsPage.APPEARANCE to "Theme, dark mode, colours",
SettingsPage.TERMINAL to "Emulation, fonts, colours, keys",
SettingsPage.SSH to "This phone's keys for SSH",
SettingsPage.LINUX to "Linux on the phone, the modem at /dev/ttyDM0",
)
Column(modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(vertical = 8.dp)) {
for ((page, summary) in rows) {
Column(
Modifier.fillMaxWidth().clickable { SettingsNav.open(page) }.padding(horizontal = 16.dp, vertical = 12.dp),
) {
Text(page.title, style = MaterialTheme.typography.titleMedium)
Text(summary, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
}
}
}
/** what the line is, in a line */
private fun lineSummary(s: ModemSettings): String = when (s.line) {
ModemSettings.LINE_WIFI -> "Another phone on Wi-Fi" + s.peerName.ifBlank { s.peerAddress }.let { if (it.isBlank()) "" else ": $it" }
ModemSettings.LINE_BLUETOOTH -> "Another phone on Bluetooth" + s.peerName.let { if (it.isBlank()) "" else ": $it" }
ModemSettings.LINE_CELL -> "This phone's mobile calls"
ModemSettings.LINE_NONE -> "No line: the modem on its own"
ModemSettings.LINE_USB -> "A phone line, through a USB modem"
else -> if (s.complete) "SIP: ${s.user}@${s.domain}" + (if (s.listen) ", taking calls" else "") else "SIP: no account set up yet"
}
@Composable
@@ -88,7 +88,7 @@ class AppearanceTest {
compose.waitForIdle()
shot("theme-$name-home")
if (name == "dark-ocean" || name == "light-violet") {
tab("Settings")
SettingsNav.open(SettingsPage.APPEARANCE); tab("Settings")
compose.onNodeWithText("Black background").performScrollTo()
shot("theme-$name-settings")
}
@@ -111,7 +111,7 @@ class AppearanceTest {
fun chosenInSettings() {
runBlocking { store.save(Appearance()) }
ActivityScenario.launch(MainActivity::class.java).use {
tab("Settings")
SettingsNav.open(SettingsPage.APPEARANCE); tab("Settings")
compose.onNodeWithText("Black background").performScrollTo()
compose.onNodeWithText("Dark").performClick()
compose.onNodeWithText("Teal").performClick()
@@ -3,8 +3,10 @@
package com.neodesktop.dmodem.ui
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import org.junit.Assert.assertFalse
import org.junit.Rule
import org.junit.Test
@@ -45,4 +47,46 @@ class BackNavigationTest {
assertFalse(a.isFinishing)
}
}
@Test
fun settingsMenuToAPageAndBack() {
tab("Settings")
// the menu: its pages, what each is set to
compose.onNodeWithText("SIP: no account set up yet").assertExists()
compose.onNodeWithText("Fax").assertExists()
compose.onNodeWithText("Linux").assertExists()
// a page; back to the menu, back again to Home
compose.onNodeWithText("Dial-up internet").performScrollTo().performClick()
// (the page: the menu gone, its title)
gone("The ISP to dial; dial-in for callers")
compose.onNodeWithText("Dial-up internet").assertExists()
back()
shown("The ISP to dial; dial-in for callers")
back()
shown("Set up SIP")
// Home's Set up SIP: the line's page
compose.onNodeWithText("Set up SIP").performClick()
shown("Line")
gone("SIP: no account set up yet")
// the Settings tab again: its menu
tab("Settings")
shown("SIP: no account set up yet")
}
private fun shown(text: String) = compose.waitUntil(5000) {
compose.onAllNodesWithText(text).fetchSemanticsNodes().isNotEmpty()
}
private fun gone(text: String) = compose.waitUntil(5000) {
compose.onAllNodesWithText(text).fetchSemanticsNodes().isEmpty()
}
private fun tab(name: String) {
compose.onNode(
androidx.compose.ui.test.hasText(name) and androidx.compose.ui.test.SemanticsMatcher.expectValue(
androidx.compose.ui.semantics.SemanticsProperties.Role, androidx.compose.ui.semantics.Role.Tab,
),
).performClick()
compose.waitForIdle()
}
}
@@ -85,6 +85,7 @@ class FaxShotsTest {
@Test
fun faxSettings() {
SettingsNav.open(SettingsPage.FAX)
compose.onNodeWithText("Settings").performClick()
compose.onNodeWithText("Fastest rate").performScrollTo()
shot("fax-3-settings")
@@ -93,6 +93,7 @@ class LinuxUiTest {
@Test
fun installedFromSettingsAndUsed() {
SettingsNav.open(SettingsPage.LINUX)
compose.onNode(hasText("Settings") and isSelectable()).performClick()
compose.onNodeWithText("Install a Linux").performScrollTo()
shot("linux-1-settings")
@@ -48,6 +48,7 @@ class PeerShotsTest {
@Test
fun theSettings() {
save(ModemSettings(line = ModemSettings.LINE_WIFI, peerAddress = "192.168.1.20", listen = true))
SettingsNav.open(SettingsPage.LINE)
compose.onNodeWithText("Settings").performClick()
compose.onNodeWithText("Find phones on this network").performScrollTo()
shot("peer-1-settings")
@@ -57,6 +58,7 @@ class PeerShotsTest {
@Test
fun theLineFromItsMenu() {
save(ModemSettings(line = ModemSettings.LINE_SIP))
SettingsNav.open(SettingsPage.LINE)
compose.onNodeWithText("Settings").performClick()
compose.onNodeWithText("A SIP account (calls over the internet)").performScrollTo().performClick()
compose.onNodeWithText("Another phone with D-Modem, on Wi-Fi").performClick()
@@ -67,6 +69,7 @@ class PeerShotsTest {
@Test
fun noLine() {
save(ModemSettings(line = ModemSettings.LINE_SIP))
SettingsNav.open(SettingsPage.LINE)
compose.onNodeWithText("Settings").performClick()
compose.onNodeWithText("A SIP account (calls over the internet)").performScrollTo().performClick()
compose.onNodeWithText("No line (the modem on its own)").performClick()
@@ -79,6 +82,7 @@ class PeerShotsTest {
@Test
fun aUsbModem() {
save(ModemSettings(line = ModemSettings.LINE_SIP))
SettingsNav.open(SettingsPage.LINE)
compose.onNodeWithText("Settings").performClick()
compose.onNodeWithText("A SIP account (calls over the internet)").performScrollTo().performClick()
compose.onNodeWithText("A phone line, through a USB modem").performClick()
@@ -104,6 +108,7 @@ class PeerShotsTest {
@Test
fun theMobileCallLine() {
save(ModemSettings(line = ModemSettings.LINE_CELL, listen = true))
SettingsNav.open(SettingsPage.LINE)
compose.onNodeWithText("Settings").performClick()
compose.onNodeWithText("Calls ringing here go to the modem").performScrollTo()
shot("peer-3-cell-settings")