feat: 电量变化时上报设备状态到服务端
之前 reportDeviceStatus 接口只定义未调用,手机端无法获取实时电量 现在电量变化 >=5% 时自动调用 setWatchStatusByImeiFormWatch 上报 去抖防止频繁请求 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -47,6 +47,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
@Inject lateinit var userPrefs: UserPrefs
|
||||
@Inject lateinit var eventBus: EventBus
|
||||
@Inject lateinit var taskApi: TaskApi
|
||||
@Inject lateinit var commonApi: com.xiaoqu.watch.network.api.CommonApi
|
||||
@Inject lateinit var bluetoothScanManager: com.xiaoqu.watch.service.manager.BluetoothScanManager
|
||||
@Inject lateinit var notificationManager: com.xiaoqu.watch.service.manager.NotificationManager
|
||||
@Inject lateinit var vibrationConfigManager: com.xiaoqu.watch.device.sensor.VibrationConfigManager
|
||||
@@ -464,6 +465,34 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 上次上报的电量(去抖:电量变化 >=5% 才上报) */
|
||||
private var lastReportedPower = -1
|
||||
|
||||
/**
|
||||
* 上报设备状态到服务端(电量、蓝牙、NFC)
|
||||
* 手机端从此接口获取手表电量
|
||||
*/
|
||||
private fun reportDeviceStatus(power: Int) {
|
||||
// 去抖:变化 >=5% 或首次才上报
|
||||
if (lastReportedPower >= 0 && kotlin.math.abs(power - lastReportedPower) < 5) return
|
||||
lastReportedPower = power
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
try {
|
||||
val params = hashMapOf<String, Any>(
|
||||
"imei" to devicePrefs.imei,
|
||||
"power" to power,
|
||||
"blueStatus" to 1,
|
||||
"nfcStatus" to 1
|
||||
)
|
||||
com.xiaoqu.watch.network.safeApiCall { commonApi.reportDeviceStatus(params) }
|
||||
timber.log.Timber.d("设备状态上报: power=$power")
|
||||
} catch (e: Exception) {
|
||||
timber.log.Timber.w(e, "设备状态上报失败")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 调试模式:500ms 内连续点击 6 次触发 */
|
||||
private fun checkDebugMode() {
|
||||
val now = System.currentTimeMillis()
|
||||
@@ -493,6 +522,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
statusBar.updateBattery(event.level, event.isCharging)
|
||||
bluetoothScanManager.currentPower = event.level
|
||||
updateConfigBattery(event.level, event.isCharging)
|
||||
reportDeviceStatus(event.level)
|
||||
}
|
||||
// 蓝牙状态变化
|
||||
is AppEvent.BluetoothStateChanged -> {
|
||||
|
||||
Reference in New Issue
Block a user