securemail: compact message reader modeled on the email app
- Commit
0688cd4d1a0c232288aa0e9ecfd178dc726cb4cf- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-02 01:33 UTC (1 month ago)
- Parents
db6725c
The reader wasted most of the screen: a "Message" app bar, a separate
trust-badge card, a card wrapping From/subject/body, and full-width Reply
and Back buttons. This borrows the layout of the email app's thread view
(email/ui/MessageThreadScreen.kt):
- Subject moves into the app bar, with a back arrow and a Reply action;
the Back button is gone.
- One compact header row: initial avatar, sender (recipient for Sent),
date, and "to me" / "from me".
- Trust collapses to a single coloured line with an icon under the
sender (not encrypted / signature verified / not verified / locked)
instead of its own card.
- The body renders unboxed; quoted history ("On ... wrote:", ">" lines)
is collapsed behind "Show quoted text", same rule as the email app.
- Tapping the header opens a bottom sheet with the full date, From and
To addresses, and the complete signer fingerprint grouped in fours
(previously truncated to 16 characters).
Snooze, unsubscribe, block sender, attachments and HTML rendering were
left out: SecureMail has none of those concepts.
Also drops ReaderScreen's unused messageId parameter (detekt
UnusedParameter); Navigation passes one argument fewer.
Verified: :securemail:compileDevKotlin, :securemail:lint and detekt
(no findings in ReaderScreen.kt). Not yet exercised on a device.Diff
securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt b/securemail/src/main/java/com/vayunmathur/securemail/Navigation.ktindex 80f7f390d6..3e3cb42d82 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt@@ -170,7 +170,6 @@ fun Navigation(viewModel: MailViewModel, initialRoute: Route? = null) { } ReaderScreen( state = state,- messageId = route.messageId, onReply = { m -> backStack.add( Route.Composer(
securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.ktindex 61f7aa2e45..cfe876adaa 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt@@ -1,89 +1,234 @@ package com.vayunmathur.securemail.ui -import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.AppScaffold-import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.DesktopMaxWidthContainer+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.HorizontalDivider+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconLock+import com.vayunmathur.library.ui.IconShield+import com.vayunmathur.library.ui.IconUndo+import com.vayunmathur.library.ui.IconWarning import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.ModalBottomSheet+import com.vayunmathur.library.ui.OutlinedButton+import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.rememberModalBottomSheetState+import com.vayunmathur.securemail.data.MailFolder import com.vayunmathur.securemail.data.StoredMessage import com.vayunmathur.securemail.platform.MailUiState+import java.text.DateFormat+import java.util.Date -/** Reader: trust badges (verified signer / plain / locked) + decrypted body. */+/**+ * Reader, laid out like the email app's thread view: subject in the app bar,+ * one compact sender row (details in a bottom sheet), trust as a single line,+ * and the body unboxed with quoted history collapsed.+ */+@OptIn(ExperimentalMaterial3Api::class) @Composable fun ReaderScreen( state: MailUiState,- messageId: String, onReply: (StoredMessage) -> Unit, onBack: () -> Unit, message: StoredMessage? = null, ) { val msg = message- AppScaffold(title = "Message", scrollBehavior = appBarScrollBehavior()) { padding ->+ AppScaffold(+ title = msg?.decryptedSubject?.ifBlank { "(no subject)" } ?: "Message",+ onNavigateBack = onBack,+ actions = {+ if (msg != null) {+ IconButton(onClick = { onReply(msg) }) { IconUndo() }+ }+ },+ scrollBehavior = appBarScrollBehavior(),+ ) { padding -> DesktopMaxWidthContainer(Modifier.padding(padding)) {- Column(- modifier = Modifier- .fillMaxWidth()- .padding(16.dp)- .verticalScroll(rememberScrollState()),- verticalArrangement = Arrangement.spacedBy(12.dp),- ) {+ Column(modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState())) { if (msg == null) {- Text("Message not found.", style = MaterialTheme.typography.bodyMedium)+ Text(+ "Message not found.",+ style = MaterialTheme.typography.bodyMedium,+ modifier = Modifier.padding(16.dp),+ ) } else {- TrustBadge(msg)- Card(modifier = Modifier.fillMaxWidth()) {- Column(- modifier = Modifier.padding(16.dp).fillMaxWidth(),- verticalArrangement = Arrangement.spacedBy(8.dp),- ) {- Text(- if (msg.folder == com.vayunmathur.securemail.data.MailFolder.SENT) {- "To: ${msg.toJson.ifBlank { "(unknown)" }}"- } else {- "From: ${msg.from.ifBlank { "(encrypted sender)" }}"- },- style = MaterialTheme.typography.labelMedium,- )- Text(- msg.decryptedSubject ?: "(decrypting…)",- style = MaterialTheme.typography.titleMedium,- )- Text(- msg.decryptedBody ?: "(decrypting…)",- style = MaterialTheme.typography.bodyMedium,- )- }- }- Button(onClick = { onReply(msg) }, modifier = Modifier.fillMaxWidth()) {- Text("Reply")- }+ MessageBody(msg, ownAddress = state.address, onReply = { onReply(msg) }) }- Button(onClick = onBack, modifier = Modifier.fillMaxWidth()) { Text("Back") } } } } } +@OptIn(ExperimentalMaterial3Api::class) @Composable-private fun TrustBadge(msg: StoredMessage) {+private fun MessageBody(msg: StoredMessage, ownAddress: String, onReply: () -> Unit) {+ var showDetails by remember { mutableStateOf(false) }+ val sent = msg.folder == MailFolder.SENT+ val counterpart = if (sent) msg.toJson.ifBlank { "(unknown)" } else msg.from.ifBlank { "(encrypted sender)" }+ val date = remember(msg.dateMillis) {+ DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(Date(msg.dateMillis))+ }+ val avatarColor = MaterialTheme.colorScheme.primaryContainer++ Row(+ modifier = Modifier.fillMaxWidth().clickable { showDetails = true }.padding(16.dp),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Avatar(counterpart, avatarColor, MaterialTheme.colorScheme.onPrimaryContainer, 40)+ Column(modifier = Modifier.weight(1f).padding(start = 12.dp)) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Text(+ counterpart,+ style = MaterialTheme.typography.titleSmall,+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ modifier = Modifier.weight(1f, fill = false),+ )+ Text(+ " \u2022 $date",+ style = MaterialTheme.typography.labelSmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ maxLines = 1,+ )+ }+ Text(+ if (sent) "from me" else "to me",+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ TrustLine(msg)+ }+ }++ BodyText(msg)++ Row(modifier = Modifier.padding(16.dp)) {+ OutlinedButton(onClick = onReply, modifier = Modifier.weight(1f)) {+ IconUndo(modifier = Modifier.size(18.dp))+ Spacer(Modifier.width(8.dp))+ Text("Reply")+ }+ }+ HorizontalDivider()++ if (showDetails) {+ ModalBottomSheet(+ onDismissRequest = { showDetails = false },+ sheetState = rememberModalBottomSheetState(),+ ) {+ Column(modifier = Modifier.padding(16.dp).fillMaxWidth()) {+ Text(date, style = MaterialTheme.typography.labelSmall, modifier = Modifier.align(Alignment.End))+ DetailRow("From", if (sent) ownAddress else msg.from.ifBlank { "(encrypted sender)" }, avatarColor)+ DetailRow("To", if (sent) msg.toJson.ifBlank { "(unknown)" } else ownAddress, MaterialTheme.colorScheme.surfaceVariant)+ if (msg.verifiedSigner != null) {+ Spacer(Modifier.height(8.dp))+ Text("Signer fingerprint", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.primary)+ Text(+ msg.verifiedSigner.chunked(4).joinToString(" "),+ style = MaterialTheme.typography.bodySmall,+ modifier = Modifier.padding(vertical = 8.dp),+ )+ }+ Spacer(Modifier.height(24.dp))+ }+ }+ }+}++@Composable+private fun TrustLine(msg: StoredMessage) {+ val colors = MaterialTheme.colorScheme val (label, color) = when {- msg.unencrypted -> "Unencrypted — sent or received in clear" to MaterialTheme.colorScheme.error- msg.verifiedSigner != null -> "Signed by ${msg.verifiedSigner.take(16)}…" to MaterialTheme.colorScheme.primary- msg.decryptedBody != null -> "Encrypted — signature not verified" to MaterialTheme.colorScheme.secondary- else -> "Locked — decrypting…" to MaterialTheme.colorScheme.secondary+ msg.unencrypted -> "Not encrypted" to colors.error+ msg.verifiedSigner != null -> "Encrypted \u00b7 signature verified" to colors.primary+ msg.decryptedBody != null -> "Encrypted \u00b7 signature not verified" to colors.onSurfaceVariant+ else -> "Locked \u00b7 decrypting\u2026" to colors.onSurfaceVariant+ }+ Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(top = 2.dp)) {+ val iconModifier = Modifier.size(14.dp)+ when {+ msg.unencrypted -> IconWarning(modifier = iconModifier, tint = color)+ msg.verifiedSigner != null -> IconShield(modifier = iconModifier, tint = color)+ else -> IconLock(modifier = iconModifier, tint = color)+ }+ Spacer(Modifier.width(4.dp))+ Text(label, style = MaterialTheme.typography.labelSmall, color = color)+ }+}++@Composable+private fun BodyText(msg: StoredMessage) {+ val body = msg.decryptedBody ?: "(decrypting\u2026)"+ var showQuotes by remember(msg.id) { mutableStateOf(false) }+ val (main, quoted) = remember(body) { splitQuotedText(body) }+ Text(+ if (showQuotes || quoted.isEmpty()) body else main,+ style = MaterialTheme.typography.bodyMedium,+ modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp),+ )+ if (quoted.isNotEmpty()) {+ TextButton(onClick = { showQuotes = !showQuotes }, modifier = Modifier.padding(horizontal = 8.dp)) {+ Text(if (showQuotes) "Hide quoted text" else "Show quoted text")+ } }- Card(modifier = Modifier.fillMaxWidth()) {- Text(label, color = color, modifier = Modifier.padding(12.dp), style = MaterialTheme.typography.labelMedium)+}++@Composable+private fun DetailRow(label: String, address: String, avatarColor: Color) {+ Column(modifier = Modifier.padding(vertical = 8.dp)) {+ Text(label, style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.primary)+ Row(modifier = Modifier.padding(vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) {+ Avatar(address, avatarColor, MaterialTheme.colorScheme.onSurface, 32)+ Text(address, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.padding(start = 12.dp))+ }+ }+}++@Composable+private fun Avatar(address: String, color: Color, contentColor: Color, sizeDp: Int) {+ Surface(shape = CircleShape, color = color, modifier = Modifier.size(sizeDp.dp)) {+ Box(contentAlignment = Alignment.Center) {+ Text(address.take(1).uppercase(), color = contentColor, style = MaterialTheme.typography.titleMedium)+ }+ }+}++private fun splitQuotedText(body: String): Pair<String, String> {+ val lines = body.split("\n")+ val onWrote = Regex("^On .+ wrote:\\s*$")+ val origMsg = Regex("^-{2,}\\s*Original Message\\s*-{2,}\\s*$", RegexOption.IGNORE_CASE)+ for (i in lines.indices) {+ val line = lines[i].trim()+ if (i > 0 && (onWrote.matches(line) || origMsg.matches(line) || line.startsWith(">"))) {+ return lines.subList(0, i).joinToString("\n").trimEnd() to lines.subList(i, lines.size).joinToString("\n")+ } }+ return body to "" }