fix: resolve weight scope bug and add feedback banners
This commit is contained in:
1 parent
4acc08e2f8
commit
a7f05b56ed
4 files changed
+55
-10
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package cn.xiaobai.openclawapp
|
package cn.xiaobai.openclawapp
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
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
|
||||||
@@ -10,11 +11,13 @@ import androidx.compose.material3.NavigationBarItem
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import cn.xiaobai.openclawapp.app.MainTab
|
import cn.xiaobai.openclawapp.app.MainTab
|
||||||
import cn.xiaobai.openclawapp.app.OpenClawAppState
|
import cn.xiaobai.openclawapp.app.OpenClawAppState
|
||||||
import cn.xiaobai.openclawapp.data.ServerConfig
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
@@ -23,6 +26,8 @@ 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.StatusPill
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun App() {
|
fun App() {
|
||||||
@@ -62,6 +67,13 @@ fun App() {
|
|||||||
private fun OpenClawRoot(appState: OpenClawAppState) {
|
private fun OpenClawRoot(appState: OpenClawAppState) {
|
||||||
val activeSession = appState.activeSessionId?.let(appState.repository::findSession)
|
val activeSession = appState.activeSessionId?.let(appState.repository::findSession)
|
||||||
|
|
||||||
|
LaunchedEffect(appState.feedbackMessage) {
|
||||||
|
if (appState.feedbackMessage != null) {
|
||||||
|
delay(2200)
|
||||||
|
appState.clearFeedback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
CenterAlignedTopAppBar(
|
CenterAlignedTopAppBar(
|
||||||
@@ -103,13 +115,22 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
val contentModifier = Modifier
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(innerPadding)
|
.padding(innerPadding),
|
||||||
|
) {
|
||||||
|
appState.feedbackMessage?.let { message ->
|
||||||
|
StatusPill(
|
||||||
|
text = message,
|
||||||
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
|
highlighted = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
when {
|
when {
|
||||||
activeSession != null -> ChatScreen(
|
activeSession != null -> ChatScreen(
|
||||||
modifier = contentModifier,
|
modifier = Modifier.fillMaxSize(),
|
||||||
sessionTitle = activeSession.title,
|
sessionTitle = activeSession.title,
|
||||||
messages = appState.repository.messagesFor(activeSession.id),
|
messages = appState.repository.messagesFor(activeSession.id),
|
||||||
onBack = appState::closeChat,
|
onBack = appState::closeChat,
|
||||||
@@ -117,7 +138,7 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
appState.selectedTab == MainTab.Sessions -> SessionListScreen(
|
appState.selectedTab == MainTab.Sessions -> SessionListScreen(
|
||||||
modifier = contentModifier,
|
modifier = Modifier.fillMaxSize(),
|
||||||
sessions = appState.repository.sessions,
|
sessions = appState.repository.sessions,
|
||||||
recentSession = appState.repository.recentSession(),
|
recentSession = appState.repository.recentSession(),
|
||||||
pinnedCount = appState.repository.pinnedCount(),
|
pinnedCount = appState.repository.pinnedCount(),
|
||||||
@@ -126,12 +147,12 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
appState.selectedTab == MainTab.Status -> StatusScreen(
|
appState.selectedTab == MainTab.Status -> StatusScreen(
|
||||||
modifier = contentModifier,
|
modifier = Modifier.fillMaxSize(),
|
||||||
status = appState.repository.status,
|
status = appState.repository.status,
|
||||||
)
|
)
|
||||||
|
|
||||||
appState.selectedTab == MainTab.Settings -> SettingsScreen(
|
appState.selectedTab == MainTab.Settings -> SettingsScreen(
|
||||||
modifier = contentModifier,
|
modifier = Modifier.fillMaxSize(),
|
||||||
serverConfig = appState.serverConfig,
|
serverConfig = appState.serverConfig,
|
||||||
currentModel = appState.repository.status.currentModel,
|
currentModel = appState.repository.status.currentModel,
|
||||||
availableAgents = appState.repository.availableAgents,
|
availableAgents = appState.repository.availableAgents,
|
||||||
@@ -140,4 +161,5 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,17 +11,20 @@ class OpenClawAppState {
|
|||||||
var selectedTab by mutableStateOf(MainTab.Sessions)
|
var selectedTab by mutableStateOf(MainTab.Sessions)
|
||||||
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)
|
||||||
val repository = MockOpenClawRepository()
|
val repository = MockOpenClawRepository()
|
||||||
|
|
||||||
fun connect(config: ServerConfig) {
|
fun connect(config: ServerConfig) {
|
||||||
serverConfig = config
|
serverConfig = config
|
||||||
isConfigured = true
|
isConfigured = true
|
||||||
|
feedbackMessage = "已连接到 ${config.baseUrl}"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun disconnect() {
|
fun disconnect() {
|
||||||
isConfigured = false
|
isConfigured = false
|
||||||
activeSessionId = null
|
activeSessionId = null
|
||||||
selectedTab = MainTab.Sessions
|
selectedTab = MainTab.Sessions
|
||||||
|
feedbackMessage = "连接已断开"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openSession(sessionId: String) {
|
fun openSession(sessionId: String) {
|
||||||
@@ -36,10 +39,16 @@ class OpenClawAppState {
|
|||||||
fun updateDefaultAgent(agent: String) {
|
fun updateDefaultAgent(agent: String) {
|
||||||
serverConfig = serverConfig.copy(defaultAgent = agent)
|
serverConfig = serverConfig.copy(defaultAgent = agent)
|
||||||
repository.status = repository.status.copy(defaultAgent = agent)
|
repository.status = repository.status.copy(defaultAgent = agent)
|
||||||
|
feedbackMessage = "默认 Agent 已切换到 $agent"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun togglePin(sessionId: String) {
|
fun togglePin(sessionId: String) {
|
||||||
repository.togglePinned(sessionId)
|
val pinned = repository.togglePinned(sessionId)
|
||||||
|
feedbackMessage = if (pinned) "已置顶会话" else "已取消置顶"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearFeedback() {
|
||||||
|
feedbackMessage = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -82,12 +82,19 @@ class MockOpenClawRepository {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun togglePinned(sessionId: String) {
|
fun togglePinned(sessionId: String): Boolean {
|
||||||
|
var pinned = false
|
||||||
sessions = resortSessions(
|
sessions = resortSessions(
|
||||||
sessions.map {
|
sessions.map {
|
||||||
if (it.id == sessionId) it.copy(isPinned = !it.isPinned) else it
|
if (it.id == sessionId) {
|
||||||
|
pinned = !it.isPinned
|
||||||
|
it.copy(isPinned = pinned)
|
||||||
|
} else {
|
||||||
|
it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
return pinned
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendMessage(sessionId: String, text: String) {
|
fun sendMessage(sessionId: String, text: String) {
|
||||||
@@ -98,6 +105,12 @@ class MockOpenClawRepository {
|
|||||||
role = MessageRole.User,
|
role = MessageRole.User,
|
||||||
text = text,
|
text = text,
|
||||||
createdAt = "现在",
|
createdAt = "现在",
|
||||||
|
) + ChatMessage(
|
||||||
|
id = Random.nextInt().toString(),
|
||||||
|
role = MessageRole.System,
|
||||||
|
text = "OpenClaw 正在组织回复…",
|
||||||
|
createdAt = "现在",
|
||||||
|
status = "thinking",
|
||||||
) + ChatMessage(
|
) + ChatMessage(
|
||||||
id = Random.nextInt().toString(),
|
id = Random.nextInt().toString(),
|
||||||
role = MessageRole.Assistant,
|
role = MessageRole.Assistant,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.weight
|
import androidx.compose.foundation.layout.weight
|
||||||
@@ -141,7 +142,7 @@ fun ChatScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun QuickActionButton(text: String, onClick: () -> Unit) {
|
private fun RowScope.QuickActionButton(text: String, onClick: () -> Unit) {
|
||||||
Button(onClick = onClick, modifier = Modifier.weight(1f)) {
|
Button(onClick = onClick, modifier = Modifier.weight(1f)) {
|
||||||
Text(text)
|
Text(text)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user