From 71eebe7b0ca84d2890f9dd4c9bb96294c45c219f Mon Sep 17 00:00:00 2001 From: dongliang Date: Thu, 30 Apr 2026 22:06:53 +0930 Subject: [PATCH] =?UTF-8?q?feat(config):=20=E8=AE=BE=E7=BD=AE=E9=A1=B5?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对照旧版 hardInfo.vue 补全缺失的 4 个字段: - 设备名称(bluetoothName,来自 DevicePrefs) - 蓝牙MAC(bluetoothMac,来自 DevicePrefs) - 蓝牙连接状态(动态,通过 EventBus BluetoothDevice 事件更新) - 电池(动态,通过 EventBus BatteryChanged 事件 + 初始化获取) Co-Authored-By: Claude Opus 4.6 (1M context) --- .../com/xiaoqu/watch/ui/home/HomeFragment.kt | 34 +++++++++++++++++-- app/src/main/res/layout/page_config.xml | 20 +++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt b/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt index bd01388..aaed378 100644 --- a/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/xiaoqu/watch/ui/home/HomeFragment.kt @@ -329,6 +329,7 @@ class HomeFragment : BaseFragment() { 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() { // 设备信息 configPageView.findViewById(R.id.tvModel)?.text = "${devicePrefs.brand} ${devicePrefs.model}" + configPageView.findViewById(R.id.tvDeviceName)?.text = + devicePrefs.bluetoothName.ifEmpty { "未知" } configPageView.findViewById(R.id.tvOsVersion)?.text = "Android ${devicePrefs.osVersion}" configPageView.findViewById(R.id.tvImei)?.text = run { @@ -445,8 +448,27 @@ class HomeFragment : BaseFragment() { if (imei.length > 6) "${imei.substring(0, 3)}***${imei.substring(imei.length - 3)}" else imei } - configPageView.findViewById(R.id.tvAppVersion)?.text = - "v${BuildConfig.VERSION_NAME}" + configPageView.findViewById(R.id.tvBluetoothMac)?.text = + devicePrefs.bluetoothMac.ifEmpty { "未知" } + // 蓝牙连接状态和电池 — 动态数据,初始化后通过 EventBus 更新 + updateConfigBluetooth(false) + updateConfigBattery(0, false) + } + + /** 更新设置页蓝牙连接状态 */ + private fun updateConfigBluetooth(isConnected: Boolean) { + if (::configPageView.isInitialized) { + configPageView.findViewById(R.id.tvBluetoothStatus)?.text = + if (isConnected) "已连接" else "未连接" + } + } + + /** 更新设置页电池信息 */ + private fun updateConfigBattery(level: Int, isCharging: Boolean) { + if (::configPageView.isInitialized) { + val suffix = if (isCharging) " 充电中" else "" + configPageView.findViewById(R.id.tvBattery)?.text = "${level}%${suffix}" + } } /** 调试模式:500ms 内连续点击 6 次触发 */ @@ -477,11 +499,19 @@ class HomeFragment : BaseFragment() { 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} 条)") diff --git a/app/src/main/res/layout/page_config.xml b/app/src/main/res/layout/page_config.xml index a690bcb..59f9df0 100644 --- a/app/src/main/res/layout/page_config.xml +++ b/app/src/main/res/layout/page_config.xml @@ -83,6 +83,11 @@ + + + + + @@ -93,6 +98,21 @@ + + + + + + + + + + + + + + +