Commit 5d03cfc94ab61c9ccc9a0f9817bdd40c90786164
1 parent
fd20342d
feat(ui):华为目标值获取数据源修改为原生,并增加上传
xx feat(ui):修复ohos目标写法 xx (cherry picked from commit 3e164451) # Conflicts: # lib/core/services/raw_data_service/platform_ohos/ohos_harmony_health_raw_data_sync_service_factory.dart
Showing
1 changed file
with
22 additions
and
11 deletions
| @@ -3,6 +3,7 @@ import 'dart:async'; | @@ -3,6 +3,7 @@ import 'dart:async'; | ||
| 3 | import 'package:doublefeel_flutter/core/logging/app_logger.dart'; | 3 | import 'package:doublefeel_flutter/core/logging/app_logger.dart'; |
| 4 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; | 4 | import 'package:doublefeel_flutter/core/network/api/health_api.dart'; |
| 5 | import 'package:doublefeel_flutter/core/network/api/harmony_api.dart'; | 5 | import 'package:doublefeel_flutter/core/network/api/harmony_api.dart'; |
| 6 | +import 'package:doublefeel_flutter/core/network/dio_client.dart'; | ||
| 6 | import 'package:doublefeel_flutter/core/platform/pigeon_api_facade.dart'; | 7 | import 'package:doublefeel_flutter/core/platform/pigeon_api_facade.dart'; |
| 7 | import 'package:doublefeel_flutter/core/result/app_result.dart'; | 8 | import 'package:doublefeel_flutter/core/result/app_result.dart'; |
| 8 | import 'package:doublefeel_flutter/data/models/harmony/hm_health_data.dart'; | 9 | import 'package:doublefeel_flutter/data/models/harmony/hm_health_data.dart'; |
| @@ -36,12 +37,25 @@ OhosHealthRawDataSyncService createDefaultOhosHealthRawDataSyncService({ | @@ -36,12 +37,25 @@ OhosHealthRawDataSyncService createDefaultOhosHealthRawDataSyncService({ | ||
| 36 | remoteDataSource: OhosHarmonyHealthRawDataRemoteDataSource( | 37 | remoteDataSource: OhosHarmonyHealthRawDataRemoteDataSource( |
| 37 | HarmonyApiOhosRawDataClient( | 38 | HarmonyApiOhosRawDataClient( |
| 38 | Get.find<HarmonyApi>(), | 39 | Get.find<HarmonyApi>(), |
| 39 | - healthApi: Get.isRegistered<HealthApi>() ? Get.find<HealthApi>() : null, | 40 | + healthApi: _resolveHealthApi(), |
| 40 | ), | 41 | ), |
| 41 | ), | 42 | ), |
| 42 | ); | 43 | ); |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 46 | +/// HealthApi is normally lazy-registered. Activity-goal synchronization can | ||
| 47 | +/// start before that lazy dependency is materialized, so construct the same | ||
| 48 | +/// lightweight API wrapper from the app-wide DioClient as a fallback. | ||
| 49 | +HealthApi? _resolveHealthApi() { | ||
| 50 | + if (Get.isRegistered<HealthApi>()) { | ||
| 51 | + return Get.find<HealthApi>(); | ||
| 52 | + } | ||
| 53 | + if (Get.isRegistered<DioClient>()) { | ||
| 54 | + return HealthApi(Get.find<DioClient>()); | ||
| 55 | + } | ||
| 56 | + return null; | ||
| 57 | +} | ||
| 58 | + | ||
| 45 | class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { | 59 | class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { |
| 46 | const HarmonyApiOhosRawDataClient( | 60 | const HarmonyApiOhosRawDataClient( |
| 47 | this._harmonyApi, { | 61 | this._harmonyApi, { |
| @@ -130,12 +144,6 @@ class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { | @@ -130,12 +144,6 @@ class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { | ||
| 130 | 144 | ||
| 131 | @override | 145 | @override |
| 132 | Future<AppResult<V2ActivityTarget>> getActivityGoal() async { | 146 | Future<AppResult<V2ActivityTarget>> getActivityGoal() async { |
| 133 | - final useRemoteData = false; | ||
| 134 | - if (!_preferNativeHealthData || useRemoteData) { | ||
| 135 | - AppLogger.i('[OHOS_ACTIVITY_GOAL] source=remote native_enabled=false'); | ||
| 136 | - return _harmonyApi.getActivityGoal(); | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | try { | 147 | try { |
| 140 | final goal = | 148 | final goal = |
| 141 | await (_healthKitApi ?? AppHealthKitHostApi()).readActivityGoal(); | 149 | await (_healthKitApi ?? AppHealthKitHostApi()).readActivityGoal(); |
| @@ -151,10 +159,13 @@ class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { | @@ -151,10 +159,13 @@ class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { | ||
| 151 | '[OHOS_ACTIVITY_GOAL] ' | 159 | '[OHOS_ACTIVITY_GOAL] ' |
| 152 | 'source=native value=${_goalLogValue(nativeGoal)}', | 160 | 'source=native value=${_goalLogValue(nativeGoal)}', |
| 153 | ); | 161 | ); |
| 154 | - if (useRemoteData || _preferNativeHealthData) { | ||
| 155 | - // 上传目标值到服务器 | ||
| 156 | - unawaited(_uploadNativeActivityGoal(nativeGoal)); | ||
| 157 | - } | 162 | + AppLogger.i( |
| 163 | + '[OHOS_ACTIVITY_GOAL] ' | ||
| 164 | + 'upload_scheduled value=${_goalLogValue(nativeGoal)}', | ||
| 165 | + ); | ||
| 166 | + // Deliberately do not await: a failed request must not prevent the | ||
| 167 | + // user from entering the app or the health-data sync from continuing. | ||
| 168 | + unawaited(_uploadNativeActivityGoal(nativeGoal)); | ||
| 158 | return AppSuccess(nativeGoal); | 169 | return AppSuccess(nativeGoal); |
| 159 | } | 170 | } |
| 160 | } | 171 | } |
-
Please register or login to post a comment