refactor(ui): 重构无人机控制器界面组件结构
- 将 HomeScreen 组件重命名为 PilotHomeScreen 并调整参数 - 移除大量内联的 UI 组件实现,改为独立的可复用组件 - 优化地图预览显示逻辑,更新为更简洁的定位信息展示 - 重构飞行控制面板布局,调整尺寸和间距参数 - 添加更多菜单选项,整合飞前检查等功能入口 - 更新遥测数据显示组件,优化仪表盘读数展示 - 调整按钮样式和交互效果,改进视觉反馈 - 优化响应式布局计算,提升不同屏幕尺寸适配效果
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.zklh.dronecontroller.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.zklh.dronecontroller.core.msdk.DroneSdkState
|
||||
import com.zklh.dronecontroller.core.telemetry.TelemetrySnapshot
|
||||
import com.zklh.dronecontroller.core.telemetry.hasReliableRtkPosition
|
||||
|
||||
/** Read-only checks. The former placeholder sliders never wrote settings to the aircraft. */
|
||||
@Composable
|
||||
internal fun PilotPreflightScreen(sdkState: DroneSdkState, telemetry: TelemetrySnapshot, onClose: () -> Unit) {
|
||||
val connected = sdkState.productConnected
|
||||
fun reading(value: String) = if (connected) value else "—"
|
||||
Column(Modifier.fillMaxSize().background(Color(0xFF0D1118)).padding(20.dp)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text("飞前检查", color = Color.White, fontSize = 24.sp, fontWeight = FontWeight.Bold)
|
||||
Text("设备状态", color = Color(0xFF9CABB9), fontSize = 12.sp)
|
||||
}
|
||||
IconButton(onClick = onClose) { Icon(Icons.Filled.Close, "关闭飞前检查", tint = Color.White) }
|
||||
}
|
||||
Spacer(Modifier.height(18.dp))
|
||||
Row(Modifier.weight(1f).verticalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
CheckCard("连接与定位", listOf(
|
||||
"飞机连接" to if (connected) "已连接" else "未连接",
|
||||
"遥控链路" to if (sdkState.productLinkConnected) "已连接" else "未连接",
|
||||
"卫星数" to reading(if (telemetry.gpsValid) telemetry.gpsSatelliteCount.toString() else "定位不可用"),
|
||||
"返航点" to reading(if (telemetry.homeLocationValid) "已记录" else "未取得"),
|
||||
"RTK" to reading(if (telemetry.hasReliableRtkForCheck()) "定位可用" else if (telemetry.rtkEnabled) "等待定位" else "未启用")
|
||||
), Modifier.weight(1f))
|
||||
CheckCard("电池与设备", listOf(
|
||||
"飞行器电量" to reading(if (telemetry.batteryPercent in 0..100) "${telemetry.batteryPercent}%" else "—"),
|
||||
"遥控器电量" to if (sdkState.productLinkConnected && telemetry.rcBatteryPercent in 0..100) "${telemetry.rcBatteryPercent}%" else "—",
|
||||
"电池温度" to reading(if (telemetry.batteryTemperatureKnown) "${instrumentNumber(telemetry.batteryTemperature)} °C" else "—"),
|
||||
"预计剩余飞行时间" to reading(if (telemetry.remainingFlightTimeKnown) "${telemetry.remainingFlightTime / 60} 分钟" else "—"),
|
||||
"固件版本" to reading(telemetry.firmwareVersion.ifBlank { "—" })
|
||||
), Modifier.weight(1f))
|
||||
}
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Text(sdkState.registerError ?: sdkState.aircraftConnectionDetail, color = Color(0xFF9CABB9), fontSize = 12.sp)
|
||||
Text("起飞前请检查机臂、桨叶及周围环境,并确认返航与避障设置。", color = Color(0xFF9CABB9), fontSize = 12.sp, modifier = Modifier.padding(top = 8.dp))
|
||||
}
|
||||
}
|
||||
|
||||
private fun TelemetrySnapshot.hasReliableRtkForCheck() =
|
||||
hasReliableRtkPosition()
|
||||
|
||||
@Composable
|
||||
private fun CheckCard(title: String, rows: List<Pair<String, String>>, modifier: Modifier) {
|
||||
Surface(color = Color(0xFF171F2A), shape = RoundedCornerShape(16.dp), modifier = modifier) {
|
||||
Column(Modifier.padding(18.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
Text(title, color = Color.White, fontSize = 18.sp, fontWeight = FontWeight.Bold)
|
||||
rows.forEach { (label, value) ->
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(label, color = Color(0xFF9CABB9), fontSize = 13.sp, modifier = Modifier.weight(1f))
|
||||
Text(value, color = Color.White, fontSize = 13.sp, modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user