feat(config): 设置页补全设备信息字段
对照旧版 hardInfo.vue 补全缺失的 4 个字段: - 设备名称(bluetoothName,来自 DevicePrefs) - 蓝牙MAC(bluetoothMac,来自 DevicePrefs) - 蓝牙连接状态(动态,通过 EventBus BluetoothDevice 事件更新) - 电池(动态,通过 EventBus BatteryChanged 事件 + 初始化获取) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -329,6 +329,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
val isCharging = status == android.os.BatteryManager.BATTERY_STATUS_CHARGING
|
||||
|| status == android.os.BatteryManager.BATTERY_STATUS_FULL
|
||||
statusBar.updateBattery(percent, isCharging)
|
||||
updateConfigBattery(percent, isCharging)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,6 +439,8 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
// 设备信息
|
||||
configPageView.findViewById<TextView>(R.id.tvModel)?.text =
|
||||
"${devicePrefs.brand} ${devicePrefs.model}"
|
||||
configPageView.findViewById<TextView>(R.id.tvDeviceName)?.text =
|
||||
devicePrefs.bluetoothName.ifEmpty { "未知" }
|
||||
configPageView.findViewById<TextView>(R.id.tvOsVersion)?.text =
|
||||
"Android ${devicePrefs.osVersion}"
|
||||
configPageView.findViewById<TextView>(R.id.tvImei)?.text = run {
|
||||
@@ -445,8 +448,27 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
if (imei.length > 6) "${imei.substring(0, 3)}***${imei.substring(imei.length - 3)}"
|
||||
else imei
|
||||
}
|
||||
configPageView.findViewById<TextView>(R.id.tvAppVersion)?.text =
|
||||
"v${BuildConfig.VERSION_NAME}"
|
||||
configPageView.findViewById<TextView>(R.id.tvBluetoothMac)?.text =
|
||||
devicePrefs.bluetoothMac.ifEmpty { "未知" }
|
||||
// 蓝牙连接状态和电池 — 动态数据,初始化后通过 EventBus 更新
|
||||
updateConfigBluetooth(false)
|
||||
updateConfigBattery(0, false)
|
||||
}
|
||||
|
||||
/** 更新设置页蓝牙连接状态 */
|
||||
private fun updateConfigBluetooth(isConnected: Boolean) {
|
||||
if (::configPageView.isInitialized) {
|
||||
configPageView.findViewById<TextView>(R.id.tvBluetoothStatus)?.text =
|
||||
if (isConnected) "已连接" else "未连接"
|
||||
}
|
||||
}
|
||||
|
||||
/** 更新设置页电池信息 */
|
||||
private fun updateConfigBattery(level: Int, isCharging: Boolean) {
|
||||
if (::configPageView.isInitialized) {
|
||||
val suffix = if (isCharging) " 充电中" else ""
|
||||
configPageView.findViewById<TextView>(R.id.tvBattery)?.text = "${level}%${suffix}"
|
||||
}
|
||||
}
|
||||
|
||||
/** 调试模式:500ms 内连续点击 6 次触发 */
|
||||
@@ -477,11 +499,19 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
is AppEvent.BatteryChanged -> {
|
||||
statusBar.updateBattery(event.level, event.isCharging)
|
||||
bluetoothScanManager.currentPower = event.level
|
||||
updateConfigBattery(event.level, event.isCharging)
|
||||
}
|
||||
// 蓝牙状态变化
|
||||
is AppEvent.BluetoothStateChanged -> {
|
||||
statusBar.updateBluetooth(event.isOn)
|
||||
}
|
||||
// 蓝牙设备连接/断开 → 更新设置页
|
||||
is AppEvent.BluetoothDeviceConnected -> {
|
||||
updateConfigBluetooth(true)
|
||||
}
|
||||
is AppEvent.BluetoothDeviceDisconnected -> {
|
||||
updateConfigBluetooth(false)
|
||||
}
|
||||
// 新任务到达(由 MainActivity→NotificationManager 处理后发出)
|
||||
is AppEvent.NewTaskArrived -> {
|
||||
Timber.d("首页: 新任务到达 (${event.count} 条)")
|
||||
|
||||
Reference in New Issue
Block a user