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
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 @@ -102,6 +102,7 @@ import dev.opencode.mobile.ui.componentgallery.components.RenderedMarkdownGaller
import dev.opencode.mobile.ui.componentgallery.components.ReorderableListGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ReviewChangesPillGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SectionHeaderGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.OptionCardGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SelectableCardGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ServerAddressInputGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SessionBranchPillGalleryScreen
Expand Down Expand Up @@ -759,6 +760,7 @@ fun MainNavigation() {
ComponentGalleryEntryId.ListItem -> ListItemGalleryScreen()
ComponentGalleryEntryId.SelectableCard ->
SelectableCardGalleryScreen()
ComponentGalleryEntryId.OptionCard -> OptionCardGalleryScreen()
ComponentGalleryEntryId.ListGroup -> ListGroupGalleryScreen()
ComponentGalleryEntryId.SectionHeader -> SectionHeaderGalleryScreen()
ComponentGalleryEntryId.ReorderableList -> ReorderableListGalleryScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ object ProductAnalytics {
const val SESSION_TOOL_GROUP = "session_tool_group"
const val SESSION_SKILLS = "session_skills"
const val SESSION_CHIP_TIMELINE_INTRO = "session_chip_timeline_intro"
const val SESSION_TIMELINE_STYLE_PICKER = "session_timeline_style_picker"
const val SESSION_TODOS = "session_todos"
const val SESSION_CONTEXT = "session_context"
const val CHANGES = "changes"
Expand Down Expand Up @@ -260,6 +261,8 @@ object ProductAnalytics {
const val CHIP_TIMELINE_INTRO_ENABLE = "chip_timeline_intro_enable"
const val CHIP_TIMELINE_INTRO_LATER = "chip_timeline_intro_later"
const val CHIP_TIMELINE_INTRO_NEVER = "chip_timeline_intro_never"
const val TIMELINE_STYLE_PICKER_USE = "timeline_style_picker_use"
const val TIMELINE_STYLE_PICKER_DISMISS = "timeline_style_picker_dismiss"
const val SESSION_TOOL_GROUP_BACK = "session_tool_group_back"
const val TODOS_DISMISS = "todos_dismiss"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ object ChipTimelineIntro {
/** Pause after the turn finishes so the user sees the result first. */
const val SETTLE_DELAY_MILLIS = 1_500L

/**
* Starting Chip timeline value, settled once per install: a fresh install
* starts on it; an install that already had the standard timeline keeps it
* and is offered the intro instead.
*/
fun startingChipTimeline(existingInstall: Boolean): Boolean = !existingInstall

fun shouldShow(
chipTimelineAvailable: Boolean,
chipTimelineOn: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.opencode.mobile.domain.preferences

import android.content.Context
import android.content.SharedPreferences
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -15,14 +16,17 @@ import dev.opencode.mobile.domain.message.FollowUpDelivery
*/
enum class SessionChatTimelineStyle(
val wireValue: String,
val title: String,
val subtitle: String,
) {
Standard("standard"),
Chips("chips"),
StepRail("step_rail"),
ActivityCard("activity_card"),
Standard("standard", "Standard", "Tool cards and groups between the agent's messages"),
Chips("chips", "Chips", "Tools as chips under the agent's narration"),
StepRail("step_rail", "Step Rail", "One line per step on a rail, live while the agent works"),
ActivityCard("activity_card", "Activity Card", "Running steps on one live card that folds into a summary"),
;

companion object {
/** In-memory style before an install is resolved and after Clear All Data. */
val DEFAULT = Standard

fun fromWire(value: String?): SessionChatTimelineStyle? = entries.firstOrNull { it.wireValue == value }
Expand All @@ -39,9 +43,9 @@ enum class SessionChatTimelineStyle(
fromWire(storedStyle)
?: storedChipTimeline?.let { if (it) Chips else Standard }

/** Starting style when nothing is stored: a fresh install starts on Chips. */
fun forInstall(existingInstall: Boolean): SessionChatTimelineStyle =
if (ChipTimelineIntro.startingChipTimeline(existingInstall)) Chips else Standard
/** Styles a picker offers, in order; Chips only while its flag is on. */
fun available(chipTimelineAvailable: Boolean): List<SessionChatTimelineStyle> =
entries.filter { it != Chips || chipTimelineAvailable }

/** Chips is gated by the remote flag; a disabled flag renders Standard. */
fun effective(
Expand All @@ -63,6 +67,7 @@ object SessionChatDisplayPreferences {
private const val KEY_FOLLOW_UP_DELIVERY = "follow_up_delivery"
private const val KEY_CHIP_TIMELINE_INTRO_DONE = "chip_timeline_intro_done"
private const val KEY_CHIP_TIMELINE_INTRO_SNOOZED_UNTIL = "chip_timeline_intro_snoozed_until"
private const val KEY_TIMELINE_STYLE_PICKER_DONE = "timeline_style_picker_done"
const val DEFAULT_COLLAPSE_CONSECUTIVE_TOOL_CALLS = true
const val DEFAULT_CHIP_TIMELINE = false
val DEFAULT_FOLLOW_UP_DELIVERY = FollowUpDelivery.Steer
Expand Down Expand Up @@ -91,6 +96,17 @@ object SessionChatDisplayPreferences {
var chipTimelineIntroSnoozedUntilMillis: Long? by mutableStateOf(null)
private set

/**
* One-time Timeline Style picker (#805): false while an existing install still has to
* answer it, true once answered (or on a fresh install), null when never settled.
*/
var timelineStylePickerDone: Boolean? by mutableStateOf(null)
private set

/** Session Chat should offer the Timeline Style picker: the stored key is exactly false. */
val timelineStylePickerPending: Boolean
get() = timelineStylePickerDone == false

/** True while the `session_chat_chip_timeline` flag allows the mode at all (OPE-269). */
val chipTimelineAvailable: Boolean
get() = FeatureFlags.isEnabled(FeatureFlag.SessionChatChipTimeline)
Expand All @@ -104,6 +120,10 @@ object SessionChatDisplayPreferences {
val chipTimeline: Boolean
get() = timelineStyle == SessionChatTimelineStyle.Chips

/** Styles the Settings and Session Chat pickers offer. */
val availableTimelineStyles: List<SessionChatTimelineStyle>
get() = SessionChatTimelineStyle.available(chipTimelineAvailable)

/** Effective Timeline Style: Chips falls back to Standard while the flag is off. */
val timelineStyle: SessionChatTimelineStyle
get() = SessionChatTimelineStyle.effective(timelineStylePreference, chipTimelineAvailable)
Expand All @@ -116,11 +136,14 @@ object SessionChatDisplayPreferences {
val activityCardTimeline: Boolean
get() = timelineStyle == SessionChatTimelineStyle.ActivityCard

private var appContext: Context? = null
private var preferences: SharedPreferences? = null

fun initialize(context: Context) {
appContext = context.applicationContext
val prefs = prefs() ?: return
initialize(context.applicationContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE))
}

internal fun initialize(prefs: SharedPreferences) {
preferences = prefs
collapseConsecutiveToolCalls =
if (prefs.contains(KEY_COLLAPSE_CONSECUTIVE_TOOL_CALLS)) {
prefs.getBoolean(KEY_COLLAPSE_CONSECUTIVE_TOOL_CALLS, DEFAULT_COLLAPSE_CONSECUTIVE_TOOL_CALLS)
Expand All @@ -147,6 +170,12 @@ object SessionChatDisplayPreferences {
} else {
null
}
timelineStylePickerDone =
if (prefs.contains(KEY_TIMELINE_STYLE_PICKER_DONE)) {
prefs.getBoolean(KEY_TIMELINE_STYLE_PICKER_DONE, true)
} else {
null
}
}

fun updateCollapseConsecutiveToolCalls(value: Boolean) {
Expand All @@ -164,28 +193,48 @@ object SessionChatDisplayPreferences {
updateTimelineStyle(if (value) SessionChatTimelineStyle.Chips else SessionChatTimelineStyle.Standard)
}

/** Any explicit choice, from Settings or the intro sheet, also ends the intro. */
/**
* Any explicit choice, from Settings, the Chip intro, or the Timeline Style picker, also
* ends the Chip intro and the picker.
*/
fun updateTimelineStyle(value: SessionChatTimelineStyle) {
timelineStylePreference = value
chipTimelineIntroDone = true
timelineStylePickerDone = true
prefs()
?.edit()
?.putString(KEY_TIMELINE_STYLE, value.wireValue)
?.putBoolean(KEY_CHIP_TIMELINE_INTRO_DONE, true)
?.putBoolean(KEY_TIMELINE_STYLE_PICKER_DONE, true)
?.apply()
}

/** Timeline Style picker swipe, scrim, back, or close: keeps the recommended Activity Card. */
fun dismissTimelineStylePicker() {
updateTimelineStyle(SessionChatTimelineStyle.ActivityCard)
}

/**
* Settles the starting Chip timeline value once per install (OPE-270).
* [existingInstall] is true when the app opens past App onboarding. A
* stored value, from an earlier launch or a Settings choice, always wins.
* Settles the starting Timeline Style and the one-time picker once per install (#805).
* [existingInstall] is true when the app opens past App onboarding. A fresh install starts
* on Activity Card and never sees the picker; an existing install with nothing stored keeps
* Standard and is offered the picker. A stored value, from an earlier launch or a Settings
* choice, always wins.
*/
fun resolveChipTimelineForInstall(existingInstall: Boolean) {
fun resolveTimelineForInstall(existingInstall: Boolean) {
val prefs = prefs() ?: return
if (prefs.contains(KEY_TIMELINE_STYLE) || prefs.contains(KEY_CHIP_TIMELINE)) return
val value = SessionChatTimelineStyle.forInstall(existingInstall)
timelineStylePreference = value
prefs.edit().putString(KEY_TIMELINE_STYLE, value.wireValue).apply()
val editor = prefs.edit()
if (!prefs.contains(KEY_TIMELINE_STYLE) && !prefs.contains(KEY_CHIP_TIMELINE)) {
val value = if (existingInstall) SessionChatTimelineStyle.Standard else SessionChatTimelineStyle.ActivityCard
timelineStylePreference = value
editor.putString(KEY_TIMELINE_STYLE, value.wireValue)
}
if (!prefs.contains(KEY_TIMELINE_STYLE_PICKER_DONE)) {
val done = !existingInstall
timelineStylePickerDone = done
editor.putBoolean(KEY_TIMELINE_STYLE_PICKER_DONE, done)
}
editor.apply()
}

/** Intro sheet "Don't show again", or a second Later. */
Expand All @@ -205,22 +254,26 @@ object SessionChatDisplayPreferences {
prefs()?.edit()?.putLong(KEY_CHIP_TIMELINE_INTRO_SNOOZED_UNTIL, until)?.apply()
}

/** Whether a finished turn with [turnToolCalls] tool calls should offer the intro sheet. */
/**
* Whether a finished turn with [turnToolCalls] tool calls should offer the intro sheet.
* Never while the Timeline Style picker is still pending (#805).
*/
fun shouldOfferChipTimelineIntro(
turnToolCalls: Int,
nowMillis: Long,
): Boolean =
ChipTimelineIntro.shouldShow(
chipTimelineAvailable = chipTimelineAvailable,
chipTimelineOn = chipTimelinePreference,
timelineStyleChosen =
timelineStylePreference == SessionChatTimelineStyle.StepRail ||
timelineStylePreference == SessionChatTimelineStyle.ActivityCard,
introDone = chipTimelineIntroDone,
snoozedUntilMillis = chipTimelineIntroSnoozedUntilMillis,
nowMillis = nowMillis,
turnToolCalls = turnToolCalls,
)
!timelineStylePickerPending &&
ChipTimelineIntro.shouldShow(
chipTimelineAvailable = chipTimelineAvailable,
chipTimelineOn = chipTimelinePreference,
timelineStyleChosen =
timelineStylePreference == SessionChatTimelineStyle.StepRail ||
timelineStylePreference == SessionChatTimelineStyle.ActivityCard,
introDone = chipTimelineIntroDone,
snoozedUntilMillis = chipTimelineIntroSnoozedUntilMillis,
nowMillis = nowMillis,
turnToolCalls = turnToolCalls,
)

fun clear() {
prefs()
Expand All @@ -231,13 +284,15 @@ object SessionChatDisplayPreferences {
?.remove(KEY_TIMELINE_STYLE)
?.remove(KEY_CHIP_TIMELINE_INTRO_DONE)
?.remove(KEY_CHIP_TIMELINE_INTRO_SNOOZED_UNTIL)
?.remove(KEY_TIMELINE_STYLE_PICKER_DONE)
?.apply()
collapseConsecutiveToolCalls = DEFAULT_COLLAPSE_CONSECUTIVE_TOOL_CALLS
followUpDelivery = DEFAULT_FOLLOW_UP_DELIVERY
timelineStylePreference = SessionChatTimelineStyle.DEFAULT
chipTimelineIntroDone = false
chipTimelineIntroSnoozedUntilMillis = null
timelineStylePickerDone = null
}

private fun prefs() = appContext?.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
private fun prefs() = preferences
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum class ComponentGalleryEntryId {
Snackbar,
ListItem,
SelectableCard,
OptionCard,
ListGroup,
SectionHeader,
ReorderableList,
Expand Down Expand Up @@ -261,6 +262,12 @@ val ComponentGalleryEntries =
description = "Title, blurb, and preview slot that can be selected.",
category = ComponentGalleryCategory.Lists,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.OptionCard,
title = "Option Card",
description = "Bordered single-choice card with radio, title and tag, subtitle, and illustration preview.",
category = ComponentGalleryCategory.Lists,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.SectionHeader,
title = "Section Header",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import dev.opencode.mobile.ui.components.OpenCodeButton
import dev.opencode.mobile.ui.components.OpenCodeButtonVariant
import dev.opencode.mobile.ui.components.OpenCodeChoiceBadge
import dev.opencode.mobile.ui.components.OpenCodeListItem
import dev.opencode.mobile.ui.components.OpenCodeSkeletonIllustrationTopic
import dev.opencode.mobile.ui.components.OpenCodeTextInput
import dev.opencode.mobile.ui.components.OpenCodeTextInputKind
import dev.opencode.mobile.ui.components.StartDecorator
Expand All @@ -34,13 +35,15 @@ import dev.opencode.mobile.ui.icons.OpenCodeIcons
private enum class GalleryBottomSheetDecoratorKind {
None,
Icon,
Illustration,
}

@Composable
fun BottomSheetGalleryScreen(modifier: Modifier = Modifier) {
var visible by rememberSaveable { mutableStateOf(false) }
var enabled by rememberSaveable { mutableStateOf(true) }
var selected by rememberSaveable { mutableStateOf(false) }
var showsTag by rememberSaveable { mutableStateOf(false) }
var showsHeaderBack by rememberSaveable { mutableStateOf(false) }
var showsHeaderTextAction by rememberSaveable { mutableStateOf(false) }
var headerEditing by rememberSaveable { mutableStateOf(false) }
Expand All @@ -63,11 +66,15 @@ fun BottomSheetGalleryScreen(modifier: Modifier = Modifier) {
when (startDecoratorKind) {
GalleryBottomSheetDecoratorKind.None -> BottomSheetEntryDecorator.None
GalleryBottomSheetDecoratorKind.Icon -> BottomSheetEntryDecorator.Icon(OpenCodeIcons.Folder)
GalleryBottomSheetDecoratorKind.Illustration ->
BottomSheetEntryDecorator.Illustration(OpenCodeSkeletonIllustrationTopic.TimelineActivityCard)
}
val endDecorator =
when (endDecoratorKind) {
GalleryBottomSheetDecoratorKind.None -> BottomSheetEntryDecorator.None
GalleryBottomSheetDecoratorKind.Icon -> BottomSheetEntryDecorator.Icon(OpenCodeIcons.ChevronRight)
GalleryBottomSheetDecoratorKind.Illustration ->
BottomSheetEntryDecorator.Illustration(OpenCodeSkeletonIllustrationTopic.TimelineStepRail)
}

Column(modifier = modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(16.dp)) {
Expand All @@ -76,6 +83,7 @@ fun BottomSheetGalleryScreen(modifier: Modifier = Modifier) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OpenCodeChoiceBadge(label = "Entry enabled", selected = enabled, onClick = { enabled = !enabled })
OpenCodeChoiceBadge(label = "Entry selected", selected = selected, onClick = { selected = !selected })
OpenCodeChoiceBadge(label = "Entry tag", selected = showsTag, onClick = { showsTag = !showsTag })
OpenCodeChoiceBadge(label = "Header back", selected = showsHeaderBack, onClick = { showsHeaderBack = !showsHeaderBack })
OpenCodeChoiceBadge(
label = "Header Edit",
Expand Down Expand Up @@ -219,6 +227,7 @@ fun BottomSheetGalleryScreen(modifier: Modifier = Modifier) {
ActionSheetEntries(
enabled = enabled,
selected = selected,
tag = if (showsTag) "Recommended" else null,
startDecorator = startDecorator,
endDecorator = endDecorator,
itemCount = itemCount,
Expand Down Expand Up @@ -265,6 +274,7 @@ private fun KeyboardExpandBottomSheet(
private fun ActionSheetEntries(
enabled: Boolean,
selected: Boolean,
tag: String?,
startDecorator: BottomSheetEntryDecorator,
endDecorator: BottomSheetEntryDecorator,
itemCount: Int,
Expand All @@ -276,6 +286,7 @@ private fun ActionSheetEntries(
startDecorator = startDecorator,
endDecorator = endDecorator,
selected = selected,
tag = tag,
onClick = onDismiss,
)
OpenCodeBottomSheetEntry(
Expand Down Expand Up @@ -307,6 +318,12 @@ private fun ActionSheetEntries(
onClick = onDismiss,
)
}
// Past the 420 compact limit: FitContent rests at half height, FitAllContent shows them all.
if (itemCount >= 12) {
repeat(6) { index ->
OpenCodeBottomSheetEntry(title = "Extra action ${index + 1}", onClick = onDismiss)
}
}
}

@Composable
Expand Down Expand Up @@ -358,7 +375,7 @@ private fun ItemCountControls(
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(text = "Items", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurface)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
listOf(2, 4, 6).forEach { count ->
listOf(2, 4, 6, 12).forEach { count ->
OpenCodeChoiceBadge(
label = count.toString(),
selected = selected == count,
Expand Down
Loading
Loading