Commit 5d03cfc94ab61c9ccc9a0f9817bdd40c90786164

Authored by 权海
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
... ... @@ -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,13 @@ class HarmonyApiOhosRawDataClient implements OhosHarmonyRawDataClient {
'[OHOS_ACTIVITY_GOAL] '
'source=native value=${_goalLogValue(nativeGoal)}',
);
if (useRemoteData || _preferNativeHealthData) {
// 上传目标值到服务器
unawaited(_uploadNativeActivityGoal(nativeGoal));
}
AppLogger.i(
'[OHOS_ACTIVITY_GOAL] '
'upload_scheduled value=${_goalLogValue(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);
}
}
... ...