|
...
|
...
|
@@ -10,7 +10,10 @@ import 'package:get/get.dart'; |
|
|
|
|
|
|
|
import '../../../../core/logging/app_logger.dart';
|
|
|
|
import '../../../../core/services/raw_data_service/health_raw_data_core_service.dart';
|
|
|
|
import '../../../../core/services/raw_data_service/health_raw_models.dart';
|
|
|
|
import '../../../../core/services/raw_data_service/platform_ios/apple_health_raw_local_notification.dart';
|
|
|
|
import '../../../../data/local/user_preferences_storage.dart';
|
|
|
|
import '../../../../l10n/l10n_extensions.dart';
|
|
|
|
import '../../../../pigeon/platform_api.g.dart';
|
|
|
|
import '../../../routes/app_pages.dart';
|
|
|
|
|
|
...
|
...
|
@@ -33,6 +36,7 @@ enum DeveloperOptionsAction { |
|
|
|
shareFlutterObserverRecord,
|
|
|
|
shareUploadTaskRecord,
|
|
|
|
shareLocalNotificationDebugRecord,
|
|
|
|
sendTestHrvLocalNotification,
|
|
|
|
clearHealthRawDataDatabaseAndUploadLog,
|
|
|
|
globalEnv,
|
|
|
|
}
|
|
...
|
...
|
@@ -86,6 +90,10 @@ class DeveloperOptionsController extends GetxController { |
|
|
|
action: DeveloperOptionsAction.shareLocalNotificationDebugRecord,
|
|
|
|
),
|
|
|
|
DeveloperOptionsItem(
|
|
|
|
title: '测试本地推送 HRV',
|
|
|
|
action: DeveloperOptionsAction.sendTestHrvLocalNotification,
|
|
|
|
),
|
|
|
|
DeveloperOptionsItem(
|
|
|
|
title: '清除本地数据库、上传日志',
|
|
|
|
action: DeveloperOptionsAction.clearHealthRawDataDatabaseAndUploadLog,
|
|
|
|
),
|
|
...
|
...
|
@@ -127,6 +135,9 @@ class DeveloperOptionsController extends GetxController { |
|
|
|
case DeveloperOptionsAction.shareLocalNotificationDebugRecord:
|
|
|
|
await shareLocalNotificationDebugRecord();
|
|
|
|
break;
|
|
|
|
case DeveloperOptionsAction.sendTestHrvLocalNotification:
|
|
|
|
await sendTestHrvLocalNotification();
|
|
|
|
break;
|
|
|
|
case DeveloperOptionsAction.clearHealthRawDataDatabaseAndUploadLog:
|
|
|
|
await clearHealthRawDataDatabaseAndUploadLog();
|
|
|
|
break;
|
|
...
|
...
|
@@ -159,7 +170,9 @@ class DeveloperOptionsController extends GetxController { |
|
|
|
});
|
|
|
|
Get.offAllNamed(AppRoutes.login);
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
AppLogger.e('Set global env failed', error, stackTrace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case null:
|
|
...
|
...
|
@@ -244,6 +257,65 @@ class DeveloperOptionsController extends GetxController { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> sendTestHrvLocalNotification() async {
|
|
|
|
try {
|
|
|
|
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
|
|
final notifications = HealthRawLocalNotificationBuilder(l10n).build(
|
|
|
|
result: HealthRawStressCalculationResult(
|
|
|
|
userId: _userPreferencesStorage.preferences.value.meUserInfo?.id ?? 0,
|
|
|
|
hrvStressPoints: [
|
|
|
|
HealthRawHrvStressPoint(
|
|
|
|
userId:
|
|
|
|
_userPreferencesStorage.preferences.value.meUserInfo?.id ?? 0,
|
|
|
|
rawEndTime: now,
|
|
|
|
rawHrv: 35,
|
|
|
|
result: 32,
|
|
|
|
sourceStartTime: now,
|
|
|
|
sourceEndTime: now,
|
|
|
|
state: HealthRawStressState.excellent,
|
|
|
|
baselineHrv: 30,
|
|
|
|
baselineAwakeHrv: 30,
|
|
|
|
baselineSleepHrv: null,
|
|
|
|
baselineRestingHr: 60,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
realtimeStressPoints: const [],
|
|
|
|
dailyStressPoints: const [],
|
|
|
|
sleepResults: const [],
|
|
|
|
),
|
|
|
|
hasExistingHrv: true,
|
|
|
|
hasExistingSleep: false,
|
|
|
|
realtimeWindow: const [],
|
|
|
|
record: const HealthRawLocalNotificationRecord(),
|
|
|
|
);
|
|
|
|
final notification = notifications.firstWhereOrNull(
|
|
|
|
(item) => item.recordType == HealthRawLocalNotificationRecordType.hrv,
|
|
|
|
);
|
|
|
|
if (notification == null) {
|
|
|
|
Get.snackbar('Send failed', 'No HRV notification was built');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final userId =
|
|
|
|
_userPreferencesStorage.preferences.value.meUserInfo?.id ?? 0;
|
|
|
|
final sent = await HealthRawLocalNotificationDispatcher().sendOne(
|
|
|
|
userId: userId,
|
|
|
|
notification: notification,
|
|
|
|
);
|
|
|
|
Get.snackbar(
|
|
|
|
sent ? '已触发 HRV 本地推送' : 'HRV 本地推送发送失败',
|
|
|
|
'${notification.title}\n${notification.content}',
|
|
|
|
);
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
AppLogger.e(
|
|
|
|
'Send test HRV local notification failed',
|
|
|
|
error,
|
|
|
|
stackTrace,
|
|
|
|
);
|
|
|
|
Get.snackbar('Send failed', error.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> clearHealthRawDataDatabaseAndUploadLog() async {
|
|
|
|
try {
|
|
|
|
await _healthRawDataCoreService.clearLocalDatabaseAndUploadLog();
|
...
|
...
|
|