feat: add mobile app skeleton with mock chat flow
This commit is contained in:
1 parent
a017533b96
commit
c8cb3b5812
10 files changed
+713
-34
No files matched your search
@@ -1,49 +1,139 @@
|
|||||||
package cn.xiaobai.openclawapp
|
package cn.xiaobai.openclawapp
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.safeContentPadding
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.NavigationBar
|
||||||
|
import androidx.compose.material3.NavigationBarItem
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import cn.xiaobai.openclawapp.app.MainTab
|
||||||
import org.jetbrains.compose.resources.painterResource
|
import cn.xiaobai.openclawapp.app.OpenClawAppState
|
||||||
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
import openclawapp.composeapp.generated.resources.Res
|
import cn.xiaobai.openclawapp.feature.chat.ChatScreen
|
||||||
import openclawapp.composeapp.generated.resources.compose_multiplatform
|
import cn.xiaobai.openclawapp.feature.config.ServerConfigScreen
|
||||||
|
import cn.xiaobai.openclawapp.feature.sessions.SessionListScreen
|
||||||
|
import cn.xiaobai.openclawapp.feature.settings.SettingsScreen
|
||||||
|
import cn.xiaobai.openclawapp.feature.status.StatusScreen
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
|
||||||
fun App() {
|
fun App() {
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
var showContent by remember { mutableStateOf(false) }
|
val appState = remember { OpenClawAppState() }
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
if (!appState.isConfigured) {
|
||||||
.background(MaterialTheme.colorScheme.primaryContainer)
|
var baseUrl by remember { mutableStateOf(appState.serverConfig.baseUrl) }
|
||||||
.safeContentPadding()
|
var token by remember { mutableStateOf(appState.serverConfig.token) }
|
||||||
.fillMaxSize(),
|
var agent by remember { mutableStateOf(appState.serverConfig.defaultAgent) }
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
) {
|
ServerConfigScreen(
|
||||||
Button(onClick = { showContent = !showContent }) {
|
baseUrl = baseUrl,
|
||||||
Text("Click me!")
|
token = token,
|
||||||
|
defaultAgent = agent,
|
||||||
|
onBaseUrlChange = { baseUrl = it },
|
||||||
|
onTokenChange = { token = it },
|
||||||
|
onDefaultAgentChange = { agent = it },
|
||||||
|
onConnect = {
|
||||||
|
appState.connect(
|
||||||
|
ServerConfig(
|
||||||
|
baseUrl = baseUrl,
|
||||||
|
token = token,
|
||||||
|
defaultAgent = agent,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
OpenClawRoot(appState)
|
||||||
}
|
}
|
||||||
AnimatedVisibility(showContent) {
|
|
||||||
val greeting = remember { Greeting().greet() }
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
) {
|
|
||||||
Image(painterResource(Res.drawable.compose_multiplatform), null)
|
|
||||||
Text("Compose: $greeting")
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
private fun OpenClawRoot(appState: OpenClawAppState) {
|
||||||
|
val activeSession = appState.activeSessionId?.let(appState.repository::findSession)
|
||||||
|
|
||||||
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
CenterAlignedTopAppBar(
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = when {
|
||||||
|
activeSession != null -> activeSession.title
|
||||||
|
appState.selectedTab == MainTab.Sessions -> "OpenClaw"
|
||||||
|
appState.selectedTab == MainTab.Status -> "运行状态"
|
||||||
|
appState.selectedTab == MainTab.Settings -> "设置"
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
bottomBar = {
|
||||||
|
if (activeSession == null) {
|
||||||
|
NavigationBar {
|
||||||
|
NavigationBarItem(
|
||||||
|
selected = appState.selectedTab == MainTab.Sessions,
|
||||||
|
onClick = { appState.selectedTab = MainTab.Sessions },
|
||||||
|
icon = { Text("💬") },
|
||||||
|
label = { Text("会话") },
|
||||||
|
)
|
||||||
|
NavigationBarItem(
|
||||||
|
selected = appState.selectedTab == MainTab.Status,
|
||||||
|
onClick = { appState.selectedTab = MainTab.Status },
|
||||||
|
icon = { Text("📡") },
|
||||||
|
label = { Text("状态") },
|
||||||
|
)
|
||||||
|
NavigationBarItem(
|
||||||
|
selected = appState.selectedTab == MainTab.Settings,
|
||||||
|
onClick = { appState.selectedTab = MainTab.Settings },
|
||||||
|
icon = { Text("⚙️") },
|
||||||
|
label = { Text("设置") },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) { innerPadding ->
|
||||||
|
val contentModifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(innerPadding)
|
||||||
|
|
||||||
|
when {
|
||||||
|
activeSession != null -> ChatScreen(
|
||||||
|
modifier = contentModifier,
|
||||||
|
sessionTitle = activeSession.title,
|
||||||
|
messages = appState.repository.messagesFor(activeSession.id),
|
||||||
|
onBack = appState::closeChat,
|
||||||
|
onSend = { text -> appState.repository.sendMessage(activeSession.id, text) },
|
||||||
|
)
|
||||||
|
|
||||||
|
appState.selectedTab == MainTab.Sessions -> SessionListScreen(
|
||||||
|
modifier = contentModifier,
|
||||||
|
sessions = appState.repository.sessions,
|
||||||
|
onOpenSession = appState::openSession,
|
||||||
|
)
|
||||||
|
|
||||||
|
appState.selectedTab == MainTab.Status -> StatusScreen(
|
||||||
|
modifier = contentModifier,
|
||||||
|
status = appState.repository.status,
|
||||||
|
)
|
||||||
|
|
||||||
|
appState.selectedTab == MainTab.Settings -> SettingsScreen(
|
||||||
|
modifier = contentModifier,
|
||||||
|
serverConfig = appState.serverConfig,
|
||||||
|
currentModel = appState.repository.status.currentModel,
|
||||||
|
availableAgents = appState.repository.availableAgents,
|
||||||
|
onSelectAgent = appState::updateDefaultAgent,
|
||||||
|
onDisconnect = appState::disconnect,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package cn.xiaobai.openclawapp.app
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import cn.xiaobai.openclawapp.data.MockOpenClawRepository
|
||||||
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
|
|
||||||
|
class OpenClawAppState {
|
||||||
|
var isConfigured by mutableStateOf(false)
|
||||||
|
var selectedTab by mutableStateOf(MainTab.Sessions)
|
||||||
|
var activeSessionId by mutableStateOf<String?>(null)
|
||||||
|
var serverConfig by mutableStateOf(ServerConfig())
|
||||||
|
val repository = MockOpenClawRepository()
|
||||||
|
|
||||||
|
fun connect(config: ServerConfig) {
|
||||||
|
serverConfig = config
|
||||||
|
isConfigured = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun disconnect() {
|
||||||
|
isConfigured = false
|
||||||
|
activeSessionId = null
|
||||||
|
selectedTab = MainTab.Sessions
|
||||||
|
}
|
||||||
|
|
||||||
|
fun openSession(sessionId: String) {
|
||||||
|
activeSessionId = sessionId
|
||||||
|
}
|
||||||
|
|
||||||
|
fun closeChat() {
|
||||||
|
activeSessionId = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateDefaultAgent(agent: String) {
|
||||||
|
serverConfig = serverConfig.copy(defaultAgent = agent)
|
||||||
|
repository.status = repository.status.copy(defaultAgent = agent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class MainTab {
|
||||||
|
Sessions,
|
||||||
|
Status,
|
||||||
|
Settings,
|
||||||
|
}
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
package cn.xiaobai.openclawapp.data
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
class MockOpenClawRepository {
|
||||||
|
val availableAgents = listOf("main", "pm", "rd-lead", "backend-dev")
|
||||||
|
|
||||||
|
var sessions by mutableStateOf(
|
||||||
|
listOf(
|
||||||
|
SessionSummary(
|
||||||
|
id = "agent:main:main",
|
||||||
|
title = "主会话",
|
||||||
|
lastMessage = "先把移动端的接入方案定下来。",
|
||||||
|
updatedAt = "刚刚",
|
||||||
|
),
|
||||||
|
SessionSummary(
|
||||||
|
id = "agent:main:rd-lead",
|
||||||
|
title = "rd-lead",
|
||||||
|
lastMessage = "架构方案已经同步。",
|
||||||
|
updatedAt = "10 分钟前",
|
||||||
|
),
|
||||||
|
SessionSummary(
|
||||||
|
id = "agent:main:pm",
|
||||||
|
title = "pm",
|
||||||
|
lastMessage = "MVP 范围保持克制。",
|
||||||
|
updatedAt = "1 小时前",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
var status by mutableStateOf(
|
||||||
|
ServerStatus(
|
||||||
|
online = true,
|
||||||
|
openClawVersion = "2026.2.26",
|
||||||
|
currentModel = "cliproxy/gpt-5.4",
|
||||||
|
defaultAgent = "main",
|
||||||
|
updatedAt = "刚刚",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
private var messageStore by mutableStateOf(
|
||||||
|
mapOf(
|
||||||
|
"agent:main:main" to listOf(
|
||||||
|
ChatMessage("1", MessageRole.System, "已连接到 OpenClaw Mobile Gateway", "20:01", "connected"),
|
||||||
|
ChatMessage("2", MessageRole.User, "帮我规划一下移动端接入方案。", "20:03"),
|
||||||
|
ChatMessage("3", MessageRole.Assistant, "建议先做 App + BFF + OpenClaw 三层结构。", "20:03", "done"),
|
||||||
|
),
|
||||||
|
"agent:main:rd-lead" to listOf(
|
||||||
|
ChatMessage("4", MessageRole.User, "架构文档准备好了没?", "19:40"),
|
||||||
|
ChatMessage("5", MessageRole.Assistant, "已经整理成 ARCHITECTURE.md。", "19:41", "done"),
|
||||||
|
),
|
||||||
|
"agent:main:pm" to listOf(
|
||||||
|
ChatMessage("6", MessageRole.Assistant, "先做会话、聊天、状态、设置四个页面。", "18:20", "done"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fun findSession(sessionId: String): SessionSummary? = sessions.firstOrNull { it.id == sessionId }
|
||||||
|
|
||||||
|
fun messagesFor(sessionId: String): List<ChatMessage> = messageStore[sessionId].orEmpty()
|
||||||
|
|
||||||
|
fun sendMessage(sessionId: String, text: String) {
|
||||||
|
val currentMessages = messageStore[sessionId].orEmpty()
|
||||||
|
val newMessages = currentMessages + ChatMessage(
|
||||||
|
id = Random.nextInt().toString(),
|
||||||
|
role = MessageRole.User,
|
||||||
|
text = text,
|
||||||
|
createdAt = "现在",
|
||||||
|
) + ChatMessage(
|
||||||
|
id = Random.nextInt().toString(),
|
||||||
|
role = MessageRole.Assistant,
|
||||||
|
text = "Mock 回复:后面这里会替换成真实 BFF 流式消息。",
|
||||||
|
createdAt = "现在",
|
||||||
|
status = "stream-complete",
|
||||||
|
)
|
||||||
|
|
||||||
|
messageStore = messageStore + (sessionId to newMessages)
|
||||||
|
sessions = sessions.map {
|
||||||
|
if (it.id == sessionId) it.copy(lastMessage = text, updatedAt = "现在") else it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package cn.xiaobai.openclawapp.data
|
||||||
|
|
||||||
|
data class ServerConfig(
|
||||||
|
val baseUrl: String = "https://mobile-gateway.example.com",
|
||||||
|
val token: String = "",
|
||||||
|
val defaultAgent: String = "main",
|
||||||
|
)
|
||||||
|
|
||||||
|
data class SessionSummary(
|
||||||
|
val id: String,
|
||||||
|
val title: String,
|
||||||
|
val lastMessage: String,
|
||||||
|
val updatedAt: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class ChatMessage(
|
||||||
|
val id: String,
|
||||||
|
val role: MessageRole,
|
||||||
|
val text: String,
|
||||||
|
val createdAt: String,
|
||||||
|
val status: String? = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
enum class MessageRole {
|
||||||
|
User,
|
||||||
|
Assistant,
|
||||||
|
System,
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ServerStatus(
|
||||||
|
val online: Boolean,
|
||||||
|
val openClawVersion: String,
|
||||||
|
val currentModel: String,
|
||||||
|
val defaultAgent: String,
|
||||||
|
val updatedAt: String,
|
||||||
|
)
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package cn.xiaobai.openclawapp.feature.chat
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import cn.xiaobai.openclawapp.data.ChatMessage
|
||||||
|
import cn.xiaobai.openclawapp.data.MessageRole
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ChatScreen(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
sessionTitle: String,
|
||||||
|
messages: List<ChatMessage>,
|
||||||
|
onBack: () -> Unit,
|
||||||
|
onSend: (String) -> Unit,
|
||||||
|
) {
|
||||||
|
var input by remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
Button(onClick = onBack) { Text("返回") }
|
||||||
|
Column {
|
||||||
|
Text(sessionTitle, style = MaterialTheme.typography.titleLarge)
|
||||||
|
Text(
|
||||||
|
"当前是 Mock 对话流,后面这里会接 SSE / WebSocket。",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyColumn(
|
||||||
|
modifier = Modifier.weight(1f).fillMaxWidth(),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
|
) {
|
||||||
|
items(messages, key = { it.id }) { message ->
|
||||||
|
MessageBubble(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = input,
|
||||||
|
onValueChange = { input = it },
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
label = { Text("输入消息") },
|
||||||
|
placeholder = { Text("给 OpenClaw 发一句话") },
|
||||||
|
)
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
if (input.isNotBlank()) {
|
||||||
|
onSend(input.trim())
|
||||||
|
input = ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text("发送")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun MessageBubble(message: ChatMessage) {
|
||||||
|
val background = when (message.role) {
|
||||||
|
MessageRole.User -> MaterialTheme.colorScheme.primaryContainer
|
||||||
|
MessageRole.Assistant -> MaterialTheme.colorScheme.secondaryContainer
|
||||||
|
MessageRole.System -> MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
}
|
||||||
|
|
||||||
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(background)
|
||||||
|
.padding(14.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = when (message.role) {
|
||||||
|
MessageRole.User -> "你"
|
||||||
|
MessageRole.Assistant -> "OpenClaw"
|
||||||
|
MessageRole.System -> "系统"
|
||||||
|
},
|
||||||
|
style = MaterialTheme.typography.labelLarge,
|
||||||
|
)
|
||||||
|
Text(text = message.text, style = MaterialTheme.typography.bodyLarge)
|
||||||
|
Row(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Text(
|
||||||
|
text = message.createdAt,
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
if (message.status != null) {
|
||||||
|
Text(
|
||||||
|
text = message.status,
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
package cn.xiaobai.openclawapp.feature.config
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ServerConfigScreen(
|
||||||
|
baseUrl: String,
|
||||||
|
token: String,
|
||||||
|
defaultAgent: String,
|
||||||
|
onBaseUrlChange: (String) -> Unit,
|
||||||
|
onTokenChange: (String) -> Unit,
|
||||||
|
onDefaultAgentChange: (String) -> Unit,
|
||||||
|
onConnect: () -> Unit,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(20.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
) {
|
||||||
|
Text("连接 OpenClaw", style = MaterialTheme.typography.headlineMedium)
|
||||||
|
Text(
|
||||||
|
"第一版先连接你自己的 Mobile Gateway / BFF,后面再接真实 OpenClaw 服务。",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
|
||||||
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = baseUrl,
|
||||||
|
onValueChange = onBaseUrlChange,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
label = { Text("服务器地址") },
|
||||||
|
placeholder = { Text("https://mobile-gateway.example.com") },
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = token,
|
||||||
|
onValueChange = onTokenChange,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
label = { Text("访问令牌") },
|
||||||
|
placeholder = { Text("输入登录 token") },
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = defaultAgent,
|
||||||
|
onValueChange = onDefaultAgentChange,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
label = { Text("默认 Agent") },
|
||||||
|
placeholder = { Text("main") },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(onClick = onConnect, modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Text("进入应用")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
package cn.xiaobai.openclawapp.feature.sessions
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import cn.xiaobai.openclawapp.data.SessionSummary
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SessionListScreen(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
sessions: List<SessionSummary>,
|
||||||
|
onOpenSession: (String) -> Unit,
|
||||||
|
) {
|
||||||
|
LazyColumn(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
item {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
|
Text("会话", style = MaterialTheme.typography.headlineMedium)
|
||||||
|
Text(
|
||||||
|
"先用 Mock 数据跑通列表和聊天流程,下一步再接真实 OpenClaw。",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
items(sessions, key = { it.id }) { session ->
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable { onOpenSession(session.id) },
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
) {
|
||||||
|
Row(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Text(
|
||||||
|
text = session.title,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = session.updatedAt,
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = session.lastMessage,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+94
@@ -0,0 +1,94 @@
|
|||||||
|
package cn.xiaobai.openclawapp.feature.settings
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import cn.xiaobai.openclawapp.data.ServerConfig
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SettingsScreen(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
serverConfig: ServerConfig,
|
||||||
|
currentModel: String,
|
||||||
|
availableAgents: List<String>,
|
||||||
|
onSelectAgent: (String) -> Unit,
|
||||||
|
onDisconnect: () -> Unit,
|
||||||
|
) {
|
||||||
|
LazyColumn(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
item {
|
||||||
|
Text("设置", style = MaterialTheme.typography.headlineMedium)
|
||||||
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
SettingCard(label = "服务器地址", value = serverConfig.baseUrl)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
SettingCard(label = "当前模型", value = currentModel)
|
||||||
|
}
|
||||||
|
item {
|
||||||
|
SettingCard(label = "默认 Agent", value = serverConfig.defaultAgent)
|
||||||
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
Text("可选 Agent", style = MaterialTheme.typography.titleMedium)
|
||||||
|
}
|
||||||
|
|
||||||
|
items(availableAgents) { agent ->
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable { onSelectAgent(agent) },
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
) {
|
||||||
|
Text(agent, modifier = Modifier.weight(1f))
|
||||||
|
if (serverConfig.defaultAgent == agent) {
|
||||||
|
Text("当前")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
Button(onClick = onDisconnect, modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Text("断开连接")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SettingCard(label: String, value: String) {
|
||||||
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
) {
|
||||||
|
Text(label, style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
Text(value, style = MaterialTheme.typography.bodyLarge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package cn.xiaobai.openclawapp.feature.status
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import cn.xiaobai.openclawapp.data.ServerStatus
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun StatusScreen(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
status: ServerStatus,
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
) {
|
||||||
|
Text("运行状态", style = MaterialTheme.typography.headlineMedium)
|
||||||
|
|
||||||
|
StatusCard("连接状态", if (status.online) "在线" else "离线")
|
||||||
|
StatusCard("OpenClaw 版本", status.openClawVersion)
|
||||||
|
StatusCard("当前模型", status.currentModel)
|
||||||
|
StatusCard("默认 Agent", status.defaultAgent)
|
||||||
|
StatusCard("最后更新时间", status.updatedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun StatusCard(label: String, value: String) {
|
||||||
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
) {
|
||||||
|
Text(label, style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
Text(value, style = MaterialTheme.typography.titleMedium)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.11.2"
|
agp = "8.8.2"
|
||||||
android-compileSdk = "36"
|
android-compileSdk = "36"
|
||||||
android-minSdk = "33"
|
android-minSdk = "33"
|
||||||
android-targetSdk = "36"
|
android-targetSdk = "36"
|
||||||
|
|||||||
Reference in new issue
Block a user