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
Expand Up @@ -103,8 +103,8 @@ class StoreScreenshotTest {
@Test
fun settings() {
waitForHome()
tapDesc(SETTINGS)
waitForText(SETTINGS)
tapDesc(MORE_OPTIONS)
tapText(SETTINGS)
waitForText(SERVERS)
settle()
capture("05-settings.png")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package dev.opencode.mobile.ui.components

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.getUnclippedBoundsInRoot
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.width
import dev.opencode.mobile.theme.OpenCodeTheme
import dev.opencode.mobile.ui.icons.OpenCodeIcons
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test

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

@Test
fun dividerKeepsThePanelAtItsContentWidth() {
composeTestRule.setContent {
OpenCodeTheme(darkTheme = false) {
OpenCodeTopBarOverflowHost(
expanded = true,
onDismissRequest = {},
entries =
listOf(
OpenCodeOverflowMenuEntry(
title = "Archived sessions",
icon = OpenCodeIcons.Archive,
subtitle = "4 in All projects",
onClick = {},
testTag = ARCHIVED_TAG,
),
OpenCodeOverflowMenuEntry(
title = "Settings",
icon = OpenCodeIcons.Settings,
onClick = {},
testTag = SETTINGS_TAG,
dividerAbove = true,
),
),
) {
OpenCodeTopBar(title = "Sessions")
}
}
}

val archived = composeTestRule.onNodeWithTag(ARCHIVED_TAG).getUnclippedBoundsInRoot()
val settings = composeTestRule.onNodeWithTag(SETTINGS_TAG).getUnclippedBoundsInRoot()
val metrics = composeTestRule.activity.resources.displayMetrics
val windowWidth = metrics.widthPixels / metrics.density
assertTrue(
"Menu row is ${archived.width} wide in a $windowWidth dp window",
archived.width.value < windowWidth - 64f,
)
// The tag sits inside the row padding, so the 200 dp minimum reads a little narrower.
assertTrue(archived.width >= 170.dp)
// Every row spans the panel, so the whole row takes the tap.
assertEquals(archived.width.value, settings.width.value, 0.5f)
}

private companion object {
const val ARCHIVED_TAG = "overflowArchived"
const val SETTINGS_TAG = "overflowSettings"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ object ProductAnalytics {

// Home
const val HOME_OPEN_SETTINGS = "home_open_settings"
const val HOME_OPEN_MENU = "home_open_menu"
const val HOME_OPEN_TERMINAL = "home_open_terminal"
const val HOME_PULL_TO_REFRESH = "home_pull_to_refresh"
const val HOME_OPEN_SESSION = "home_open_session"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fun OverflowMenuGalleryScreen(modifier: Modifier = Modifier) {
var entriesEnabled by rememberSaveable { mutableStateOf(true) }
var selectionRowsEnabled by rememberSaveable { mutableStateOf(false) }
var showDestructive by rememberSaveable { mutableStateOf(false) }
var showDivider by rememberSaveable { mutableStateOf(false) }
var itemCount by rememberSaveable { mutableStateOf(2) }

val entries =
Expand Down Expand Up @@ -60,6 +61,7 @@ fun OverflowMenuGalleryScreen(modifier: Modifier = Modifier) {
title = "Copy session ID",
icon = if (selectionRowsEnabled) null else OpenCodeIcons.ContentCopy,
enabled = entriesEnabled,
dividerAbove = showDivider,
onClick = { menuExpanded = false },
),
)
Expand Down Expand Up @@ -126,6 +128,11 @@ fun OverflowMenuGalleryScreen(modifier: Modifier = Modifier) {
selected = showDestructive,
onClick = { showDestructive = !showDestructive },
)
OpenCodeChoiceBadge(
label = "Divider",
selected = showDivider,
onClick = { showDivider = !showDivider },
)
}

ControlGroup(title = "Entry count") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
Expand Down Expand Up @@ -57,6 +60,7 @@ private val OverflowMenuEntryMinHeight = 48.dp
private val OverflowMenuEntryPaddingHorizontal = 12.dp
private val OverflowMenuEntryIconSize = 20.dp
private val OverflowMenuEntryIconSpacing = 12.dp
private val OverflowMenuDividerPaddingVertical = 4.dp
private val OverflowMenuAnchorEndInset = 4.dp
private val OverflowMenuAnchorTopOffset = 8.dp
private val OverflowMenuEntryTextMaxWidth = 240.dp
Expand All @@ -72,6 +76,8 @@ data class OpenCodeOverflowMenuEntry(
/** Secondary line under the title, such as why the entry is disabled. */
val subtitle: String? = null,
val testTag: String? = null,
/** Draws a divider above the entry, starting a new group. */
val dividerAbove: Boolean = false,
)

@Composable
Expand Down Expand Up @@ -249,14 +255,21 @@ private fun OpenCodeOverflowMenuPanel(
border = BorderStroke(1.dp, openCodeColor("border-weak-base")),
shadowElevation = 0.dp,
) {
// As wide as the widest row: dividers and rows fill that width, not the popup window's.
Column(
modifier =
Modifier
.wrapContentWidth(Alignment.Start)
.widthIn(min = OverflowMenuMinWidth)
.width(IntrinsicSize.Max)
.padding(vertical = OverflowMenuPaddingVertical),
) {
entries.forEach { entry ->
if (entry.dividerAbove) {
HorizontalDivider(
modifier = Modifier.padding(vertical = OverflowMenuDividerPaddingVertical),
thickness = 1.dp,
color = openCodeColor("border-weak-base"),
)
}
Comment thread
ivanfenenko marked this conversation as resolved.
Resolved
OverflowMenuEntryRow(
entry = entry,
reservesIconColumn = reservesIconColumn,
Expand Down Expand Up @@ -290,6 +303,7 @@ private fun OverflowMenuEntryRow(
Row(
modifier =
Modifier
.fillMaxWidth()
.widthIn(min = OverflowMenuMinWidth)
.defaultMinSize(minHeight = OverflowMenuEntryMinHeight)
.openCodeFocusRing(OpenCodeSmallShape, entry.enabled)
Expand Down Expand Up @@ -397,6 +411,44 @@ private fun OpenCodeOverflowMenuDarkPreview() {
}
}

/** Grouped entries with subtitles: the panel keeps its content width with a divider. */
@Preview(showBackground = true, widthDp = 411)
@Composable
private fun OpenCodeOverflowMenuGroupedPreview() {
OpenCodeTheme(darkTheme = false) {
OpenCodeTopBarOverflowHost(
expanded = true,
onDismissRequest = {},
entries = previewGroupedOverflowMenuEntries(),
) {
OpenCodeTopBar(title = "Sessions", showDivider = true)
}
}
}

private fun previewGroupedOverflowMenuEntries(): List<OpenCodeOverflowMenuEntry> =
listOf(
OpenCodeOverflowMenuEntry(title = "Search sessions", icon = OpenCodeIcons.Search, onClick = {}),
OpenCodeOverflowMenuEntry(
title = "Archived sessions",
icon = OpenCodeIcons.Archive,
subtitle = "4 in All projects",
onClick = {},
),
OpenCodeOverflowMenuEntry(
title = "Worktrees",
icon = OpenCodeIcons.CallSplit,
subtitle = "3 across 2 projects",
onClick = {},
),
OpenCodeOverflowMenuEntry(
title = "Settings",
icon = OpenCodeIcons.Settings,
dividerAbove = true,
onClick = {},
),
)

private fun previewOverflowMenuEntries(): List<OpenCodeOverflowMenuEntry> =
listOf(
OpenCodeOverflowMenuEntry(
Expand All @@ -421,6 +473,7 @@ private fun previewOverflowMenuEntries(): List<OpenCodeOverflowMenuEntry> =
title = "Delete",
icon = OpenCodeIcons.Close,
destructive = true,
dividerAbove = true,
onClick = {},
),
)
26 changes: 26 additions & 0 deletions android/app/src/main/java/dev/opencode/mobile/ui/main/HomeMenu.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.opencode.mobile.ui.main

import dev.opencode.mobile.ui.components.OpenCodeOverflowMenuEntry
import dev.opencode.mobile.ui.icons.OpenCodeIcons

/**
* Home's top-bar ⋯ menu. Feature entries come first, in the order given; Settings always closes
* the menu, after a divider when anything sits above it.
*/
object HomeMenu {
const val SETTINGS_TEST_TAG = "homeMenuSettings"

fun entries(
features: List<OpenCodeOverflowMenuEntry>,
settingsTitle: String,
onSettingsClick: () -> Unit,
): List<OpenCodeOverflowMenuEntry> =
features +
OpenCodeOverflowMenuEntry(
title = settingsTitle,
icon = OpenCodeIcons.Settings,
onClick = onSettingsClick,
testTag = SETTINGS_TEST_TAG,
dividerAbove = features.isNotEmpty(),
)
}
91 changes: 56 additions & 35 deletions android/app/src/main/java/dev/opencode/mobile/ui/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import dev.opencode.mobile.ui.components.OpenCodeSnackbarMessage
import dev.opencode.mobile.ui.components.OpenCodeStatusStack
import dev.opencode.mobile.ui.components.OpenCodeTopBar
import dev.opencode.mobile.ui.components.OpenCodeTopBarAction
import dev.opencode.mobile.ui.components.OpenCodeTopBarOverflowHost
import dev.opencode.mobile.ui.components.OpenCodeTopBarSubtitleAccessory
import dev.opencode.mobile.ui.components.SessionList
import dev.opencode.mobile.ui.components.SessionListFilterTab
Expand Down Expand Up @@ -321,6 +322,20 @@ internal fun MainScreen(
}

var selectedFilterId by rememberSaveable { mutableStateOf(SessionListFilterTab.ALL_ID) }
var homeMenuExpanded by rememberSaveable { mutableStateOf(false) }
// Feature entries go in `features`, top to bottom; HomeMenu adds Settings last.
val homeMenuEntries =
HomeMenu.entries(
features = emptyList(),
settingsTitle = stringResource(R.string.common_settings),
onSettingsClick = {
ProductAnalytics.logUserAction(
screenId = ProductAnalytics.Screen.HOME,
actionId = ProductAnalytics.Action.HOME_OPEN_SETTINGS,
)
onSettingsClick()
},
)
val worktreesEnabled = HomeDisplayPreferences.showsWorktrees
val loaded = uiState as? MainScreenUiState.Loaded
val homeSessions = remember(loaded, worktreesEnabled) { loaded?.homeSessions(worktreesEnabled).orEmpty() }
Expand Down Expand Up @@ -377,50 +392,56 @@ internal fun MainScreen(

Box(modifier = modifier.fillMaxSize()) {
Column(modifier = Modifier.fillMaxSize()) {
OpenCodeTopBar(
title = serversChrome.title.resolve(),
onTitleClick = if (serversChrome.isSwitcher) onTitleClick else null,
titleMenuExpanded = serversChrome.sheetVisible,
subtitleAccessory =
if (showsLiveUpdatesStatus(uiState)) {
OpenCodeTopBarSubtitleAccessory.StatusDot(
liveUpdatesConnectionStatus.toOpenCodeSessionConnectionStatus(),
)
} else {
null
},
actions =
buildList {
if (showTerminalAction) {
OpenCodeTopBarOverflowHost(
expanded = homeMenuExpanded,
onDismissRequest = { homeMenuExpanded = false },
entries = homeMenuEntries,
) {
OpenCodeTopBar(
title = serversChrome.title.resolve(),
onTitleClick = if (serversChrome.isSwitcher) onTitleClick else null,
titleMenuExpanded = serversChrome.sheetVisible,
subtitleAccessory =
if (showsLiveUpdatesStatus(uiState)) {
OpenCodeTopBarSubtitleAccessory.StatusDot(
liveUpdatesConnectionStatus.toOpenCodeSessionConnectionStatus(),
)
} else {
null
},
actions =
buildList {
if (showTerminalAction) {
add(
OpenCodeTopBarAction.Icon(
imageVector = OpenCodeIcons.Terminal,
contentDescription = stringResource(R.string.common_terminal),
onClick = {
ProductAnalytics.logUserAction(
screenId = ProductAnalytics.Screen.HOME,
actionId = ProductAnalytics.Action.HOME_OPEN_TERMINAL,
)
onTerminalClick()
},
),
)
}
add(
OpenCodeTopBarAction.Icon(
imageVector = OpenCodeIcons.Terminal,
contentDescription = stringResource(R.string.common_terminal),
imageVector = OpenCodeIcons.MoreVert,
contentDescription = stringResource(R.string.home_more_options),
onClick = {
ProductAnalytics.logUserAction(
screenId = ProductAnalytics.Screen.HOME,
actionId = ProductAnalytics.Action.HOME_OPEN_TERMINAL,
actionId = ProductAnalytics.Action.HOME_OPEN_MENU,
)
onTerminalClick()
homeMenuExpanded = true
},
),
)
}
add(
OpenCodeTopBarAction.Icon(
imageVector = OpenCodeIcons.Settings,
contentDescription = stringResource(R.string.common_settings),
onClick = {
ProductAnalytics.logUserAction(
screenId = ProductAnalytics.Screen.HOME,
actionId = ProductAnalytics.Action.HOME_OPEN_SETTINGS,
)
onSettingsClick()
},
),
)
},
)
},
)
}

val activeServerId = serversChrome.active?.id.orEmpty()
AnimatedContent(
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<string name="home_servers_sheet_using_now">Using now</string>
<string name="home_servers_sheet_switch_to">Switch to</string>
<string name="home_servers_sheet_manage">Manage in Settings</string>
<string name="home_more_options">More options</string>
<string name="home_new_session">New session</string>
<string name="home_no_projects">No projects</string>
<string name="home_filter_sheet_title">Filter by project</string>
Expand Down
Loading