|
1
|
import 'dart:async';
|
1
|
import 'dart:async';
|
|
|
|
2
|
+import 'dart:nativewrappers/_internal/vm/lib/ffi_allocation_patch.dart';
|
|
2
|
import 'dart:ui';
|
3
|
import 'dart:ui';
|
|
3
|
|
4
|
|
|
4
|
import 'package:doublefeel_flutter/app/modules/friends/controllers/friend_trend_controller.dart';
|
5
|
import 'package:doublefeel_flutter/app/modules/friends/controllers/friend_trend_controller.dart';
|
|
@@ -265,7 +266,6 @@ class TodayController extends GetMaterialController { |
|
@@ -265,7 +266,6 @@ class TodayController extends GetMaterialController { |
|
265
|
}
|
266
|
}
|
|
266
|
});
|
267
|
});
|
|
267
|
result.status = 1;
|
268
|
result.status = 1;
|
|
268
|
- checkHealthDataAuthCardVisible();
|
|
|
|
269
|
// AppToast.show('刷新完成');
|
269
|
// AppToast.show('刷新完成');
|
|
270
|
if (isFromNoPermissionPage) {
|
270
|
if (isFromNoPermissionPage) {
|
|
271
|
Get.back();
|
271
|
Get.back();
|
|
@@ -284,7 +284,6 @@ class TodayController extends GetMaterialController { |
|
@@ -284,7 +284,6 @@ class TodayController extends GetMaterialController { |
|
284
|
AppLogger.e('Apple Health upload failed', error, stackTrace);
|
284
|
AppLogger.e('Apple Health upload failed', error, stackTrace);
|
|
285
|
}
|
285
|
}
|
|
286
|
});
|
286
|
});
|
|
287
|
- checkHealthDataAuthCardVisible(result);
|
|
|
|
288
|
if (isFromNoPermissionPage) {
|
287
|
if (isFromNoPermissionPage) {
|
|
289
|
Get.back();
|
288
|
Get.back();
|
|
290
|
}
|
289
|
}
|
|
@@ -303,34 +302,19 @@ class TodayController extends GetMaterialController { |
|
@@ -303,34 +302,19 @@ class TodayController extends GetMaterialController { |
|
303
|
if (showHealthDataAuthCardStatus.value == 1) {
|
302
|
if (showHealthDataAuthCardStatus.value == 1) {
|
|
304
|
return;
|
303
|
return;
|
|
305
|
} else if (showHealthDataAuthCardStatus.value == 0) {
|
304
|
} else if (showHealthDataAuthCardStatus.value == 0) {
|
|
306
|
- Get.to(NoHealthDataNoPermissionPage(
|
305
|
+ await Get.to(NoHealthDataNoPermissionPage(
|
|
307
|
onRequest: () =>
|
306
|
onRequest: () =>
|
|
308
|
requestHealthAuthorization(isFromNoPermissionPage: true),
|
307
|
requestHealthAuthorization(isFromNoPermissionPage: true),
|
|
309
|
));
|
308
|
));
|
|
|
|
309
|
+ checkHealthDataAuthCardVisible();
|
|
310
|
} else {
|
310
|
} else {
|
|
311
|
- Get.to(NoHealthDataPage(
|
311
|
+ await Get.to(NoHealthDataPage(
|
|
312
|
onRefresh: requestHealthAuthorization,
|
312
|
onRefresh: requestHealthAuthorization,
|
|
313
|
onHelp: () {
|
313
|
onHelp: () {
|
|
314
|
Get.toNamed(Routes.HELP);
|
314
|
Get.toNamed(Routes.HELP);
|
|
315
|
},
|
315
|
},
|
|
316
|
));
|
316
|
));
|
|
317
|
- }
|
|
|
|
318
|
- }
|
|
|
|
319
|
-
|
|
|
|
320
|
- /// 上传 Apple Health 新数据。
|
|
|
|
321
|
- Future<void> _performDataUpload() async {
|
|
|
|
322
|
- try {
|
|
|
|
323
|
- final result = await _hostApi.performHealthUpload();
|
|
|
|
324
|
- // AppLogger.i(
|
|
|
|
325
|
- // 'Apple Health upload finished: '
|
|
|
|
326
|
- // 'common=${result.commonUploadSuccess}(${result.commonCount}), '
|
|
|
|
327
|
- // 'sleep=${result.sleepUploadSuccess}(${result.sleepCount}), '
|
|
|
|
328
|
- // 'activityTarget=${result.activityTargetUploadSuccess}'
|
|
|
|
329
|
- // '(${result.activityTargetCount}), '
|
|
|
|
330
|
- // 'success=${result.isSuccess}',
|
|
|
|
331
|
- // );
|
|
|
|
332
|
- } catch (error, stackTrace) {
|
|
|
|
333
|
- AppLogger.e('Apple Health upload failed', error, stackTrace);
|
317
|
+ checkHealthDataAuthCardVisible();
|
|
334
|
}
|
318
|
}
|
|
335
|
}
|
319
|
}
|
|
336
|
|
320
|
|
|
@@ -350,27 +334,48 @@ class TodayController extends GetMaterialController { |
|
@@ -350,27 +334,48 @@ class TodayController extends GetMaterialController { |
|
350
|
ta.setSuperProperties(
|
334
|
ta.setSuperProperties(
|
|
351
|
{'health_data_permission': result.status.clamp(0, 1)});
|
335
|
{'health_data_permission': result.status.clamp(0, 1)});
|
|
352
|
if (result.status == 1) {
|
336
|
if (result.status == 1) {
|
|
353
|
- await _performDataUpload();
|
337
|
+ _uploadHealthDataWithoutLoading(
|
|
|
|
338
|
+ uploaded: () async {
|
|
|
|
339
|
+ await checkUploadedStatus(firstTime, result);
|
|
|
|
340
|
+ },
|
|
|
|
341
|
+ );
|
|
|
|
342
|
+ } else {
|
|
|
|
343
|
+ await checkUploadedStatus(firstTime, result);
|
|
354
|
}
|
344
|
}
|
|
355
|
- bool hasUploaded = false;
|
|
|
|
356
|
- switch (await _healthApi.getHealthDataEverUploaded()) {
|
|
|
|
357
|
- case AppSuccess(:final data):
|
|
|
|
358
|
- hasUploaded = data.flag ?? false;
|
|
|
|
359
|
- if (hasUploaded && data.startTime != null && data.startTime! > 0) {
|
|
|
|
360
|
- final firstDayTime = DateUtils.dateOnly(
|
|
|
|
361
|
- DateTime.fromMillisecondsSinceEpoch(data.startTime! * 1000),
|
|
|
|
362
|
- );
|
|
|
|
363
|
- if (firstDayTime.isBefore(firstTime)) {
|
|
|
|
364
|
- firstSelectableDay.value = firstDayTime;
|
|
|
|
365
|
- }
|
|
|
|
366
|
- }
|
|
|
|
367
|
- case AppFailure():
|
|
|
|
368
|
- }
|
|
|
|
369
|
- showHealthDataAuthCardStatus.value = !hasUploaded ? -1 : result.status;
|
|
|
|
370
|
} catch (e) {}
|
345
|
} catch (e) {}
|
|
371
|
}
|
346
|
}
|
|
372
|
}
|
347
|
}
|
|
373
|
|
348
|
|
|
|
|
349
|
+ Future<void> checkUploadedStatus(
|
|
|
|
350
|
+ DateTime firstTime, HealthAuthorization result) async {
|
|
|
|
351
|
+ bool hasUploaded = false;
|
|
|
|
352
|
+ switch (await _healthApi.getHealthDataEverUploaded()) {
|
|
|
|
353
|
+ case AppSuccess(:final data):
|
|
|
|
354
|
+ hasUploaded = data.flag ?? false;
|
|
|
|
355
|
+ if (hasUploaded && data.startTime != null && data.startTime! > 0) {
|
|
|
|
356
|
+ final firstDayTime = DateUtils.dateOnly(
|
|
|
|
357
|
+ DateTime.fromMillisecondsSinceEpoch(data.startTime! * 1000),
|
|
|
|
358
|
+ );
|
|
|
|
359
|
+ if (firstDayTime.isBefore(firstTime)) {
|
|
|
|
360
|
+ firstSelectableDay.value = firstDayTime;
|
|
|
|
361
|
+ }
|
|
|
|
362
|
+ }
|
|
|
|
363
|
+ case AppFailure():
|
|
|
|
364
|
+ }
|
|
|
|
365
|
+ showHealthDataAuthCardStatus.value = !hasUploaded ? -1 : result.status;
|
|
|
|
366
|
+ }
|
|
|
|
367
|
+
|
|
|
|
368
|
+ _uploadHealthDataWithoutLoading({VoidCallback? uploaded}) {
|
|
|
|
369
|
+ try {
|
|
|
|
370
|
+ _hostApi.performHealthUpload().then((_) {
|
|
|
|
371
|
+ unawaited(loadDataForDate(selectedDate.value));
|
|
|
|
372
|
+ uploaded?.call();
|
|
|
|
373
|
+ });
|
|
|
|
374
|
+ } catch (error, stackTrace) {
|
|
|
|
375
|
+ AppLogger.e('Apple Health upload failed', error, stackTrace);
|
|
|
|
376
|
+ }
|
|
|
|
377
|
+ }
|
|
|
|
378
|
+
|
|
374
|
Future<void> checkNotificationCardVisible() async {
|
379
|
Future<void> checkNotificationCardVisible() async {
|
|
375
|
try {
|
380
|
try {
|
|
376
|
Permission.notification.status.then((status) {
|
381
|
Permission.notification.status.then((status) {
|