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

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.animation.core.tween
import androidx.compose.animation.togetherWith
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
Expand All @@ -27,6 +25,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.rememberNavBackStack
import androidx.navigation3.ui.NavDisplay
import dev.opencode.mobile.domain.connection.ConnectionProfile
import dev.opencode.mobile.theme.OpenCodeTheme
import dev.opencode.mobile.ui.componentgallery.ComponentGalleryDetailScreen
import dev.opencode.mobile.ui.componentgallery.ComponentGalleryEntries
Expand All @@ -46,13 +45,12 @@ import dev.opencode.mobile.ui.componentgallery.foundation.TypographyGalleryScree
import dev.opencode.mobile.ui.components.OpenCodeBottomSheet
import dev.opencode.mobile.ui.connection.ConnectionSetupSheetContent
import dev.opencode.mobile.ui.connection.ConnectionSetupViewModel
import dev.opencode.mobile.domain.connection.ConnectionProfile
import dev.opencode.mobile.ui.main.MainScreen
import dev.opencode.mobile.ui.root.AppRootState
import dev.opencode.mobile.ui.settings.SettingsScreen
import dev.opencode.mobile.ui.settings.SettingsViewModel
import dev.opencode.mobile.ui.root.AppRootViewModel
import dev.opencode.mobile.ui.sessionchat.SessionChatScreen
import dev.opencode.mobile.ui.settings.SettingsScreen
import dev.opencode.mobile.ui.settings.SettingsViewModel

@Composable
fun MainNavigation() {
Expand Down Expand Up @@ -193,6 +191,7 @@ fun MainNavigation() {
}
}

@Suppress("ktlint:standard:property-naming")
private const val RouteTransitionDurationMillis = 220

private fun forwardRouteTransition() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class EncryptedSecureCredentialStore
preferences.edit().remove(passwordKey(serverBaseUrl)).apply()
}

override fun clearAll() {
preferences.edit().clear().apply()
}

private fun passwordKey(serverBaseUrl: String): String = "connection.password.$serverBaseUrl"

private companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class ConnectionSessionCoordinator
}

suspend fun clearConnectionData() {
val profile = activeConnectionManager.currentProfile()
if (profile != null) {
secureCredentialStore.deletePassword(profile.baseUrl)
}
secureCredentialStore.clearAll()
connectionProfileStore.clearAll()
activeConnectionManager.disconnect()
httpClient.rebuild()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ interface SecureCredentialStore {
)

fun deletePassword(serverBaseUrl: String)

fun clearAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package dev.opencode.mobile.domain.live
import dev.opencode.mobile.domain.event.ForegroundEventStream
import dev.opencode.mobile.domain.message.Message
import dev.opencode.mobile.domain.message.MessageRepository
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
Expand All @@ -16,8 +18,6 @@ import kotlinx.coroutines.flow.shareIn
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview

@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
@Singleton
Expand Down Expand Up @@ -89,8 +89,9 @@ class DefaultMessageLiveStore
var lastFingerprint = initialFingerprint
while (true) {
delay(LiveStoreRefreshPolicy.WORKING_POLL_INTERVAL_MS)
val messages = runCatching { messageRepository.listMessages(sessionId, directory) }.getOrNull()
?: continue
val messages =
runCatching { messageRepository.listMessages(sessionId, directory) }.getOrNull()
?: continue
val fingerprint = messageFingerprint(messages)
if (fingerprint != lastFingerprint) {
lastFingerprint = fingerprint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.opencode.mobile.domain.live
import dev.opencode.mobile.domain.event.ForegroundEventStream
import dev.opencode.mobile.domain.session.Session
import dev.opencode.mobile.domain.session.SessionRepository
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
Expand All @@ -15,7 +16,6 @@ import kotlinx.coroutines.flow.shareIn
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.FlowPreview

@OptIn(FlowPreview::class)
@Singleton
Expand All @@ -32,8 +32,7 @@ class DefaultSessionLiveStore
cache.clear()
}

override fun observeSessions(directory: String): Flow<List<Session>> =
cache.getOrPut(directory) { buildSharedFlow(directory) }
override fun observeSessions(directory: String): Flow<List<Session>> = cache.getOrPut(directory) { buildSharedFlow(directory) }

private fun buildSharedFlow(directory: String): SharedFlow<List<Session>> =
buildSessionFlow(directory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.opencode.mobile.domain.live
import dev.opencode.mobile.domain.event.ForegroundEventStream
import dev.opencode.mobile.domain.session.SessionRepository
import dev.opencode.mobile.domain.session.SessionStatus
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
Expand All @@ -15,7 +16,6 @@ import kotlinx.coroutines.flow.shareIn
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.FlowPreview

@OptIn(FlowPreview::class)
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ class LiveStoreScope(
val coroutineScope: CoroutineScope,
)

fun defaultLiveStoreScope(): LiveStoreScope =
LiveStoreScope(CoroutineScope(SupervisorJob() + Dispatchers.Default))
fun defaultLiveStoreScope(): LiveStoreScope = LiveStoreScope(CoroutineScope(SupervisorJob() + Dispatchers.Default))
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ interface MessageLiveStore {
sessionId: String,
directory: String,
): Flow<List<Message>>

fun clearCache()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import kotlinx.coroutines.flow.Flow

interface SessionLiveStore {
fun observeSessions(directory: String): Flow<List<Session>>

fun clearCache()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import kotlinx.coroutines.flow.Flow

interface SessionStatusLiveStore {
fun observeStatuses(directory: String): Flow<Map<String, SessionStatus>>

fun clearCache()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class ModelDomainAdapter {
providerName = provider.name ?: provider.id,
modelId = model.id ?: key,
modelName = model.name ?: model.id ?: key,
variants = model.variants?.keys?.sortedWith(String.CASE_INSENSITIVE_ORDER).orEmpty(),
variants =
model.variants
?.keys
?.sortedWith(String.CASE_INSENSITIVE_ORDER)
.orEmpty(),
)
}.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.modelLabel })
}
Expand All @@ -35,8 +39,7 @@ class ModelDomainAdapter {
else -> ModelSelectionError.Transport(throwable)
}

private fun isUsable(model: ProviderModelDto): Boolean =
model.disabled != true && model.status?.lowercase() != "deprecated"
private fun isUsable(model: ProviderModelDto): Boolean = model.disabled != true && model.status?.lowercase() != "deprecated"

private fun defaultOption(
defaults: Map<String, String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data class ModelSelection(
val modelDisplayLabel: String = option.displayLabel
val variantLabel: String = selectedVariant ?: DefaultVariantLabel

@Suppress("ktlint:standard:property-naming")
companion object {
const val DefaultVariantLabel = "Default"
}
Expand Down
5 changes: 4 additions & 1 deletion android/app/src/main/java/dev/opencode/mobile/theme/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ fun openCodeColor(token: String): Color {
/**
* Resolve a named semantic token for a specific mode without composition.
*/
fun openCodeColor(token: String, isDark: Boolean): Color {
fun openCodeColor(
token: String,
isDark: Boolean,
): Color {
val hex = if (isDark) ThemeManager.resolvedDark[token] else ThemeManager.resolvedLight[token]
return ThemeResolver.parseHexColor(hex)
}
Expand Down
149 changes: 76 additions & 73 deletions android/app/src/main/java/dev/opencode/mobile/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,82 +22,85 @@ fun OpenCodeTheme(
ThemeManager.initialize(context)
}

val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
else -> {
if (darkTheme) {
darkColorScheme(
primary = parse("text-interactive-base", dark = true),
onPrimary = Color.White,
primaryContainer = parse("surface-interactive-weak", dark = true),
onPrimaryContainer = parse("text-strong", dark = true),
inversePrimary = parse("text-interactive-base", dark = false),
secondary = parse("info", dark = true),
onSecondary = Color.White,
secondaryContainer = parse("surface-raised-base", dark = true),
onSecondaryContainer = parse("text-strong", dark = true),
tertiary = parse("success", dark = true),
onTertiary = Color.White,
tertiaryContainer = parse("surface-success-base", dark = true),
onTertiaryContainer = parse("text-strong", dark = true),
background = parse("background-base", dark = true),
onBackground = parse("text-strong", dark = true),
surface = parse("surface-base", dark = true),
onSurface = parse("text-strong", dark = true),
surfaceVariant = parse("surface-raised-base", dark = true),
onSurfaceVariant = parse("text-base", dark = true),
surfaceTint = parse("interactive", dark = true),
inverseSurface = parse("surface-base", dark = false),
inverseOnSurface = parse("text-strong", dark = false),
error = parse("error", dark = true),
onError = Color.White,
errorContainer = parse("surface-critical-base", dark = true),
onErrorContainer = parse("error", dark = true),
outline = parse("border-weak-base", dark = true),
outlineVariant = parse("border-weaker-base", dark = true),
scrim = Color.Black,
)
} else {
lightColorScheme(
primary = parse("text-interactive-base", dark = false),
onPrimary = Color.White,
primaryContainer = parse("surface-interactive-weak", dark = false),
onPrimaryContainer = parse("text-strong", dark = false),
inversePrimary = parse("text-interactive-base", dark = true),
secondary = parse("info", dark = false),
onSecondary = Color.White,
secondaryContainer = parse("surface-raised-base", dark = false),
onSecondaryContainer = parse("text-strong", dark = false),
tertiary = parse("success", dark = false),
onTertiary = Color.White,
tertiaryContainer = parse("surface-success-base", dark = false),
onTertiaryContainer = parse("text-strong", dark = false),
background = parse("background-base", dark = false),
onBackground = parse("text-strong", dark = false),
surface = parse("surface-base", dark = false),
onSurface = parse("text-strong", dark = false),
surfaceVariant = parse("surface-raised-base", dark = false),
onSurfaceVariant = parse("text-base", dark = false),
surfaceTint = parse("interactive", dark = false),
inverseSurface = parse("surface-base", dark = true),
inverseOnSurface = parse("text-strong", dark = true),
error = parse("error", dark = false),
onError = Color.White,
errorContainer = parse("surface-critical-base", dark = false),
onErrorContainer = parse("error", dark = false),
outline = parse("border-weak-base", dark = false),
outlineVariant = parse("border-weaker-base", dark = false),
scrim = Color.Black,
)
val colorScheme =
when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
else -> {
if (darkTheme) {
darkColorScheme(
primary = parse("text-interactive-base", dark = true),
onPrimary = Color.White,
primaryContainer = parse("surface-interactive-weak", dark = true),
onPrimaryContainer = parse("text-strong", dark = true),
inversePrimary = parse("text-interactive-base", dark = false),
secondary = parse("info", dark = true),
onSecondary = Color.White,
secondaryContainer = parse("surface-raised-base", dark = true),
onSecondaryContainer = parse("text-strong", dark = true),
tertiary = parse("success", dark = true),
onTertiary = Color.White,
tertiaryContainer = parse("surface-success-base", dark = true),
onTertiaryContainer = parse("text-strong", dark = true),
background = parse("background-base", dark = true),
onBackground = parse("text-strong", dark = true),
surface = parse("surface-base", dark = true),
onSurface = parse("text-strong", dark = true),
surfaceVariant = parse("surface-raised-base", dark = true),
onSurfaceVariant = parse("text-base", dark = true),
surfaceTint = parse("interactive", dark = true),
inverseSurface = parse("surface-base", dark = false),
inverseOnSurface = parse("text-strong", dark = false),
error = parse("error", dark = true),
onError = Color.White,
errorContainer = parse("surface-critical-base", dark = true),
onErrorContainer = parse("error", dark = true),
outline = parse("border-weak-base", dark = true),
outlineVariant = parse("border-weaker-base", dark = true),
scrim = Color.Black,
)
} else {
lightColorScheme(
primary = parse("text-interactive-base", dark = false),
onPrimary = Color.White,
primaryContainer = parse("surface-interactive-weak", dark = false),
onPrimaryContainer = parse("text-strong", dark = false),
inversePrimary = parse("text-interactive-base", dark = true),
secondary = parse("info", dark = false),
onSecondary = Color.White,
secondaryContainer = parse("surface-raised-base", dark = false),
onSecondaryContainer = parse("text-strong", dark = false),
tertiary = parse("success", dark = false),
onTertiary = Color.White,
tertiaryContainer = parse("surface-success-base", dark = false),
onTertiaryContainer = parse("text-strong", dark = false),
background = parse("background-base", dark = false),
onBackground = parse("text-strong", dark = false),
surface = parse("surface-base", dark = false),
onSurface = parse("text-strong", dark = false),
surfaceVariant = parse("surface-raised-base", dark = false),
onSurfaceVariant = parse("text-base", dark = false),
surfaceTint = parse("interactive", dark = false),
inverseSurface = parse("surface-base", dark = true),
inverseOnSurface = parse("text-strong", dark = true),
error = parse("error", dark = false),
onError = Color.White,
errorContainer = parse("surface-critical-base", dark = false),
onErrorContainer = parse("error", dark = false),
outline = parse("border-weak-base", dark = false),
outlineVariant = parse("border-weaker-base", dark = false),
scrim = Color.Black,
)
}
}
}
}

MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content)
}

private fun parse(token: String, dark: Boolean): Color =
openCodeColor(token, dark)
private fun parse(
token: String,
dark: Boolean,
): Color = openCodeColor(token, dark)
Loading