diff --git a/android/README.md b/android/README.md index 7d3ee0dc..907ed61f 100644 --- a/android/README.md +++ b/android/README.md @@ -369,11 +369,42 @@ content, or a failed clipboard operation, offers UTF-8 file export through FileProvider and Android's sharesheet; Binder receives a URI, not the text. Exports older than 24 hours are cleaned on the next export. -Body/composer/user text uses 16sp/24sp, code/diff/terminal 14sp/20sp, captions -12sp/16sp. Content and composer share a centered 720dp reading column with -16dp minimum side margins. Bubble widths use actual container constraints, +Reading metrics match iOS `HapiTypography` (`ui/theme/HapiTypography.kt`): +body/composer/user text 16sp/24sp with zero tracking, strict CJK line breaking +and leading trimmed above the first and below the last line; code/diff/terminal +14sp/20sp in bundled JetBrains Mono NL (SIL OFL, no ligatures); inline code 14sp +on a glyph-hugging chip; captions 12sp/16sp; headings 24/20/18/17sp semibold. +Markdown blocks are 12dp apart, 24dp before a heading and 8dp after one; list +items 8dp. Transcript rows use iOS `TranscriptRowRole` gaps (8dp between tools +or between user prompts, 24dp before and 16dp after a user turn, otherwise +12dp). Content and composer share a centered 720dp reading column with 16dp +minimum side margins. Bubble widths use actual container constraints, including split-screen; Android font scaling remains enabled. +Chat surfaces stay neutral gray: the static schemes carry hue-free surface +ladders, and `NeutralChatSurfaces` reapplies them over Material You so the +wallpaper only tints accents inside a conversation (presets and OLED pass +through). Transcript icons are Material Symbols Rounded vector drawables +(`res/drawable/ic_sym_*`, Apache-2.0), never emoji or text glyphs. Inline +actions (approvals, plan actions) share `ChatActionButton`: 48dp minimum, +10dp corners, one filled primary per row. + +### Visual specimens + +`app/src/test/.../specimens/` renders deterministic, non-networked specimens +(Markdown, reasoning, tool cards, approvals, composer states) under Robolectric +native graphics in light/dark/OLED. Ordinary unit-test runs only compose them; +capture images with: + +```sh +./gradlew :app:recordRoborazziDebug --tests 'app.hapi.companion.specimens.*' +# โ†’ app/build/outputs/roborazzi/specimens/*.png +``` + +They are review aids for visual changes, not committed goldens or store +screenshots. Roborazzi is pinned to 1.60.0: later releases ship Kotlin 2.3 +metadata this Kotlin 2.1 build cannot read. + ## Connection status and home filters The chat subtitle reserves its height. **Reconnecting ยท Tap to retry** appears diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 3bffb4ef..1953ea99 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -8,6 +8,8 @@ plugins { alias(libs.plugins.kotlin.compose) // New-session form draft + prefs persist as JSON blobs in DataStore (B-M3d). alias(libs.plugins.kotlin.serialization) + // Visual specimens: `./gradlew :app:recordRoborazziDebug` (README). + alias(libs.plugins.roborazzi) // com.google.gms.google-services is applied CONDITIONALLY below (B-M4a): // the plugin hard-fails when app/google-services.json is missing, and the // repo must build green without any Firebase project configured. @@ -132,6 +134,8 @@ android { } testOptions { + // Robolectric specimens resolve fonts, drawables and strings. + unitTests.isIncludeAndroidResources = true unitTests.all { test -> // Chat pipeline smoke tests replay golden fixtures from the repo // root (same wiring as :core:protocol / :core:data). @@ -213,4 +217,10 @@ dependencies { testImplementation(libs.turbine) // Generated media fetch tests: real HTTP round-trip against localhost. testImplementation(libs.okhttp.mockwebserver) + // Visual specimens (Compose rendered under Robolectric native graphics). + testImplementation(platform(libs.androidx.compose.bom)) + testImplementation(libs.androidx.compose.ui.test.junit4) + testImplementation(libs.robolectric) + testImplementation(libs.roborazzi) + testImplementation(libs.roborazzi.compose) } diff --git a/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatHost.kt b/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatHost.kt index 2b7b9374..90105942 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatHost.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatHost.kt @@ -32,6 +32,7 @@ import app.hapi.companion.feature.chat.composer.DictationController import app.hapi.companion.ui.markdown.LocalMarkdownLinkHandler import app.hapi.companion.ui.markdown.LocalMarkdownRenderCache import app.hapi.companion.ui.theme.HapiTypography +import app.hapi.companion.ui.theme.NeutralChatSurfaces import app.hapi.companion.ui.theme.ReadingColumn import app.hapi.protocol.chat.* import kotlinx.coroutines.launch @@ -125,44 +126,46 @@ internal fun ChatHost( LocalMarkdownRenderCache provides viewModel.markdownCache, LocalMarkdownLinkHandler provides rememberChatLinkHandler(onOpenFile = openFile), ) { - Box(Modifier.fillMaxSize()) { - NavHost(navigation, startDestination = "thread") { - composable("thread") { - ChatScreen( - viewModel, media, onBack, snackbarHostState = snackbar, - dictation = dictation, onOpenFiles = { pauseReading(); onOpenFiles() }, onOpenFile = openFile, - onOpenScratchlist = onOpenScratchlist?.let { open -> { pauseReading(); open() } }, - transcriptList = transcriptList, readingState = reading, - ) - } - for (kind in listOf("group", "tool", "process", "message")) { - composable("$kind/{id}", arguments = listOf(navArgument("id") { type = NavType.StringType })) { destination -> - val id = destination.arguments?.getString("id").orEmpty() - val revision by viewModel.inspection.revision.collectAsState() - val back = { navigation.popBackStack(); Unit } - val close = { navigation.popBackStack("thread", false); Unit } - when (kind) { - "group" -> { - val group = remember(id, revision) { viewModel.inspection.group(id) } - if (group == null) MissingInspection(back, close) - else ToolGroupBrowser(group, state.basePath, actions::openTool, back, close) - } - "message" -> { - val message = remember(id, revision) { viewModel.inspection.message(id) } - if (message == null) MissingInspection(back, close) - else MessageReader(message.value.text, message.stale, back, close) - } - else -> { - val tool = remember(id, revision) { viewModel.inspection.tool(id) } - if (tool == null) MissingInspection(back, close) - else ToolReader(tool, kind == "process", state.basePath, openFile, back, close) + NeutralChatSurfaces { + Box(Modifier.fillMaxSize()) { + NavHost(navigation, startDestination = "thread") { + composable("thread") { + ChatScreen( + viewModel, media, onBack, snackbarHostState = snackbar, + dictation = dictation, onOpenFiles = { pauseReading(); onOpenFiles() }, onOpenFile = openFile, + onOpenScratchlist = onOpenScratchlist?.let { open -> { pauseReading(); open() } }, + transcriptList = transcriptList, readingState = reading, + ) + } + for (kind in listOf("group", "tool", "process", "message")) { + composable("$kind/{id}", arguments = listOf(navArgument("id") { type = NavType.StringType })) { destination -> + val id = destination.arguments?.getString("id").orEmpty() + val revision by viewModel.inspection.revision.collectAsState() + val back = { navigation.popBackStack(); Unit } + val close = { navigation.popBackStack("thread", false); Unit } + when (kind) { + "group" -> { + val group = remember(id, revision) { viewModel.inspection.group(id) } + if (group == null) MissingInspection(back, close) + else ToolGroupBrowser(group, state.basePath, actions::openTool, back, close) + } + "message" -> { + val message = remember(id, revision) { viewModel.inspection.message(id) } + if (message == null) MissingInspection(back, close) + else MessageReader(message.value.text, message.stale, back, close) + } + else -> { + val tool = remember(id, revision) { viewModel.inspection.tool(id) } + if (tool == null) MissingInspection(back, close) + else ToolReader(tool, kind == "process", state.basePath, openFile, back, close) + } } } } } - } - if (entry?.destination?.route != "thread") { - SnackbarHost(snackbar, Modifier.align(Alignment.BottomCenter).navigationBarsPadding()) + if (entry?.destination?.route != "thread") { + SnackbarHost(snackbar, Modifier.align(Alignment.BottomCenter).navigationBarsPadding()) + } } } } diff --git a/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatTranscript.kt b/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatTranscript.kt index bfa35696..f28111b7 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatTranscript.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/feature/chat/ChatTranscript.kt @@ -13,7 +13,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.MaterialTheme @@ -38,10 +38,14 @@ import androidx.compose.ui.layout.layout import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import app.hapi.companion.R import app.hapi.data.store.ChatHistoryPagingState import app.hapi.protocol.chat.AggregatedAssistantMeta +import app.hapi.protocol.chat.ToolCallBlock +import app.hapi.protocol.chat.ToolGroupBlock +import app.hapi.protocol.chat.UserTextBlock import app.hapi.protocol.chat.VisibleChatBlock import app.hapi.protocol.chat.buildMessageMetadataLabels import app.hapi.protocol.chat.messageMetadataForBlock @@ -82,7 +86,6 @@ internal fun ChatTranscript( val heights = remember(state.sessionId) { mutableMapOf() } val density = LocalDensity.current val estimatedHeight = with(density) { 100.dp.roundToPx() } - val spacing = with(density) { 10.dp.roundToPx() } val headerHeight = with(density) { 44.dp.roundToPx() } val isDragged by listState.interactionSource.collectIsDraggedAsState() // Restore intent with LazyListState, otherwise the first tail effect @@ -122,8 +125,9 @@ internal fun ChatTranscript( } var distance = listState.firstVisibleItemScrollOffset for (index in 0 until listState.firstVisibleItemIndex) { - distance += if (index == 0) headerHeight + spacing - else (heights[current.getOrNull(index - 1)?.id] ?: estimatedHeight) + spacing + // Measured row heights include their role-based top gap. + distance += if (index == 0) headerHeight + else heights[current.getOrNull(index - 1)?.id] ?: estimatedHeight if (distance > height) break } val short = !listState.canScrollBackward && !listState.canScrollForward @@ -257,15 +261,17 @@ internal fun ChatTranscript( } }, contentPadding = PaddingValues(vertical = 10.dp), - verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.Bottom), + verticalArrangement = Arrangement.Bottom, ) { item(key = HISTORY_KEY, contentType = HISTORY_KEY) { HistoryControl(paging.phase, state.hasMore, state.isSyncingTail, onRetryHistory) } - items(rows, key = { it.id }, contentType = { it.block.contentKind }) { row -> + itemsIndexed(rows, key = { _, row -> row.id }, contentType = { _, row -> row.block.contentKind }) { index, row -> rowState.SaveableStateProvider(row.id) { + val gap = transcriptRowGap(row.block, rows.getOrNull(index - 1)?.block) val rowModifier = Modifier .onSizeChanged { heights[row.id] = it.height } + .padding(top = gap) .testTag("chat-row-" + row.id) app.hapi.companion.ui.theme.ReadingColumn(modifier = rowModifier) { Column(modifier = Modifier.fillMaxWidth()) { @@ -358,3 +364,28 @@ private fun HistoryControl( } } } + +/** Presentation-only rhythm (iOS `TranscriptRowRole`); independent of grouping and IDs. */ +internal enum class TranscriptRowRole { User, Tool, Content } + +internal val VisibleChatBlock.rowRole: TranscriptRowRole + get() = when (this) { + is UserTextBlock -> TranscriptRowRole.User + is ToolCallBlock, is ToolGroupBlock -> TranscriptRowRole.Tool + else -> TranscriptRowRole.Content + } + +/** + * Gap above a transcript row: tight between consecutive tools or user + * prompts, generous around a user turn, 12dp otherwise (and after history). + */ +internal fun transcriptRowGap(block: VisibleChatBlock, previous: VisibleChatBlock?): Dp { + val role = block.rowRole + val before = previous?.rowRole ?: return 12.dp + return when { + role == TranscriptRowRole.User -> if (before == TranscriptRowRole.User) 8.dp else 24.dp + before == TranscriptRowRole.User -> 16.dp + role == TranscriptRowRole.Tool && before == TranscriptRowRole.Tool -> 8.dp + else -> 12.dp + } +} diff --git a/android/app/src/main/kotlin/app/hapi/companion/feature/chat/blocks/CodexReviewBlockView.kt b/android/app/src/main/kotlin/app/hapi/companion/feature/chat/blocks/CodexReviewBlockView.kt index 0b85073a..d4d217e5 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/feature/chat/blocks/CodexReviewBlockView.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/feature/chat/blocks/CodexReviewBlockView.kt @@ -25,7 +25,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -33,6 +32,7 @@ import androidx.compose.ui.unit.sp import app.hapi.companion.R import app.hapi.companion.ui.markdown.Markdown import app.hapi.companion.ui.theme.HapiTheme +import app.hapi.companion.ui.theme.HapiTypography import app.hapi.companion.ui.theme.hapi import app.hapi.protocol.chat.CodexReview import app.hapi.protocol.chat.CodexReviewBlock @@ -177,7 +177,7 @@ private fun FindingRow(finding: CodexReviewFinding) { formatLocation(finding)?.let { location -> Text( text = location, - style = MaterialTheme.typography.labelSmall.copy(fontFamily = FontFamily.Monospace, fontSize = 10.sp), + style = MaterialTheme.typography.labelSmall.copy(fontFamily = HapiTypography.monoFamily, fontSize = 10.sp), color = colors.hint, modifier = Modifier.padding(top = 4.dp), ) diff --git a/android/app/src/main/kotlin/app/hapi/companion/feature/files/FilesScreen.kt b/android/app/src/main/kotlin/app/hapi/companion/feature/files/FilesScreen.kt index 65cb24f5..ae9a01b8 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/feature/files/FilesScreen.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/feature/files/FilesScreen.kt @@ -42,12 +42,12 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import app.hapi.companion.R +import app.hapi.companion.ui.theme.HapiTypography import app.hapi.companion.ui.theme.hapi import app.hapi.protocol.git.GitFileStatus import app.hapi.protocol.wire.FileSearchItem @@ -267,7 +267,7 @@ private fun GitFileRow(file: GitFileStatus, onClick: () -> Unit) { if (file.linesAdded > 0 && file.linesRemoved > 0) append(' ') if (file.linesRemoved > 0) append("-${file.linesRemoved}") }, - fontFamily = FontFamily.Monospace, + fontFamily = HapiTypography.monoFamily, fontSize = 11.sp, color = colors.hint, ) diff --git a/android/app/src/main/kotlin/app/hapi/companion/feature/settings/StorageScreen.kt b/android/app/src/main/kotlin/app/hapi/companion/feature/settings/StorageScreen.kt index db1fa5bf..ff1e0880 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/feature/settings/StorageScreen.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/feature/settings/StorageScreen.kt @@ -29,8 +29,8 @@ import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset @@ -39,9 +39,9 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.graphics.lerp import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp import app.hapi.companion.R +import app.hapi.companion.ui.theme.HapiTypography import app.hapi.protocol.wire.SqliteStorageUsageResponse /** @@ -212,7 +212,7 @@ internal fun StorageUsageCard(usage: SqliteStorageUsageResponse, modifier: Modif Text( text = usage.path, style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, + fontFamily = HapiTypography.monoFamily, ) } } diff --git a/android/app/src/main/kotlin/app/hapi/companion/ui/components/ChatActionButton.kt b/android/app/src/main/kotlin/app/hapi/companion/ui/components/ChatActionButton.kt new file mode 100644 index 00000000..39c979fb --- /dev/null +++ b/android/app/src/main/kotlin/app/hapi/companion/ui/components/ChatActionButton.kt @@ -0,0 +1,67 @@ +package app.hapi.companion.ui.components + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.defaultMinSize +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.ProvideTextStyle +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import app.hapi.companion.ui.theme.hapi + +/** Visual weight of a [ChatActionButton]. */ +enum class ChatActionProminence { + /** The one filled action of a row (Allow, Submit answer, Implement plan). */ + Primary, + + /** Hairline-bordered companion actions (Deny, Previous, Continue planning). */ + Secondary, +} + +/** + * The single button style for inline transcript actions โ€” approvals, question + * navigation, plan actions and queued-message actions (iOS + * `ChatActionButtonStyle`). It owns the full touch target (48dp minimum, + * 10dp corners); callers must not add another minimum height or padding. + * Only geometry is shared: each caller keeps its own submission semantics. + */ +@Composable +fun ChatActionButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + prominence: ChatActionProminence = ChatActionProminence.Secondary, + enabled: Boolean = true, + content: @Composable RowScope.() -> Unit, +) { + val sized = modifier.defaultMinSize(minHeight = 48.dp) + val textStyle = MaterialTheme.typography.labelLarge.copy(fontSize = 15.sp, letterSpacing = 0.sp, fontWeight = FontWeight.Medium) + when (prominence) { + ChatActionProminence.Primary -> Button( + onClick = onClick, + modifier = sized, + enabled = enabled, + shape = ChatActionShape, + contentPadding = ChatActionPadding, + ) { ProvideTextStyle(textStyle) { content() } } + ChatActionProminence.Secondary -> OutlinedButton( + onClick = onClick, + modifier = sized, + enabled = enabled, + shape = ChatActionShape, + contentPadding = ChatActionPadding, + border = BorderStroke(1.dp, MaterialTheme.hapi.divider), + colors = ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.colorScheme.onSurface), + ) { ProvideTextStyle(textStyle) { content() } } + } +} + +private val ChatActionShape = RoundedCornerShape(10.dp) +private val ChatActionPadding = PaddingValues(horizontal = 16.dp, vertical = 10.dp) diff --git a/android/app/src/main/kotlin/app/hapi/companion/ui/components/DiffView.kt b/android/app/src/main/kotlin/app/hapi/companion/ui/components/DiffView.kt index b3db780b..400a2cf2 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/ui/components/DiffView.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/ui/components/DiffView.kt @@ -28,7 +28,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.withStyle @@ -36,6 +35,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import app.hapi.companion.R import app.hapi.companion.ui.theme.HapiExtendedColors +import app.hapi.companion.ui.theme.HapiTypography import app.hapi.companion.ui.theme.hapi import app.hapi.protocol.git.DiffChangeKind import app.hapi.protocol.git.DiffFile @@ -93,7 +93,7 @@ fun DiffView( ) { Text( text = row.text, - fontFamily = FontFamily.Monospace, + fontFamily = HapiTypography.monoFamily, fontSize = 14.sp, lineHeight = 20.sp, softWrap = false, @@ -140,7 +140,7 @@ private fun DiffHeader(file: DiffFile, colors: HapiExtendedColors) { } Text( text = title, - fontFamily = FontFamily.Monospace, + fontFamily = HapiTypography.monoFamily, fontSize = 11.sp, letterSpacing = 0.5.sp, color = colors.codeHeaderForeground, diff --git a/android/app/src/main/kotlin/app/hapi/companion/ui/markdown/MermaidDiagram.kt b/android/app/src/main/kotlin/app/hapi/companion/ui/markdown/MermaidDiagram.kt index 184e83a3..555e06c1 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/ui/markdown/MermaidDiagram.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/ui/markdown/MermaidDiagram.kt @@ -38,7 +38,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -47,6 +46,7 @@ import androidx.compose.ui.viewinterop.AndroidView import app.hapi.companion.R import app.hapi.companion.ui.components.FullTextAction import app.hapi.companion.ui.theme.HapiExtendedColors +import app.hapi.companion.ui.theme.HapiTypography import app.hapi.companion.ui.theme.hapi import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicInteger @@ -314,7 +314,7 @@ private fun MermaidDiagramHeader(code: String, colors: HapiExtendedColors) { ) { Text( text = "mermaid".uppercase(), - fontFamily = FontFamily.Monospace, + fontFamily = HapiTypography.monoFamily, fontSize = 11.sp, lineHeight = 16.sp, letterSpacing = 0.8.sp, @@ -357,7 +357,7 @@ private fun MermaidDiagramFallback( text = message, fontSize = 11.sp, lineHeight = 15.sp, - fontFamily = FontFamily.Monospace, + fontFamily = HapiTypography.monoFamily, color = colors.hint, ) } @@ -370,7 +370,7 @@ private fun MermaidDiagramFallback( ) { Text( text = code, - fontFamily = FontFamily.Monospace, + fontFamily = HapiTypography.monoFamily, fontSize = 14.sp, lineHeight = 20.sp, softWrap = false, diff --git a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiColors.kt b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiColors.kt index f58bb587..aa9d5477 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiColors.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiColors.kt @@ -43,6 +43,16 @@ data class HapiExtendedColors( val hint: Color, /** Amber caution accent for warning bands (context indicator, cautions). */ val warning: Color, + /** + * Secondary reading text (iOS `textSecondary`): tool subtitles, reasoning + * labels, status captions. Darker than [hint], which stays for + * placeholders and disabled-looking metadata. + */ + val textSecondary: Color, + /** Neutral fill for inline transcript cards (tools, approvals, groups). */ + val cardSurface: Color, + /** Composer card fill: lifts off the canvas instead of sinking into it. */ + val composerSurface: Color, ) /** Mirrors `:root` (light) tokens in web/src/index.css. */ @@ -68,6 +78,9 @@ val HapiLightExtendedColors = HapiExtendedColors( hint = Color(0xFF6B7280), // Amber-700: 5.0:1 on white. warning = Color(0xFFB45309), + textSecondary = Color(0xFF52555E), + cardSurface = Color(0xFFF6F7F9), + composerSurface = Color(0xFFFFFFFF), ) /** Mirrors `[data-theme="dark"]` tokens in web/src/index.css. */ @@ -93,6 +106,9 @@ val HapiDarkExtendedColors = HapiExtendedColors( hint = Color(0xFF8E8E93), // Amber-400: 10.2:1 on the M3 dark surface. warning = Color(0xFFFBBF24), + textSecondary = Color(0xFFA8ADB8), + cardSurface = Color(0xFF171A21), + composerSurface = Color(0xFF1C2028), ) /** @@ -121,6 +137,9 @@ val HapiOledExtendedColors = HapiExtendedColors( hint = Color(0xFF8E8E93), // Amber-400 on the pure-black canvas. warning = Color(0xFFFBBF24), + textSecondary = Color(0xFFA8ADB8), + cardSurface = Color(0xFF0A0A0C), + composerSurface = Color(0xFF131316), ) val LocalHapiExtendedColors = staticCompositionLocalOf { HapiLightExtendedColors } diff --git a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiTypography.kt b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiTypography.kt index d4a6c707..a5e5bd8c 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiTypography.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/HapiTypography.kt @@ -10,46 +10,106 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.Font import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.LineBreak +import androidx.compose.ui.text.style.LineHeightStyle import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import app.hapi.companion.R -/** sp delegates scaling (including Android 14's nonlinear scaling) to the platform. */ +/** + * Reading metrics shared with iOS `HapiTypography`: 16/24 body, 15 inline + * code, 14/20 code, 12/16 captions, 24/20/18/17 headings. sp delegates + * scaling (including Android 14's nonlinear scaling) to the platform. + */ object HapiTypography { - /** Primary reading style: chat bubbles and long-form markdown. */ - val body = TextStyle(fontSize = 16.sp, lineHeight = 24.sp) + /** + * JetBrains Mono NL (SIL OFL 1.1; license in the font's name table). The + * no-ligature cut keeps `!=`/`->` in agent output literal, like SF Mono. + */ + val monoFamily = FontFamily( + Font(R.font.jetbrains_mono_regular, FontWeight.Normal), + Font(R.font.jetbrains_mono_bold, FontWeight.Bold), + ) /** - * Monospace style for code blocks and CLI output. Material has no code - * slot, so views that render code consume this token directly; it never - * leaks into the shared scale's reading slots. + * Leading is distributed between lines only (iOS `lineSpacing`): the first + * line's ascent and the last line's descent are trimmed, so block spacing + * tokens measure the visible gap instead of hidden half-leading. */ - val code = TextStyle(fontFamily = FontFamily.Monospace, fontSize = 14.sp, lineHeight = 20.sp) + private val trimmedLeading = LineHeightStyle( + alignment = LineHeightStyle.Alignment.Center, + trim = LineHeightStyle.Trim.Both, + ) - /** Compact metadata style: timestamps, counters, table headers. */ - val caption = TextStyle(fontSize = 12.sp, lineHeight = 16.sp) + /** Primary reading style: chat bubbles and long-form markdown. */ + val body = TextStyle( + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.sp, + lineHeightStyle = trimmedLeading, + // Strict CJK breaking rules and high-quality line filling. + lineBreak = LineBreak.Paragraph, + ) + + /** + * Monospace style for code blocks, CLI output and diffs. Material has no + * code slot, so views that render code consume this token directly. + */ + val code = TextStyle( + fontFamily = monoFamily, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.sp, + lineHeightStyle = trimmedLeading, + ) + + /** Compact metadata style: timestamps, counters, tool subtitles. */ + val caption = TextStyle(fontSize = 12.sp, lineHeight = 16.sp, letterSpacing = 0.sp) + + /** Tool summary titles and similar one-line labels (iOS 15pt medium). */ + val rowTitle = TextStyle(fontSize = 15.sp, lineHeight = 20.sp, letterSpacing = 0.sp, fontWeight = FontWeight.Medium) + + /** Tool summary subtitles and secondary row text (iOS 13pt). */ + val rowSubtitle = TextStyle(fontSize = 13.sp, lineHeight = 18.sp, letterSpacing = 0.sp) + + /** Markdown heading by level; matches iOS `headingSize`. */ + fun heading(level: Int): TextStyle { + val size = when (level) { + 1 -> 24 + 2 -> 20 + 3 -> 18 + else -> 17 + } + return body.copy( + fontSize = size.sp, + lineHeight = (size * 1.3f).sp, + fontWeight = FontWeight.SemiBold, + ) + } /** Material's stock scale; the base the app scale derives every slot from. */ private val platformDefaults = Typography() /** - * The Material type scale the whole app renders with. It is anchored on - * the reading tokens above instead of existing as an unrelated parallel - * system: [body] drives `bodyLarge` (the chat reading size) and [caption] - * drives `bodySmall` (the metadata size). Only size and leading come from - * the tokens -- weight, tracking and family stay Material's -- and every - * slot without a token copies its platform default verbatim, so the many - * existing `MaterialTheme.typography` call sites stay pixel-identical - * while future token changes propagate through one place. + * The Material type scale the whole app renders with. [body] drives + * `bodyLarge` and [caption] drives `bodySmall`. Body slots drop Material's + * 0.25โ€“0.5sp tracking, which reads loose next to CJK and system UI text; + * title and label slots keep their platform defaults. */ val scale: Typography = Typography( bodyLarge = platformDefaults.bodyLarge.copy( fontSize = body.fontSize, lineHeight = body.lineHeight, + letterSpacing = 0.sp, ), + bodyMedium = platformDefaults.bodyMedium.copy(letterSpacing = 0.sp), bodySmall = platformDefaults.bodySmall.copy( fontSize = caption.fontSize, lineHeight = caption.lineHeight, + letterSpacing = 0.sp, ), ) } diff --git a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/Theme.kt b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/Theme.kt index d38968c0..1cd22cec 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/Theme.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/Theme.kt @@ -2,6 +2,7 @@ package app.hapi.companion.ui.theme import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.ColorScheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Typography import androidx.compose.material3.darkColorScheme @@ -10,20 +11,73 @@ import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +/** + * Neutral (hue-free) surface ladders mirroring iOS `HapiTheme.light/.dark`. + * Material's baseline schemes tint every surface lavender; HAPI keeps + * surfaces gray and lets only the accent roles carry color. [NeutralChatSurfaces] + * reapplies these over Material You so wallpaper hues never tint the transcript. + */ +private fun ColorScheme.withNeutralSurfaces(dark: Boolean): ColorScheme = if (dark) { + copy( + background = Color(0xFF0F1115), + onBackground = Color(0xFFE8EAED), + surface = Color(0xFF0F1115), + onSurface = Color(0xFFE8EAED), + surfaceVariant = Color(0xFF23272F), + onSurfaceVariant = Color(0xFFA8ADB8), + surfaceTint = Color(0xFF6E7481), + surfaceBright = Color(0xFF2A2E37), + surfaceDim = Color(0xFF0F1115), + surfaceContainerLowest = Color(0xFF0B0D10), + surfaceContainerLow = Color(0xFF14171C), + surfaceContainer = Color(0xFF181B22), + surfaceContainerHigh = Color(0xFF1E2129), + surfaceContainerHighest = Color(0xFF262A33), + outline = Color(0xFF6E7481), + outlineVariant = Color(0xFF2A2E37), + inverseSurface = Color(0xFFE8EAED), + inverseOnSurface = Color(0xFF1C1D22), + ) +} else { + copy( + background = Color(0xFFFFFFFF), + onBackground = Color(0xFF1C1D22), + surface = Color(0xFFFFFFFF), + onSurface = Color(0xFF1C1D22), + surfaceVariant = Color(0xFFEEF0F3), + onSurfaceVariant = Color(0xFF52555E), + surfaceTint = Color(0xFF8A8D96), + surfaceBright = Color(0xFFFFFFFF), + surfaceDim = Color(0xFFE2E4E8), + surfaceContainerLowest = Color(0xFFFFFFFF), + surfaceContainerLow = Color(0xFFF6F7F9), + surfaceContainer = Color(0xFFF1F3F5), + surfaceContainerHigh = Color(0xFFECEEF1), + surfaceContainerHighest = Color(0xFFE5E7EB), + outline = Color(0xFF8A8D96), + outlineVariant = Color(0xFFE5E7EB), + inverseSurface = Color(0xFF2B2D33), + inverseOnSurface = Color(0xFFF1F3F5), + ) +} + private val LightColorScheme = lightColorScheme( primary = Color(0xFF3D6837), secondary = Color(0xFF54634D), tertiary = Color(0xFF386569), -) +).withNeutralSurfaces(dark = false) private val DarkColorScheme = darkColorScheme( primary = Color(0xFFA3D397), + // Material's baseline onPrimary is purple; ink on the light-green accent. + onPrimary = Color(0xFF0F1115), secondary = Color(0xFFBCCBB2), tertiary = Color(0xFFA0CFD2), -) +).withNeutralSurfaces(dark = true) /** * Pure-black scheme for OLED panels (mirrors the web `[data-theme="oled"]` @@ -160,7 +214,10 @@ fun HapiTheme( } val extendedColors = presetPalette?.extendedColors(baseExtendedColors) ?: baseExtendedColors - CompositionLocalProvider(LocalHapiExtendedColors provides extendedColors) { + CompositionLocalProvider( + LocalHapiExtendedColors provides extendedColors, + LocalThemeSchemeSource provides schemeSource, + ) { MaterialTheme( colorScheme = colorScheme, typography = typography, @@ -168,3 +225,26 @@ fun HapiTheme( ) } } + +internal val LocalThemeSchemeSource = staticCompositionLocalOf { ThemeSchemeSource.StaticLight } + +/** + * Keeps conversation surfaces neutral under Material You: the wallpaper still + * drives accent roles, but the canvas, containers and on-surface text use the + * same gray ladder as the static schemes. Presets and OLED are deliberate + * palette choices and pass through unchanged. + */ +@Composable +fun NeutralChatSurfaces(content: @Composable () -> Unit) { + val source = LocalThemeSchemeSource.current + if (source !is ThemeSchemeSource.Dynamic) { + content() + return + } + MaterialTheme( + colorScheme = MaterialTheme.colorScheme.withNeutralSurfaces(source.dark), + typography = MaterialTheme.typography, + shapes = MaterialTheme.shapes, + content = content, + ) +} diff --git a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/ThemePresets.kt b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/ThemePresets.kt index 37e063cf..258ecd80 100644 --- a/android/app/src/main/kotlin/app/hapi/companion/ui/theme/ThemePresets.kt +++ b/android/app/src/main/kotlin/app/hapi/companion/ui/theme/ThemePresets.kt @@ -273,6 +273,9 @@ fun ThemePresetPalette.extendedColors(base: HapiExtendedColors): HapiExtendedCol divider = border, link = accent, hint = hint, + textSecondary = mix(hint, foreground, 0.35), + cardSurface = surface, + composerSurface = if (isDark) surfaceHover else background, ) /** Card-face preview colors for the preset picker (web `COLOR_THEME_OPTIONS`). */ diff --git a/android/app/src/main/res/drawable/ic_sym_add.xml b/android/app/src/main/res/drawable/ic_sym_add.xml new file mode 100644 index 00000000..20eddc93 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_add.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_arrow_outward.xml b/android/app/src/main/res/drawable/ic_sym_arrow_outward.xml new file mode 100644 index 00000000..af86672b --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_arrow_outward.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_arrow_upward.xml b/android/app/src/main/res/drawable/ic_sym_arrow_upward.xml new file mode 100644 index 00000000..f2ba184c --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_arrow_upward.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_assignment.xml b/android/app/src/main/res/drawable/ic_sym_assignment.xml new file mode 100644 index 00000000..4d45b127 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_assignment.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_attach_file.xml b/android/app/src/main/res/drawable/ic_sym_attach_file.xml new file mode 100644 index 00000000..555c7716 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_attach_file.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_bolt.xml b/android/app/src/main/res/drawable/ic_sym_bolt.xml new file mode 100644 index 00000000..8d4ed131 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_bolt.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_build.xml b/android/app/src/main/res/drawable/ic_sym_build.xml new file mode 100644 index 00000000..a8bbf4a7 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_build.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_cancel.xml b/android/app/src/main/res/drawable/ic_sym_cancel.xml new file mode 100644 index 00000000..07c16d58 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_cancel.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_chat_bubble.xml b/android/app/src/main/res/drawable/ic_sym_chat_bubble.xml new file mode 100644 index 00000000..d9b5de1b --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_chat_bubble.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_check.xml b/android/app/src/main/res/drawable/ic_sym_check.xml new file mode 100644 index 00000000..d1d20175 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_check.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_check_circle.xml b/android/app/src/main/res/drawable/ic_sym_check_circle.xml new file mode 100644 index 00000000..1ba85f0b --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_check_circle.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_chevron_right.xml b/android/app/src/main/res/drawable/ic_sym_chevron_right.xml new file mode 100644 index 00000000..ab01b6a8 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_chevron_right.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_close.xml b/android/app/src/main/res/drawable/ic_sym_close.xml new file mode 100644 index 00000000..1ec994fa --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_close.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_content_copy.xml b/android/app/src/main/res/drawable/ic_sym_content_copy.xml new file mode 100644 index 00000000..02881f11 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_content_copy.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_description.xml b/android/app/src/main/res/drawable/ic_sym_description.xml new file mode 100644 index 00000000..6f28062e --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_description.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_edit.xml b/android/app/src/main/res/drawable/ic_sym_edit.xml new file mode 100644 index 00000000..0c679c62 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_edit.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_error.xml b/android/app/src/main/res/drawable/ic_sym_error.xml new file mode 100644 index 00000000..bdfb9dfd --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_error.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_expand_more.xml b/android/app/src/main/res/drawable/ic_sym_expand_more.xml new file mode 100644 index 00000000..b8a66942 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_expand_more.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_extension.xml b/android/app/src/main/res/drawable/ic_sym_extension.xml new file mode 100644 index 00000000..c0d7f754 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_extension.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_group.xml b/android/app/src/main/res/drawable/ic_sym_group.xml new file mode 100644 index 00000000..b2f993c0 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_group.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_help.xml b/android/app/src/main/res/drawable/ic_sym_help.xml new file mode 100644 index 00000000..7aa003b8 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_help.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_hourglass_empty.xml b/android/app/src/main/res/drawable/ic_sym_hourglass_empty.xml new file mode 100644 index 00000000..dbeaeb14 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_hourglass_empty.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_image.xml b/android/app/src/main/res/drawable/ic_sym_image.xml new file mode 100644 index 00000000..5a0bc6b9 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_image.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_language.xml b/android/app/src/main/res/drawable/ic_sym_language.xml new file mode 100644 index 00000000..cb8dc539 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_language.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_lightbulb.xml b/android/app/src/main/res/drawable/ic_sym_lightbulb.xml new file mode 100644 index 00000000..b3ec635b --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_lightbulb.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_mic.xml b/android/app/src/main/res/drawable/ic_sym_mic.xml new file mode 100644 index 00000000..0dbe9d3f --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_mic.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_more_horiz.xml b/android/app/src/main/res/drawable/ic_sym_more_horiz.xml new file mode 100644 index 00000000..a2f00ba7 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_more_horiz.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_refresh.xml b/android/app/src/main/res/drawable/ic_sym_refresh.xml new file mode 100644 index 00000000..983c904b --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_refresh.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_schedule.xml b/android/app/src/main/res/drawable/ic_sym_schedule.xml new file mode 100644 index 00000000..19772b11 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_schedule.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_search.xml b/android/app/src/main/res/drawable/ic_sym_search.xml new file mode 100644 index 00000000..a1b51682 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_search.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_send.xml b/android/app/src/main/res/drawable/ic_sym_send.xml new file mode 100644 index 00000000..dfd202fc --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_send.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_stop_filled.xml b/android/app/src/main/res/drawable/ic_sym_stop_filled.xml new file mode 100644 index 00000000..e22d07d3 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_stop_filled.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_subdirectory_arrow_right.xml b/android/app/src/main/res/drawable/ic_sym_subdirectory_arrow_right.xml new file mode 100644 index 00000000..7a5a89fa --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_subdirectory_arrow_right.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_terminal.xml b/android/app/src/main/res/drawable/ic_sym_terminal.xml new file mode 100644 index 00000000..431052f0 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_terminal.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_visibility.xml b/android/app/src/main/res/drawable/ic_sym_visibility.xml new file mode 100644 index 00000000..a5576c78 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_visibility.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_sym_warning.xml b/android/app/src/main/res/drawable/ic_sym_warning.xml new file mode 100644 index 00000000..13833718 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_sym_warning.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/font/jetbrains_mono_bold.ttf b/android/app/src/main/res/font/jetbrains_mono_bold.ttf new file mode 100644 index 00000000..f78f84fb Binary files /dev/null and b/android/app/src/main/res/font/jetbrains_mono_bold.ttf differ diff --git a/android/app/src/main/res/font/jetbrains_mono_regular.ttf b/android/app/src/main/res/font/jetbrains_mono_regular.ttf new file mode 100644 index 00000000..70d2ec9e Binary files /dev/null and b/android/app/src/main/res/font/jetbrains_mono_regular.ttf differ diff --git a/android/app/src/test/kotlin/app/hapi/companion/specimens/Specimen.kt b/android/app/src/test/kotlin/app/hapi/companion/specimens/Specimen.kt new file mode 100644 index 00000000..e1e78230 --- /dev/null +++ b/android/app/src/test/kotlin/app/hapi/companion/specimens/Specimen.kt @@ -0,0 +1,45 @@ +package app.hapi.companion.specimens + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.test.junit4.ComposeContentTestRule +import androidx.compose.ui.test.onRoot +import androidx.compose.ui.unit.dp +import app.hapi.companion.ui.theme.HapiTheme +import com.github.takahirom.roborazzi.captureRoboImage + +/** + * Deterministic visual specimens (fake data, no hub): the Android analogue of + * the iOS `TypographySnapshotTests` captures. Plain `testDebugUnitTest` runs + * compose every specimen as a smoke test; images are only written by + * `./gradlew :app:recordRoborazziDebug`, into `app/build/outputs/roborazzi/`. + * They are review aids, not committed goldens or store screenshots. + */ +internal enum class SpecimenTheme(val dark: Boolean, val oled: Boolean) { + Light(dark = false, oled = false), + Dark(dark = true, oled = false), + Oled(dark = true, oled = true), +} + +/** Phone-width canvas (Pixel 8 / 412dp) with the transcript's 16dp margins. */ +@Composable +internal fun Specimen(theme: SpecimenTheme, content: @Composable () -> Unit) { + HapiTheme(darkTheme = theme.dark, dynamicColor = false, oled = theme.oled) { + Surface(color = MaterialTheme.colorScheme.background) { + Box(Modifier.width(412.dp).padding(horizontal = 16.dp, vertical = 20.dp)) { + Column { content() } + } + } + } +} + +internal fun ComposeContentTestRule.captureSpecimen(name: String, theme: SpecimenTheme) { + waitForIdle() + onRoot().captureRoboImage("build/outputs/roborazzi/specimens/$name-${theme.name.lowercase()}.png") +} diff --git a/android/app/src/test/kotlin/app/hapi/companion/ui/theme/HapiTypographyScaleTest.kt b/android/app/src/test/kotlin/app/hapi/companion/ui/theme/HapiTypographyScaleTest.kt index 9e171446..25d4172a 100644 --- a/android/app/src/test/kotlin/app/hapi/companion/ui/theme/HapiTypographyScaleTest.kt +++ b/android/app/src/test/kotlin/app/hapi/companion/ui/theme/HapiTypographyScaleTest.kt @@ -2,14 +2,15 @@ package app.hapi.companion.ui.theme import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.unit.sp import kotlin.test.Test import kotlin.test.assertEquals /** * Contract of the app-wide Material type scale: the reading tokens drive - * their anchored slots, every other slot stays byte-for-byte at the Material - * platform default, and the monospace code token never reaches a reading slot. + * their anchored slots, body slots drop Material's tracking, every other slot + * stays byte-for-byte at the Material platform default, and the bundled + * monospace code family never reaches a reading slot. */ class HapiTypographyScaleTest { @@ -30,16 +31,23 @@ class HapiTypographyScaleTest { } @Test - fun `anchored slots keep Material weight, tracking and family`() { + fun `anchored slots keep Material weight and family`() { val scale = HapiTypography.scale assertEquals(platformDefaults.bodyLarge.fontWeight, scale.bodyLarge.fontWeight) - assertEquals(platformDefaults.bodyLarge.letterSpacing, scale.bodyLarge.letterSpacing) assertEquals(platformDefaults.bodyLarge.fontFamily, scale.bodyLarge.fontFamily) assertEquals(platformDefaults.bodySmall.fontWeight, scale.bodySmall.fontWeight) - assertEquals(platformDefaults.bodySmall.letterSpacing, scale.bodySmall.letterSpacing) assertEquals(platformDefaults.bodySmall.fontFamily, scale.bodySmall.fontFamily) } + @Test + fun `body slots drop Material tracking, all else stays default`() { + val scale = HapiTypography.scale + assertEquals(0.sp, scale.bodyLarge.letterSpacing) + assertEquals(0.sp, scale.bodyMedium.letterSpacing) + assertEquals(0.sp, scale.bodySmall.letterSpacing) + assertEquals(platformDefaults.bodyMedium.copy(letterSpacing = 0.sp), scale.bodyMedium) + } + @Test fun `slots without a token stay exactly at the platform default`() { val scale = HapiTypography.scale @@ -53,7 +61,6 @@ class HapiTypographyScaleTest { "titleLarge" to (platformDefaults.titleLarge to scale.titleLarge), "titleMedium" to (platformDefaults.titleMedium to scale.titleMedium), "titleSmall" to (platformDefaults.titleSmall to scale.titleSmall), - "bodyMedium" to (platformDefaults.bodyMedium to scale.bodyMedium), "labelLarge" to (platformDefaults.labelLarge to scale.labelLarge), "labelMedium" to (platformDefaults.labelMedium to scale.labelMedium), "labelSmall" to (platformDefaults.labelSmall to scale.labelSmall), @@ -65,7 +72,7 @@ class HapiTypographyScaleTest { @Test fun `code token stays monospaced and out of the reading slots`() { - assertEquals(FontFamily.Monospace, HapiTypography.code.fontFamily) + assertEquals(HapiTypography.monoFamily, HapiTypography.code.fontFamily) // Reading slots keep whatever family Material ships with (SansSerif // in this version); the monospace family lives only in the code token. assertEquals(platformDefaults.bodyLarge.fontFamily, HapiTypography.scale.bodyLarge.fontFamily) diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index 2f86a88e..55066c70 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -42,6 +42,11 @@ fragment = "1.8.5" # Per-app locales (B-M5a): AppCompatDelegate.setApplicationLocales back to # API 26 (appcompat 1.7.1, 2025-06, on Google Maven). appcompat = "1.7.1" +# Visual specimens (JVM screenshots, see README "Visual specimens"): +# Robolectric 4.17 renders SDK 36 with native graphics; Roborazzi captures. +robolectric = "4.17" +# 1.61+ ships Kotlin 2.3 metadata, unreadable by this Kotlin 2.1 build. +roborazzi = "1.60.0" [libraries] # AndroidX @@ -99,6 +104,9 @@ junit = { group = "junit", name = "junit", version.ref = "junit" } kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" } okhttp-mockwebserver = { group = "com.squareup.okhttp3", name = "mockwebserver", version.ref = "okhttp" } turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" } +robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" } +roborazzi = { group = "io.github.takahirom.roborazzi", name = "roborazzi", version.ref = "roborazzi" } +roborazzi-compose = { group = "io.github.takahirom.roborazzi", name = "roborazzi-compose", version.ref = "roborazzi" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } @@ -109,3 +117,4 @@ kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "ko kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } # Applied conditionally in :app (only when google-services.json exists). google-services = { id = "com.google.gms.google-services", version.ref = "googleServices" } +roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }