|
...
|
...
|
@@ -305,26 +305,26 @@ class TodayController extends GetxController with WidgetsBindingObserver { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _checkHealthAuthStatus(
|
|
|
|
Future<bool> _checkHealthAuthStatus(
|
|
|
|
{bool isPullToRefresh = false,
|
|
|
|
bool shouldCaculateAndUpload = false}) async {
|
|
|
|
final result = await _hostApi.checkHealthAppAuthorization();
|
|
|
|
_currentStatus = result.status;
|
|
|
|
_refreshHealthDataAuthCardStatus(status: _currentStatus);
|
|
|
|
if (_currentStatus != 1) {
|
|
|
|
return;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!shouldCaculateAndUpload) {
|
|
|
|
return;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_performCaculateAndUpload(isPullToRefresh: isPullToRefresh);
|
|
|
|
return _performCaculateAndUpload(isPullToRefresh: isPullToRefresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
_performCaculateAndUpload({
|
|
|
|
Future<bool> _performCaculateAndUpload({
|
|
|
|
bool isPullToRefresh = false,
|
|
|
|
}) {
|
|
|
|
_performHealthDataUpload();
|
|
|
|
_calculateHealthDataWithoutLoading(
|
|
|
|
return _calculateHealthDataWithoutLoading(
|
|
|
|
uploaded: () async {
|
|
|
|
_refreshHealthDataAuthCardStatus(status: 1);
|
|
|
|
},
|
|
...
|
...
|
@@ -520,13 +520,21 @@ class TodayController extends GetxController with WidgetsBindingObserver { |
|
|
|
firstSelectableDay.value = firstTime;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
await _checkHealthAuthStatus(
|
|
|
|
final didCalculateAndReload = await _checkHealthAuthStatus(
|
|
|
|
isPullToRefresh: isPullToRefresh,
|
|
|
|
shouldCaculateAndUpload: shouldCaculateAndUpload);
|
|
|
|
ta.setSuperProperties(
|
|
|
|
{'health_data_permission': _currentStatus.clamp(0, 1)});
|
|
|
|
unawaited(loadDataForDate(selectedDate.value,
|
|
|
|
isPullToRefresh: isPullToRefresh));
|
|
|
|
// When a pull-to-refresh asks OHOS to recalculate health data,
|
|
|
|
// _calculateHealthDataWithoutLoading already reloads the page after
|
|
|
|
// the calculation. Starting another load here caused a second visible
|
|
|
|
// refresh shortly after the first one completed.
|
|
|
|
if (!didCalculateAndReload) {
|
|
|
|
await loadDataForDate(
|
|
|
|
selectedDate.value,
|
|
|
|
isPullToRefresh: isPullToRefresh,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
AppLogger.e(
|
|
|
|
'TodayController.checkHealthDataAuthCardVisible failed',
|
|
...
|
...
|
@@ -556,25 +564,25 @@ class TodayController extends GetxController with WidgetsBindingObserver { |
|
|
|
_refreshHealthDataAuthCardStatus(status: result.status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _calculateHealthDataWithoutLoading(
|
|
|
|
Future<bool> _calculateHealthDataWithoutLoading(
|
|
|
|
{Future<void> Function()? uploaded,
|
|
|
|
bool isPullToRefresh = false,
|
|
|
|
bool refreshAfterComplete = false}) {
|
|
|
|
unawaited(
|
|
|
|
(() async {
|
|
|
|
try {
|
|
|
|
await _healthRawDataCoreService.startCoreCaculate();
|
|
|
|
await loadDataForDate(selectedDate.value,
|
|
|
|
isPullToRefresh: isPullToRefresh);
|
|
|
|
await uploaded?.call();
|
|
|
|
if (refreshAfterComplete) {
|
|
|
|
await loadDataForDate(selectedDate.value);
|
|
|
|
}
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
AppLogger.e('Apple Health calculate failed', error, stackTrace);
|
|
|
|
}
|
|
|
|
})(),
|
|
|
|
);
|
|
|
|
bool refreshAfterComplete = false}) async {
|
|
|
|
try {
|
|
|
|
await _healthRawDataCoreService.startCoreCaculate();
|
|
|
|
await loadDataForDate(
|
|
|
|
selectedDate.value,
|
|
|
|
isPullToRefresh: isPullToRefresh,
|
|
|
|
);
|
|
|
|
await uploaded?.call();
|
|
|
|
if (refreshAfterComplete) {
|
|
|
|
await loadDataForDate(selectedDate.value);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} catch (error, stackTrace) {
|
|
|
|
AppLogger.e('Apple Health calculate failed', error, stackTrace);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _performHealthDataUpload() {
|
|
...
|
...
|
@@ -925,7 +933,7 @@ class TodayController extends GetxController with WidgetsBindingObserver { |
|
|
|
DateUtils.dateOnly(selectedDate.value),
|
|
|
|
DateUtils.dateOnly(DateTime.now()),
|
|
|
|
);
|
|
|
|
checkHealthDataAuthCardVisible(
|
|
|
|
await checkHealthDataAuthCardVisible(
|
|
|
|
isPullToRefresh: isPullToRefresh,
|
|
|
|
shouldCaculateAndUpload: isOhos() && isSelectedToday,
|
|
|
|
);
|
...
|
...
|
|