Skip to content

Commit 97b6f59

Browse files
authored
Check whether historical health functionality is available (#148)
# 🚀 Pull Request ## Brief Description This pull request hide the corresponding PermissionCard in case of Health Connect historical health functionality is not available. Apart from that it also localizes missing read permission. ## Linked Issues <!-- Link related issues with the format: Fixes #123, Resolves #456, Closes #1337 --> - Partly solves #139 ## GitHub Copilot Text This pull request introduces support for checking the availability of historical health data permissions, refactors error messages to use localized strings, and updates the UI logic to conditionally display historical health data options based on availability. Below are the key changes grouped by theme: ### Localization Updates: * Added a new localized string `permission_health_read_missing` to both `lib/l10n/app_de.arb` and `lib/l10n/app_en.arb` for displaying a message when health data read permissions are missing. [[1]](diffhunk://#diff-36252c65ab82cbff4774b4983cb9027a2bef4cb738d5ea656c0b903939b3871aR341) [[2]](diffhunk://#diff-9796fde3771f42a3a759ccc941731d83f96037a661e47dde27ce81d3447a69c2R360) ### Permissions State Enhancements: * Introduced a new property `isHealthHistoricalAvailable` in the `PermissionsState` class to track the availability of historical health data functionality. Updated the constructor, `copyWith` method, and `PermissionsNotifier` logic to handle this property. [[1]](diffhunk://#diff-8a4214800464620d2099bc7cfa9c805f54af891b727a07e2d6b5ff7f71f66bacR22-R27) [[2]](diffhunk://#diff-8a4214800464620d2099bc7cfa9c805f54af891b727a07e2d6b5ff7f71f66bacR37) [[3]](diffhunk://#diff-8a4214800464620d2099bc7cfa9c805f54af891b727a07e2d6b5ff7f71f66bacR47) [[4]](diffhunk://#diff-8a4214800464620d2099bc7cfa9c805f54af891b727a07e2d6b5ff7f71f66bacR62-R63) [[5]](diffhunk://#diff-8a4214800464620d2099bc7cfa9c805f54af891b727a07e2d6b5ff7f71f66bacL287-R310) ### UI Logic Adjustments: * Updated the `PermissionsPage` and `PermissionsSettingsScreen` widgets to use the new `isHealthHistoricalAvailable` property instead of relying solely on the platform check. This ensures the historical health data option is displayed only when available. [[1]](diffhunk://#diff-ed114b585bef8ee4333df6f2e72f1c9dfa98c882124fb226aad2ea091e172338L203-R203) [[2]](diffhunk://#diff-ed114b585bef8ee4333df6f2e72f1c9dfa98c882124fb226aad2ea091e172338L219-R218) [[3]](diffhunk://#diff-90b689fa9760b9b500d20dba87b979e37ee2b6d7f8034db402842ca07274eeffL196-R196) [[4]](diffhunk://#diff-90b689fa9760b9b500d20dba87b979e37ee2b6d7f8034db402842ca07274eeffL210-R209) ### Error Message Refactoring: * Replaced hardcoded error messages for missing health data read permissions with the localized `permission_health_read_missing` string across multiple widgets for consistency. [[1]](diffhunk://#diff-ed114b585bef8ee4333df6f2e72f1c9dfa98c882124fb226aad2ea091e172338L147-R147) [[2]](diffhunk://#diff-ed114b585bef8ee4333df6f2e72f1c9dfa98c882124fb226aad2ea091e172338L219-R218) [[3]](diffhunk://#diff-90b689fa9760b9b500d20dba87b979e37ee2b6d7f8034db402842ca07274eeffL139-R139) [[4]](diffhunk://#diff-90b689fa9760b9b500d20dba87b979e37ee2b6d7f8034db402842ca07274eeffL210-R209)
2 parents 070313c + 7f0d217 commit 97b6f59

5 files changed

Lines changed: 34 additions & 13 deletions

File tree

lib/l10n/app_de.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
"permission_health_read_description": "Zum Lesen deiner Aktivitäten und Fitness-Daten",
339339
"permission_health_write_title": "Gesundheitsdaten Schreiben",
340340
"permission_health_write_description": "Zum Speichern deiner Aktivitäten in der Health-Datenbank",
341+
"permission_health_read_missing": "Bitte erteile zuerst die Leseberechtigung für Gesundheitsdaten",
341342
"permission_health_historical_title": "Historische Gesundheitsdaten",
342343
"permission_health_historical_description": "Für den Zugriff auf Gesundheitsdaten, die älter als 30 Tage sind, für Langzeitanalysen",
343344
"permission_allow": "Erlauben",

lib/l10n/app_en.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@
357357
"permission_health_read_description": "To read your activities and fitness data",
358358
"permission_health_write_title": "Health Data Write",
359359
"permission_health_write_description": "To save your activities to the health database",
360+
"permission_health_read_missing": "Please first allow access to read your health data",
360361
"permission_health_historical_title": "Historical Health Data",
361362
"permission_health_historical_description": "To access your health data older than 30 days for long-term analysis",
362363
"permission_allow": "Allow",

lib/presentation/onboarding/providers/permissions_provider.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class PermissionsState {
1919
final bool healthWritePermissionStatus;
2020
final bool healthHistoricalPermissionStatus;
2121

22+
/*
23+
* Determine if historical health functionality is available
24+
* Only relevant for Android, on iOS this is always false
25+
* */
26+
final bool isHealthHistoricalAvailable;
27+
2228
bool get hasRequiredPermissions => healthPermissionStatus;
2329

2430
PermissionsState({
@@ -28,6 +34,7 @@ class PermissionsState {
2834
this.healthPermissionStatus = false,
2935
this.healthWritePermissionStatus = false,
3036
this.healthHistoricalPermissionStatus = false,
37+
this.isHealthHistoricalAvailable = false,
3138
});
3239

3340
PermissionsState copyWith({
@@ -37,6 +44,7 @@ class PermissionsState {
3744
bool? healthPermissionStatus,
3845
bool? healthWritePermissionStatus,
3946
bool? healthHistoricalPermissionStatus,
47+
bool? isHealthHistoricalAvailable,
4048
}) {
4149
return PermissionsState(
4250
locationPermissionStatus:
@@ -51,6 +59,8 @@ class PermissionsState {
5159
healthWritePermissionStatus ?? this.healthWritePermissionStatus,
5260
healthHistoricalPermissionStatus: healthHistoricalPermissionStatus ??
5361
this.healthHistoricalPermissionStatus,
62+
isHealthHistoricalAvailable:
63+
isHealthHistoricalAvailable ?? this.isHealthHistoricalAvailable,
5464
);
5565
}
5666

@@ -284,7 +294,20 @@ class PermissionsNotifier extends StateNotifier<PermissionsState> {
284294
}
285295

286296
try {
287-
// Verwende die direkte API-Methode, um zu prüfen, ob historische Berechtigungen gewährt wurden
297+
// Check the availability of historical permissions
298+
// This is only relevant for Android, on iOS this is not available
299+
300+
bool isHistoricalAvailable =
301+
await _health.isHealthDataHistoryAvailable();
302+
state =
303+
state.copyWith(isHealthHistoricalAvailable: isHistoricalAvailable);
304+
if (!isHistoricalAvailable) {
305+
log.warning("Historical Health feature is not available");
306+
return;
307+
}
308+
309+
// Verwende die direkte API-Methode, um zu prüfen, ob historische Berechtigungen gewährt wurde
310+
288311
bool hasHistoricalPermissions =
289312
await _health.isHealthDataHistoryAuthorized();
290313

lib/presentation/onboarding/widgets/permissions_page.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ class PermissionsPage extends ConsumerWidget {
144144
if (!permissionsState.healthPermissionStatus) {
145145
ScaffoldMessenger.of(context).showSnackBar(
146146
SnackBar(
147-
content: Text(
148-
'Bitte erteile zuerst die Leseberechtigung für Gesundheitsdaten'),
147+
content: Text(l10n.permission_health_read_missing),
149148
backgroundColor: theme.colorScheme.error,
150149
duration: const Duration(seconds: 2),
151150
),
@@ -200,8 +199,8 @@ class PermissionsPage extends ConsumerWidget {
200199

201200
const SizedBox(height: 16),
202201

203-
// Historical Health Data permission - only for Android
204-
if (Theme.of(context).platform == TargetPlatform.android)
202+
// Historical Health Data permission - only if available
203+
if (permissionsState.isHealthHistoricalAvailable)
205204
Column(
206205
children: [
207206
PermissionCard(
@@ -216,8 +215,7 @@ class PermissionsPage extends ConsumerWidget {
216215
if (!permissionsState.healthPermissionStatus) {
217216
ScaffoldMessenger.of(context).showSnackBar(
218217
SnackBar(
219-
content: const Text(
220-
'Bitte erteile zuerst die Leseberechtigung für Gesundheitsdaten'),
218+
content: Text(l10n.permission_health_read_missing),
221219
backgroundColor: theme.colorScheme.error,
222220
duration: const Duration(seconds: 2),
223221
),

lib/presentation/profile/screen/permissions_settings_screen.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ class PermissionsSettingsScreen extends HookConsumerWidget {
136136
if (!permissionsState.healthPermissionStatus) {
137137
ScaffoldMessenger.of(context).showSnackBar(
138138
SnackBar(
139-
content: Text(
140-
'Bitte erteile zuerst die Leseberechtigung für Gesundheitsdaten'),
139+
content: Text(l10n.permission_health_read_missing),
141140
backgroundColor: theme.colorScheme.error,
142141
duration: const Duration(seconds: 2),
143142
),
@@ -193,8 +192,8 @@ class PermissionsSettingsScreen extends HookConsumerWidget {
193192

194193
const SizedBox(height: 16),
195194

196-
// Historical Health Data permission - only for Android
197-
if (Theme.of(context).platform == TargetPlatform.android)
195+
// Historical Health Data permission - only if available
196+
if (permissionsState.isHealthHistoricalAvailable)
198197
PermissionCard(
199198
icon: Icons.history,
200199
title: l10n.permission_health_historical_title,
@@ -207,8 +206,7 @@ class PermissionsSettingsScreen extends HookConsumerWidget {
207206
if (!permissionsState.healthPermissionStatus) {
208207
ScaffoldMessenger.of(context).showSnackBar(
209208
SnackBar(
210-
content: Text(
211-
'Bitte erteile zuerst die Leseberechtigung für Gesundheitsdaten'),
209+
content: Text(l10n.permission_health_read_missing),
212210
backgroundColor: theme.colorScheme.error,
213211
duration: const Duration(seconds: 2),
214212
),

0 commit comments

Comments
 (0)