Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.opencode.mobile.ui.components

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test

class ReviewChangesPillTest {
@get:Rule val composeTestRule = createAndroidComposeRule<ComponentActivity>()

@Test
fun exposesPluralizedAccessibilityAndBlocksDisabledClick() {
var clickCount = 0
composeTestRule.setContent {
OpenCodeReviewChangesPill(
variant = OpenCodeReviewChangesPillVariant.LatestTurn,
changedFileCount = 1,
onClick = { clickCount += 1 },
)
OpenCodeReviewChangesPill(
variant = OpenCodeReviewChangesPillVariant.LatestTurn,
changedFileCount = 4,
enabled = false,
onClick = { clickCount += 1 },
)
}

composeTestRule
.onNodeWithContentDescription("Review 1 changed file")
.assertIsDisplayed()
.assertIsEnabled()
.performClick()
composeTestRule
.onNodeWithContentDescription("Review 4 changed files")
.assertIsDisplayed()
.assertIsNotEnabled()
.performClick()

composeTestRule.runOnIdle { assertEquals(1, clickCount) }
}
}
2 changes: 2 additions & 0 deletions android/app/src/main/java/dev/opencode/mobile/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import dev.opencode.mobile.ui.componentgallery.components.OutgoingMessageGallery
import dev.opencode.mobile.ui.componentgallery.components.OverflowMenuGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ProjectSessionSelectorGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.RenderedMarkdownGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ReviewChangesPillGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SessionComposerGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SessionStatusBarGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.TextInputGalleryScreen
Expand Down Expand Up @@ -170,6 +171,7 @@ fun MainNavigation() {
ComponentGalleryEntryId.ListItem -> ListItemGalleryScreen()
ComponentGalleryEntryId.ChoiceBadge -> ChoiceBadgeGalleryScreen()
ComponentGalleryEntryId.ActionPill -> ActionPillGalleryScreen()
ComponentGalleryEntryId.ReviewChangesPill -> ReviewChangesPillGalleryScreen()
ComponentGalleryEntryId.UnifiedDiff -> UnifiedDiffGalleryScreen()
ComponentGalleryEntryId.Button -> ButtonGalleryScreen()
ComponentGalleryEntryId.TextInput -> TextInputGalleryScreen()
Expand Down
3 changes: 1 addition & 2 deletions android/app/src/main/java/dev/opencode/mobile/theme/Color.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.opencode.mobile.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

Expand All @@ -10,7 +9,7 @@ import androidx.compose.ui.graphics.Color
*/
@Composable
fun openCodeColor(token: String): Color {
val isDark = isSystemInDarkTheme()
val isDark = LocalOpenCodeDarkTheme.current
val hex = if (isDark) ThemeManager.resolvedDark[token] else ThemeManager.resolvedLight[token]
return ThemeResolver.parseHexColor(hex)
}
Expand Down
8 changes: 7 additions & 1 deletion android/app/src/main/java/dev/opencode/mobile/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import androidx.compose.material3.dynamicDarkColorScheme
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

val LocalOpenCodeDarkTheme = staticCompositionLocalOf { false }

@Composable
fun OpenCodeTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
Expand Down Expand Up @@ -92,7 +96,9 @@ fun OpenCodeTheme(
}
}

MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content)
CompositionLocalProvider(LocalOpenCodeDarkTheme provides darkTheme) {
MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content)
}
}

private fun parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class ComponentGalleryEntryId {
ListItem,
ChoiceBadge,
ActionPill,
ReviewChangesPill,
UnifiedDiff,
Button,
TextInput,
Expand Down Expand Up @@ -100,6 +101,12 @@ val ComponentGalleryEntries =
description = "Floating pill for contextual overlay actions such as scroll to end.",
category = ComponentGalleryCategory.Components,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.ReviewChangesPill,
title = "Review Changes Pill",
description = "Contextual shortcut to files changed by the latest completed turn.",
category = ComponentGalleryCategory.Components,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.UnifiedDiff,
title = "Unified Diff",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dev.opencode.mobile.ui.componentgallery.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.ui.components.OpenCodeChoiceBadge
import dev.opencode.mobile.ui.components.OpenCodeReviewChangesPill
import dev.opencode.mobile.ui.components.OpenCodeReviewChangesPillVariant

@Composable
fun ReviewChangesPillGalleryScreen(modifier: Modifier = Modifier) {
var enabled by rememberSaveable { mutableStateOf(true) }
var changedFileCount by rememberSaveable { mutableIntStateOf(1) }

Column(modifier = modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text(text = "Interactive", style = MaterialTheme.typography.titleMedium)
Text(
text = "Review singular, plural, and disabled latest-turn states.",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OpenCodeChoiceBadge("1 file", changedFileCount == 1, onClick = { changedFileCount = 1 })
OpenCodeChoiceBadge("4 files", changedFileCount == 4, onClick = { changedFileCount = 4 })
OpenCodeChoiceBadge("Enabled", enabled, onClick = { enabled = !enabled })
}
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
OpenCodeReviewChangesPill(
variant = OpenCodeReviewChangesPillVariant.LatestTurn,
changedFileCount = changedFileCount,
enabled = enabled,
onClick = {},
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package dev.opencode.mobile.ui.components

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.theme.OpenCodeTheme
import dev.opencode.mobile.theme.openCodeColor
import dev.opencode.mobile.ui.icons.OpenCodeIcons

private val ReviewChangesPillShape = RoundedCornerShape(percent = 50)

fun reviewChangesPillLabel(changedFileCount: Int): String =
"Review $changedFileCount changed ${if (changedFileCount == 1) "file" else "files"}"

enum class OpenCodeReviewChangesPillVariant {
LatestTurn,
}

enum class ReviewChangesPillPreviewCase(
val changedFileCount: Int,
val enabled: Boolean,
val darkTheme: Boolean,
) {
SingularLight(1, true, false),
SingularDark(1, true, true),
PluralLight(4, true, false),
PluralDark(4, true, true),
DisabledLight(4, false, false),
DisabledDark(4, false, true),
}

@Composable
private fun ReviewChangesPillPreview(case: ReviewChangesPillPreviewCase) {
OpenCodeTheme(darkTheme = case.darkTheme) {
OpenCodeReviewChangesPill(
variant = OpenCodeReviewChangesPillVariant.LatestTurn,
changedFileCount = case.changedFileCount,
enabled = case.enabled,
onClick = {},
)
}
}

@Composable
fun OpenCodeReviewChangesPill(
variant: OpenCodeReviewChangesPillVariant,
changedFileCount: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
) {
require(changedFileCount > 0) { "Review Changes Pill requires a positive file count" }
val label =
when (variant) {
OpenCodeReviewChangesPillVariant.LatestTurn -> reviewChangesPillLabel(changedFileCount)
}
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val contentColor =
if (enabled) openCodeColor("text-strong") else MaterialTheme.colorScheme.onSurfaceVariant
val iconColor =
if (enabled) openCodeColor("icon-strong-base") else MaterialTheme.colorScheme.onSurfaceVariant
val containerColor =
if (enabled && isPressed) openCodeColor("surface-raised-base-hover") else openCodeColor("surface-raised-base")

Surface(
onClick = onClick,
enabled = enabled,
modifier =
modifier
.defaultMinSize(minHeight = 36.dp)
.semantics { contentDescription = label },
shape = ReviewChangesPillShape,
color = containerColor,
contentColor = contentColor,
border = BorderStroke(1.dp, openCodeColor("border-weaker-base")),
shadowElevation = if (enabled) 4.dp else 0.dp,
interactionSource = interactionSource,
) {
Row(
modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp),
horizontalArrangement = Arrangement.spacedBy(6.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
imageVector = OpenCodeIcons.Description,
contentDescription = null,
modifier = Modifier.size(16.dp),
tint = iconColor,
)
Text(text = label, style = MaterialTheme.typography.labelLarge)
}
}
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeReviewChangesPillSingularLightPreview() {
ReviewChangesPillPreview(ReviewChangesPillPreviewCase.SingularLight)
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeReviewChangesPillSingularDarkPreview() {
ReviewChangesPillPreview(ReviewChangesPillPreviewCase.SingularDark)
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeReviewChangesPillPluralLightPreview() {
ReviewChangesPillPreview(ReviewChangesPillPreviewCase.PluralLight)
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeReviewChangesPillPluralDarkPreview() {
ReviewChangesPillPreview(ReviewChangesPillPreviewCase.PluralDark)
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeReviewChangesPillDisabledLightPreview() {
ReviewChangesPillPreview(ReviewChangesPillPreviewCase.DisabledLight)
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeReviewChangesPillDisabledDarkPreview() {
ReviewChangesPillPreview(ReviewChangesPillPreviewCase.DisabledDark)
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ fun SessionChatScreen(
messages = uiState.messages,
isRefreshing = uiState.isRefreshing,
errorMessage = uiState.errorMessage,
reviewChangesFileCount = uiState.reviewChangesFileCount,
onRefresh = viewModel::refreshMessages,
onReviewChangesClick = {
uiState.reviewChangesNavigationTarget(worktree)?.let(onReviewChangesClick)
},
onMessageActionsTap = { messageActionsTarget = it },
),
modifier = Modifier.weight(1f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ data class SessionChatUiState(
val permissionQueueCount: Int = 0,
val permissionSubmitting: Boolean = false,
val permissionErrorMessage: String? = null,
val reviewChangesMessageId: String? = null,
val reviewChangesFileCount: Int? = null,
) {
val latestCompletedUserMessageId: String?
get() {
Expand All @@ -70,6 +72,17 @@ data class SessionChatUiState(
initialSource = ChangeSource.WorkingTree,
)

fun reviewChangesNavigationTarget(worktree: String): ChangesNavigationTarget? {
val messageId = reviewChangesMessageId ?: return null
if ((reviewChangesFileCount ?: 0) <= 0) return null
return ChangesNavigationTarget(
sessionId = sessionId,
worktree = worktree,
messageId = messageId,
initialSource = ChangeSource.LastTurn,
)
}

companion object {
fun initial(
sessionId: String,
Expand All @@ -83,6 +96,14 @@ data class SessionChatUiState(
}
}

object ReviewChangesPillVisibility {
fun shouldShow(
fileCount: Int?,
isPinnedToEnd: Boolean,
showScrollToEnd: Boolean,
): Boolean = (fileCount ?: 0) > 0 && isPinnedToEnd && !showScrollToEnd
}

data class ChangesNavigationTarget(
val sessionId: String,
val worktree: String,
Expand All @@ -109,9 +130,15 @@ data class SessionInfoRegionState(
val sessionId: String = "",
val sessionTitle: String = "",
val sessionStatusLabel: String? = null,
val hasResolvedSessionStatus: Boolean = false,
val connectionStatus: SessionConnectionStatus = SessionConnectionStatus.Offline,
)

data class SessionChatReviewChangesRegionState(
val messageId: String? = null,
val fileCount: Int? = null,
)

data class LatestModelHint(
val providerId: String,
val modelId: String,
Expand Down
Loading