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 @@ + + + + + + + + + + + + + + +