Skip to content
Closed
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
7 changes: 6 additions & 1 deletion android/app/src/main/java/dev/opencode/mobile/Navigation.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.opencode.mobile

import android.content.Intent
import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
Expand Down Expand Up @@ -48,6 +49,7 @@ import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.rememberNavBackStack
import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator
import androidx.navigation3.ui.NavDisplay
import dev.opencode.mobile.R
import dev.opencode.mobile.domain.app.AppVersion
import dev.opencode.mobile.domain.connection.ConnectionProfile
import dev.opencode.mobile.domain.feedback.FeedbackScreen
Expand Down Expand Up @@ -303,13 +305,16 @@ fun MainNavigation() {
val diagnosticLogsViewModel: DiagnosticLogsViewModel = hiltViewModel()
val diagnosticLogsState by diagnosticLogsViewModel.state.collectAsStateWithLifecycle()
val context = LocalContext.current
val shareSubject = stringResource(R.string.share_diagnostics_subject)
val shareChooserTitle = stringResource(R.string.share_diagnostics_chooser_title)
DiagnosticLogsScreen(
state = diagnosticLogsState,
onNavigateBack = onNavigateBack,
detailControl = detailControl,
onShareViaApps = {
diagnosticLogsViewModel.shareViaApps { intent ->
context.startActivity(intent)
intent.putExtra(Intent.EXTRA_SUBJECT, shareSubject)
context.startActivity(Intent.createChooser(intent, shareChooserTitle))
}
},
onSaveToUri = diagnosticLogsViewModel::saveToUri,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.opencode.mobile.domain.feedback

import dev.opencode.mobile.R
import dev.opencode.mobile.domain.diagnostic.DiagnosticLogExportWindow
import dev.opencode.mobile.ui.text.UiText
import java.util.UUID

/** What the user is reporting. Shown as Bug / Idea; [wireValue] is the report's `kind`. */
Expand Down Expand Up @@ -139,7 +141,7 @@ object FeedbackReference {

/** What the share sheet gets in debug builds, or after Share Instead. */
data class FeedbackSharePayload(
val subject: String,
val subject: UiText,
val text: String,
val attachments: List<FeedbackAttachment>,
) {
Expand All @@ -158,7 +160,13 @@ data class FeedbackSharePayload(
"Ref ${report.reference}",
)
return FeedbackSharePayload(
subject = "OpenCode Mobile ${report.kind.label.lowercase()} report",
subject =
UiText.resource(
when (report.kind) {
FeedbackKind.Bug -> R.string.share_feedback_subject_bug
FeedbackKind.Feedback -> R.string.share_feedback_subject_idea
},
),
text = report.message + "\n\n" + facts.joinToString(" · "),
attachments = report.attachments,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.opencode.mobile.domain.filesystem

import dev.opencode.mobile.ui.text.UiText
import java.net.URLEncoder

/** One File Browser row: a file or folder under the Session Chat worktree. */
Expand Down Expand Up @@ -54,9 +55,16 @@ sealed interface ProjectFileContent {
class ProjectFilesException(
message: String,
/** One-line reason for the user, such as the HTTP status. */
val detail: String,
val detail: UiText,
cause: Throwable? = null,
) : Exception(message, cause)
) : Exception(message, cause) {
/** A detail that is already user-facing text, shown as is. */
constructor(
message: String,
detail: String,
cause: Throwable? = null,
) : this(message, UiText.verbatim(detail), cause)
}

object ProjectFileLimits {
/** Text preview cap; larger files show the first 1 MiB. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.opencode.mobile.domain.filesystem

import dev.opencode.mobile.R
import dev.opencode.mobile.data.remote.FilesystemApi
import dev.opencode.mobile.data.remote.V1FileContentResponse
import dev.opencode.mobile.domain.connection.ServerProtocol
import dev.opencode.mobile.network.ActiveConnectionManager
import dev.opencode.mobile.ui.text.UiText
import io.ktor.client.plugins.ResponseException
import kotlinx.coroutines.CancellationException
import javax.inject.Inject
Expand Down Expand Up @@ -146,10 +148,11 @@ class DefaultProjectFilesRepository
throw ProjectFilesException(failure, detail = describe(error), cause = error)
}

private fun describe(error: Exception): String =
private fun describe(error: Exception): UiText =
when (error) {
is ResponseException -> "The server responded with ${error.response.status.value}."
else -> "Check the connection to the server and try again."
// Not keyed yet: needs a files.* key (#886).
is ResponseException -> UiText.verbatim("The server responded with ${error.response.status.value}.")
else -> UiText.resource(R.string.files_error_check_server_connection)
}

private fun ProjectEntry.withParent(directory: String): ProjectEntry {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.opencode.mobile.domain.home

import dev.opencode.mobile.R
import dev.opencode.mobile.ui.text.UiText
import java.time.DayOfWeek
import java.time.Instant
import java.time.LocalDate
Expand All @@ -19,7 +21,8 @@ enum class HomeSessionLadderKind {
data class HomeSessionLadderSection<T>(
val id: String,
val kind: HomeSessionLadderKind,
val title: String,
/** Section header: a keyed label, or a formatted date. */
val title: UiText,
val hint: String? = null,
val items: List<T>,
)
Expand Down Expand Up @@ -74,7 +77,7 @@ object HomeSessionLadder {
HomeSessionLadderSection(
id = "recent",
kind = HomeSessionLadderKind.Recent,
title = "Recent",
title = UiText.resource(R.string.session_list_section_recent),
hint = RECENT_HINT,
items = recent,
)
Expand All @@ -100,9 +103,9 @@ object HomeSessionLadder {
if (items.isEmpty()) continue
val title =
when (offset) {
0 -> "Today"
1 -> "Yesterday"
else -> day.format(dayFormatter)
0 -> UiText.resource(R.string.session_list_section_today)
1 -> UiText.resource(R.string.session_list_section_yesterday)
else -> UiText.verbatim(day.format(dayFormatter))
}
sections +=
HomeSessionLadderSection(
Expand Down Expand Up @@ -144,7 +147,11 @@ object HomeSessionLadder {
.forEach { (weekStart, items) ->
val weekEnd = weekStart.plusDays(6)
val title =
"Week of ${weekStart.format(weekFormatter)} – ${weekEnd.format(weekFormatter)}"
UiText.resource(
R.string.session_list_section_week_of,
weekStart.format(weekFormatter),
weekEnd.format(weekFormatter),
)
sections +=
HomeSessionLadderSection(
id = "week-$weekStart",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
package dev.opencode.mobile.domain.time

import dev.opencode.mobile.R
import dev.opencode.mobile.ui.text.UiText
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.Locale
import java.util.concurrent.TimeUnit

/** Short relative time ("now", "5m ago", "2d ago"), then the month and day after a week. */
object RelativeTimeFormatting {
private val absoluteFormatter: DateTimeFormatter =
DateTimeFormatter.ofPattern("MMM d", Locale.US)

fun format(
epochMs: Long,
nowEpochMs: Long = System.currentTimeMillis(),
): String {
): UiText {
val deltaMs = (nowEpochMs - epochMs).coerceAtLeast(0L)
val minutes = TimeUnit.MILLISECONDS.toMinutes(deltaMs)
val hours = TimeUnit.MILLISECONDS.toHours(deltaMs)
val days = TimeUnit.MILLISECONDS.toDays(deltaMs)
return when {
minutes < 1L -> "now"
minutes < 60L -> "${minutes}m ago"
hours < 24L -> "${hours}h ago"
days < 7L -> "${days}d ago"
minutes < 1L -> UiText.resource(R.string.relative_time_now)
minutes < 60L -> UiText.plural(R.plurals.relative_time_minutes_ago, minutes.toInt())
hours < 24L -> UiText.plural(R.plurals.relative_time_hours_ago, hours.toInt())
days < 7L -> UiText.plural(R.plurals.relative_time_days_ago, days.toInt())
else ->
Instant
.ofEpochMilli(epochMs)
.atZone(ZoneId.systemDefault())
.format(absoluteFormatter)
UiText.verbatim(
Instant
.ofEpochMilli(epochMs)
.atZone(ZoneId.systemDefault())
.format(absoluteFormatter),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.content.Context
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import dev.opencode.mobile.R
import dev.opencode.mobile.domain.diagnostic.DiagnosticLog
import dev.opencode.mobile.domain.diagnostic.DiagnosticLogArea
import dev.opencode.mobile.ui.text.UiText
import kotlinx.serialization.json.Json

object ThemeManager {
Expand All @@ -32,7 +34,8 @@ object ThemeManager {
var resolvedDark: ResolvedTokens by mutableStateOf(ResolvedTokens())
private set

var loadError: String? by mutableStateOf(null)
/** Why the last theme or syntax preset change failed; shown in Settings. */
var loadError: UiText? by mutableStateOf(null)
private set

private var appContext: Context? = null
Expand Down Expand Up @@ -88,7 +91,7 @@ object ThemeManager {
fun applySyntaxPreset(id: String) {
val preset = syntaxPresets().firstOrNull { it.id == id }
if (preset == null) {
loadError = "Syntax highlight preset not found"
loadError = UiText.resource(R.string.theme_error_syntax_preset_not_found)
return
}
currentSyntaxPreset = preset
Expand All @@ -100,7 +103,7 @@ object ThemeManager {
fun applyPreset(id: String) {
val theme = loadPreset(id)
if (theme == null) {
loadError = "Theme preset not found"
loadError = UiText.resource(R.string.theme_error_preset_not_found)
return
}
try {
Expand All @@ -110,7 +113,7 @@ object ThemeManager {
saveSelectedThemeID(id)
loadError = null
} catch (e: Exception) {
loadError = e.message ?: "Failed to apply theme preset"
loadError = e.message?.let(UiText::verbatim) ?: UiText.resource(R.string.theme_error_apply_failed)
DiagnosticLog.error(DiagnosticLogArea.Connection, "Failed to apply preset $id", e)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import dev.opencode.mobile.ui.components.SessionListProjectPickerRows
import dev.opencode.mobile.ui.components.SessionListScopeLoad
import dev.opencode.mobile.ui.components.SessionListSession
import dev.opencode.mobile.ui.components.SessionListStatus
import dev.opencode.mobile.ui.text.UiText

@Composable
fun SessionListGalleryScreen(modifier: Modifier = Modifier) {
Expand Down Expand Up @@ -130,7 +131,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Violet,
subtitle = "/Users/demo/opencode-mobile",
status = SessionListStatus.Running,
caption = "now",
caption = UiText.verbatim("now"),
updatedAtEpochMs = now,
projectName = "opencode-mobile",
compactWorktree = "794-readable-tool-results",
Expand All @@ -143,7 +144,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Teal,
subtitle = "/Users/demo/playground",
status = SessionListStatus.Idle,
caption = "14m ago",
caption = UiText.verbatim("14m ago"),
updatedAtEpochMs = now - 14 * 60_000L,
),
SessionListSession(
Expand All @@ -154,7 +155,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Violet,
subtitle = "/Users/demo/opencode-mobile",
status = SessionListStatus.Ready,
caption = "3h ago",
caption = UiText.verbatim("3h ago"),
updatedAtEpochMs = now - 3 * 3_600_000L,
projectName = "opencode-mobile",
),
Expand All @@ -166,7 +167,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Teal,
subtitle = "/Users/demo/playground",
status = SessionListStatus.Done,
caption = "5m ago",
caption = UiText.verbatim("5m ago"),
updatedAtEpochMs = now - 5 * 60_000L,
),
SessionListSession(
Expand All @@ -177,7 +178,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Teal,
subtitle = "/Users/demo/playground",
status = SessionListStatus.Failed,
caption = "8m ago",
caption = UiText.verbatim("8m ago"),
updatedAtEpochMs = now - 8 * 60_000L,
),
SessionListSession(
Expand All @@ -188,7 +189,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Teal,
subtitle = "/Users/demo/playground",
status = SessionListStatus.Stopped,
caption = "11m ago",
caption = UiText.verbatim("11m ago"),
updatedAtEpochMs = now - 11 * 60_000L,
),
SessionListSession(
Expand All @@ -199,7 +200,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Violet,
subtitle = "/Users/demo/opencode-mobile",
status = SessionListStatus.Retrying,
caption = "now",
caption = UiText.verbatim("now"),
updatedAtEpochMs = now,
retryAttempt = 2,
projectName = "opencode-mobile",
Expand All @@ -214,7 +215,7 @@ private val sessionListGallerySamples: List<SessionListSession>
subtitle = "/Users/demo/opencode-mobile",
status = SessionListStatus.Running,
statusStale = true,
caption = "now",
caption = UiText.verbatim("now"),
updatedAtEpochMs = now,
),
SessionListSession(
Expand All @@ -225,7 +226,7 @@ private val sessionListGallerySamples: List<SessionListSession>
letterAccent = LetterAccent.Amber,
subtitle = "/Users/demo/api-client",
status = SessionListStatus.Running,
caption = "2d ago",
caption = UiText.verbatim("2d ago"),
updatedAtEpochMs = now - 2 * 86_400_000L,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.theme.LetterAccent
import dev.opencode.mobile.ui.components.OpenCodeChoiceBadge
Expand Down Expand Up @@ -42,7 +43,7 @@ fun SessionListSkeletonGalleryScreen(modifier: Modifier = Modifier) {
rowCount = rowCount,
accent = if (accented) LetterAccent.Violet else null,
title = "opencode-mobile",
caption = if (slow) SessionListScopeLoad.SLOW_CAPTION else null,
caption = if (slow) stringResource(SessionListScopeLoad.SLOW_CAPTION) else null,
)
}
}
Loading