|
...
|
...
|
@@ -3,6 +3,7 @@ import 'dart:async'; |
|
|
|
import 'package:doublefeel_flutter/core/logging/app_logger.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/network/api/health_api.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/network/api/harmony_api.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/network/dio_client.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/platform/pigeon_api_facade.dart';
|
|
|
|
import 'package:doublefeel_flutter/core/result/app_result.dart';
|
|
|
|
import 'package:doublefeel_flutter/data/models/harmony/hm_health_data.dart';
|
|
...
|
...
|
@@ -36,12 +37,25 @@ OhosHealthRawDataSyncService createDefaultOhosHealthRawDataSyncService({ |
|
|
|
remoteDataSource: OhosHarmonyHealthRawDataRemoteDataSource(
|
|
|
|
HarmonyApiOhosRawDataClient(
|
|
|
|
Get.find<HarmonyApi>(),
|
|
|
|
healthApi: Get.isRegistered<HealthApi>() ? Get.find<HealthApi>() : null,
|
|
|
|
healthApi: _resolveHealthApi(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// HealthApi is normally lazy-registered. Activity-goal synchronization can
|
|
|
|
/// start before that lazy dependency is materialized, so construct the same
|
|
|
|
/// lightweight API wrapper from the app-wide DioClient as a fallback.
|
|
|
|
HealthApi? _resolveHealthApi() {
|
|
|
|
if (Get.isRegistered<HealthApi>()) {
|
|
|
|
return Get.find<HealthApi>();
|
|
|
|
}
|
|
|
|
if (Get.isRegistered<DioClient>()) {
|
|
|
|
return HealthApi(Get.find<DioClient>());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient {
|
|
|
|
const HarmonyApiOhosRawDataClient(
|
|
|
|
this._harmonyApi, {
|
|
...
|
...
|
@@ -130,12 +144,6 @@ class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { |
|
|
|
|
|
|
|
@override
|
|
|
|
Future<AppResult<V2ActivityTarget>> getActivityGoal() async {
|
|
|
|
final useRemoteData = false;
|
|
|
|
if (!_preferNativeHealthData || useRemoteData) {
|
|
|
|
AppLogger.i('[OHOS_ACTIVITY_GOAL] source=remote native_enabled=false');
|
|
|
|
return _harmonyApi.getActivityGoal();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
final goal =
|
|
|
|
await (_healthKitApi ?? AppHealthKitHostApi()).readActivityGoal();
|
|
...
|
...
|
@@ -151,10 +159,9 @@ class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient { |
|
|
|
'[OHOS_ACTIVITY_GOAL] '
|
|
|
|
'source=native value=${_goalLogValue(nativeGoal)}',
|
|
|
|
);
|
|
|
|
if (useRemoteData || _preferNativeHealthData) {
|
|
|
|
// 上传目标值到服务器
|
|
|
|
unawaited(_uploadNativeActivityGoal(nativeGoal));
|
|
|
|
}
|
|
|
|
// Deliberately do not await: a failed request must not prevent the
|
|
|
|
// user from entering the app or the health-data sync from continuing.
|
|
|
|
unawaited(_uploadNativeActivityGoal(nativeGoal));
|
|
|
|
return AppSuccess(nativeGoal);
|
|
|
|
}
|
|
|
|
}
|
...
|
...
|
|