feat: add app theme system and theme switching
This commit is contained in:
1 parent
e21afbf583
commit
a4d0f97839
4 files changed
+105
-4
No files matched your search
@@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.NavigationBar
|
import androidx.compose.material3.NavigationBar
|
||||||
import androidx.compose.material3.NavigationBarItem
|
import androidx.compose.material3.NavigationBarItem
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
@@ -26,14 +25,15 @@ import cn.xiaobai.openclawapp.feature.config.ServerConfigScreen
|
|||||||
import cn.xiaobai.openclawapp.feature.sessions.SessionListScreen
|
import cn.xiaobai.openclawapp.feature.sessions.SessionListScreen
|
||||||
import cn.xiaobai.openclawapp.feature.settings.SettingsScreen
|
import cn.xiaobai.openclawapp.feature.settings.SettingsScreen
|
||||||
import cn.xiaobai.openclawapp.feature.status.StatusScreen
|
import cn.xiaobai.openclawapp.feature.status.StatusScreen
|
||||||
|
import cn.xiaobai.openclawapp.ui.OpenClawTheme
|
||||||
import cn.xiaobai.openclawapp.ui.StatusPill
|
import cn.xiaobai.openclawapp.ui.StatusPill
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun App() {
|
fun App() {
|
||||||
MaterialTheme {
|
|
||||||
val appState = remember { OpenClawAppState() }
|
val appState = remember { OpenClawAppState() }
|
||||||
|
|
||||||
|
OpenClawTheme(themeMode = appState.themeMode) {
|
||||||
if (!appState.isConfigured) {
|
if (!appState.isConfigured) {
|
||||||
var baseUrl by remember { mutableStateOf(appState.serverConfig.baseUrl) }
|
var baseUrl by remember { mutableStateOf(appState.serverConfig.baseUrl) }
|
||||||
var token by remember { mutableStateOf(appState.serverConfig.token) }
|
var token by remember { mutableStateOf(appState.serverConfig.token) }
|
||||||
@@ -156,7 +156,9 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
serverConfig = appState.serverConfig,
|
serverConfig = appState.serverConfig,
|
||||||
currentModel = appState.repository.status.currentModel,
|
currentModel = appState.repository.status.currentModel,
|
||||||
availableAgents = appState.repository.availableAgents,
|
availableAgents = appState.repository.availableAgents,
|
||||||
|
currentTheme = appState.themeMode,
|
||||||
onSelectAgent = appState::updateDefaultAgent,
|
onSelectAgent = appState::updateDefaultAgent,
|
||||||
|
onSelectTheme = appState::updateTheme,
|
||||||
onDisconnect = appState::disconnect,
|
onDisconnect = appState::disconnect,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class OpenClawAppState {
|
|||||||
var activeSessionId by mutableStateOf<String?>(null)
|
var activeSessionId by mutableStateOf<String?>(null)
|
||||||
var serverConfig by mutableStateOf(ServerConfig())
|
var serverConfig by mutableStateOf(ServerConfig())
|
||||||
var feedbackMessage by mutableStateOf<String?>(null)
|
var feedbackMessage by mutableStateOf<String?>(null)
|
||||||
|
var themeMode by mutableStateOf(AppThemeMode.Dark)
|
||||||
val repository = MockOpenClawRepository()
|
val repository = MockOpenClawRepository()
|
||||||
|
|
||||||
fun connect(config: ServerConfig) {
|
fun connect(config: ServerConfig) {
|
||||||
@@ -42,6 +43,14 @@ class OpenClawAppState {
|
|||||||
feedbackMessage = "默认 Agent 已切换到 $agent"
|
feedbackMessage = "默认 Agent 已切换到 $agent"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateTheme(theme: AppThemeMode) {
|
||||||
|
themeMode = theme
|
||||||
|
feedbackMessage = when (theme) {
|
||||||
|
AppThemeMode.Dark -> "已切到深色主题"
|
||||||
|
AppThemeMode.Light -> "已切到浅色主题"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun togglePin(sessionId: String) {
|
fun togglePin(sessionId: String) {
|
||||||
val pinned = repository.togglePinned(sessionId)
|
val pinned = repository.togglePinned(sessionId)
|
||||||
feedbackMessage = if (pinned) "已置顶会话" else "已取消置顶"
|
feedbackMessage = if (pinned) "已置顶会话" else "已取消置顶"
|
||||||
@@ -57,3 +66,8 @@ enum class MainTab {
|
|||||||
Status,
|
Status,
|
||||||
Settings,
|
Settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class AppThemeMode(val label: String) {
|
||||||
|
Dark("深色"),
|
||||||
|
Light("浅色"),
|
||||||
|
}
|
||||||
+19
-2
@@ -7,10 +7,12 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import cn.xiaobai.openclawapp.app.AppThemeMode
|
||||||
import cn.xiaobai.openclawapp.data.ServerConfig
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
import cn.xiaobai.openclawapp.ui.HeroCard
|
import cn.xiaobai.openclawapp.ui.HeroCard
|
||||||
import cn.xiaobai.openclawapp.ui.LabelValueCard
|
import cn.xiaobai.openclawapp.ui.LabelValueCard
|
||||||
@@ -22,7 +24,9 @@ fun SettingsScreen(
|
|||||||
serverConfig: ServerConfig,
|
serverConfig: ServerConfig,
|
||||||
currentModel: String,
|
currentModel: String,
|
||||||
availableAgents: List<String>,
|
availableAgents: List<String>,
|
||||||
|
currentTheme: AppThemeMode,
|
||||||
onSelectAgent: (String) -> Unit,
|
onSelectAgent: (String) -> Unit,
|
||||||
|
onSelectTheme: (AppThemeMode) -> Unit,
|
||||||
onDisconnect: () -> Unit,
|
onDisconnect: () -> Unit,
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -32,7 +36,7 @@ fun SettingsScreen(
|
|||||||
item {
|
item {
|
||||||
HeroCard(
|
HeroCard(
|
||||||
title = "连接配置",
|
title = "连接配置",
|
||||||
subtitle = "这里先承载服务器地址、token 状态和默认 Agent。等网络层接入后,再往下拆成账号、通知和实验功能。",
|
subtitle = "这里先承载服务器地址、token 状态、默认 Agent 和主题。等网络层接入后,再往下拆成账号、通知和实验功能。",
|
||||||
badge = "Settings",
|
badge = "Settings",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -48,7 +52,20 @@ fun SettingsScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
Text("切换默认 Agent", style = androidx.compose.material3.MaterialTheme.typography.titleMedium)
|
Text("主题", style = MaterialTheme.typography.titleMedium)
|
||||||
|
}
|
||||||
|
|
||||||
|
items(AppThemeMode.entries) { theme ->
|
||||||
|
SelectableRowCard(
|
||||||
|
title = theme.label,
|
||||||
|
trailing = if (theme == currentTheme) "当前" else null,
|
||||||
|
selected = theme == currentTheme,
|
||||||
|
modifier = Modifier.clickable { onSelectTheme(theme) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
Text("切换默认 Agent", style = MaterialTheme.typography.titleMedium)
|
||||||
}
|
}
|
||||||
|
|
||||||
items(availableAgents) { agent ->
|
items(availableAgents) { agent ->
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package cn.xiaobai.openclawapp.ui
|
||||||
|
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.darkColorScheme
|
||||||
|
import androidx.compose.material3.lightColorScheme
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import cn.xiaobai.openclawapp.app.AppThemeMode
|
||||||
|
|
||||||
|
private val OpenClawLightColors = lightColorScheme(
|
||||||
|
primary = Color(0xFF2D5BFF),
|
||||||
|
onPrimary = Color.White,
|
||||||
|
primaryContainer = Color(0xFFDDE4FF),
|
||||||
|
onPrimaryContainer = Color(0xFF00174A),
|
||||||
|
secondary = Color(0xFF65558F),
|
||||||
|
onSecondary = Color.White,
|
||||||
|
secondaryContainer = Color(0xFFE9DDFF),
|
||||||
|
onSecondaryContainer = Color(0xFF211047),
|
||||||
|
tertiary = Color(0xFF006B5E),
|
||||||
|
onTertiary = Color.White,
|
||||||
|
tertiaryContainer = Color(0xFF74F8E1),
|
||||||
|
onTertiaryContainer = Color(0xFF00201B),
|
||||||
|
background = Color(0xFFF7F9FF),
|
||||||
|
onBackground = Color(0xFF171C2B),
|
||||||
|
surface = Color(0xFFF7F9FF),
|
||||||
|
onSurface = Color(0xFF171C2B),
|
||||||
|
surfaceVariant = Color(0xFFE1E3EC),
|
||||||
|
onSurfaceVariant = Color(0xFF454A58),
|
||||||
|
outlineVariant = Color(0xFFC5C7D0),
|
||||||
|
)
|
||||||
|
|
||||||
|
private val OpenClawDarkColors = darkColorScheme(
|
||||||
|
primary = Color(0xFFB8C4FF),
|
||||||
|
onPrimary = Color(0xFF002A78),
|
||||||
|
primaryContainer = Color(0xFF003DAA),
|
||||||
|
onPrimaryContainer = Color(0xFFDDE4FF),
|
||||||
|
secondary = Color(0xFFD0BCFF),
|
||||||
|
onSecondary = Color(0xFF36275F),
|
||||||
|
secondaryContainer = Color(0xFF4D3E76),
|
||||||
|
onSecondaryContainer = Color(0xFFE9DDFF),
|
||||||
|
tertiary = Color(0xFF54DBC5),
|
||||||
|
onTertiary = Color(0xFF003730),
|
||||||
|
tertiaryContainer = Color(0xFF005047),
|
||||||
|
onTertiaryContainer = Color(0xFF74F8E1),
|
||||||
|
background = Color(0xFF0F1117),
|
||||||
|
onBackground = Color(0xFFE5EAF6),
|
||||||
|
surface = Color(0xFF0F1117),
|
||||||
|
onSurface = Color(0xFFE5EAF6),
|
||||||
|
surfaceVariant = Color(0xFF2C313F),
|
||||||
|
onSurfaceVariant = Color(0xFFC5C7D0),
|
||||||
|
outlineVariant = Color(0xFF454A58),
|
||||||
|
)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OpenClawTheme(
|
||||||
|
themeMode: AppThemeMode,
|
||||||
|
content: @Composable () -> Unit,
|
||||||
|
) {
|
||||||
|
val colorScheme = when (themeMode) {
|
||||||
|
AppThemeMode.Light -> OpenClawLightColors
|
||||||
|
AppThemeMode.Dark -> OpenClawDarkColors
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialTheme(
|
||||||
|
colorScheme = colorScheme,
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user