Skip to content

Commit

Permalink
Adding health connect warning message. (#320)
Browse files Browse the repository at this point in the history
* Merging recent changes (#319)

* Creates a release on tag creation (#312)

Github workflow to create a release and include an apk.

* On login page init, check if user is authenticated and redirect to Invitations or Home page (#311)

* Update permissions on Android, fix exception while uploading informed consent (#308)

* fix of #301

* Update carp_backend.dart

* Fix of #306

* update to pubspec to use CAMS ^1.8.0

* Update pubspec.lock

* Update pubspec.lock

---------

Co-authored-by: Aamir Farooq <[email protected]>

* Fixed warning about deprecated use of gradle (#310)

* initial commit

* removed warnings about deprecated use of gradle

---------

Co-authored-by: Aamir Farooq <[email protected]>

* Fix an error caused by changes in latest version of CAMS (#315)

* Migration needed for new version of CAMS

* Fix test

* Trigger TestFlight build.

* bumping versions

* bumping versions and updating depricated @UIApplicationMain on AppDelegate.swift to @main.

---------

Co-authored-by: Jakob E. Bardram <[email protected]>
Co-authored-by: Aamir Farooq <[email protected]>

* temporarily removing ACTIVITY_RECOGNITION permission.

* bumping version code to 31

* Reintroducing ACTIVITY_RECOGNITION permission

* bumping version code to 32

* Checking if health connect exists and redirect user to google play store on Health Connect page.

* bumping version to 2.2.1

* removing duplicates from pubspec.lock

* conditional check only for android

* update to EN and DA text

* Update pubspec.lock

* language improvements

---------

Co-authored-by: Jakob E. Bardram <[email protected]>
Co-authored-by: Aamir Farooq <[email protected]>
  • Loading branch information
3 people committed Aug 30, 2024
1 parent aa16144 commit dc2dcc7
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 194 deletions.
3 changes: 3 additions & 0 deletions assets/lang/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@
"expired": "udløbet",
"completed": "færdig",
"cancel": "Anuller",
"install": "Installér",
"pages.about.message.read_more": "Tryk for at læse mere",
"pages.about.study.website": "Hjemmeside",
"pages.about.study.privacy": "Fortrolighedspolitik",
"pages.about.install_health_connect.title": "Health Connect påkrævet",
"pages.about.install_health_connect.description": "Denne app kræver, at Google Connect er installeret. Vil du installere det?",
"dialog.location.permission": "Lokaliseringstjeneste",
"dialog.location.allow": "Tillad",
"pages.ic.need_accept": "Du skal acceptere denne informerede samtykke for at kunne deltage i dette studie.",
Expand Down
3 changes: 3 additions & 0 deletions assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@
"expired": "expired",
"completed": "completed",
"cancel": "Cancel",
"install": "Install",
"pages.about.message.read_more": "Tap to read more",
"pages.about.study.website": "Website",
"pages.about.study.privacy": "Privacy policy",
"pages.about.install_health_connect.title": "Health Connect Required",
"pages.about.install_health_connect.description": "This app requires Google Health Connect to be installed. Would you like to install it?",
"dialog.location.permission": "Permission Required",
"dialog.location.allow": "Allow",
"pages.ic.need_accept": "You need to accept the informed consent to participate in this study.",
Expand Down
20 changes: 20 additions & 0 deletions lib/blocs/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class StudyAppBLoC extends ChangeNotifier {
List<Message> _messages = [];
final StreamController<int> _messageStreamController =
StreamController.broadcast();
final String _healthConnectPackageName = 'com.google.android.apps.healthdata';

/// The state of this BloC.
StudyAppState get state => _state;
Expand Down Expand Up @@ -84,6 +85,8 @@ class StudyAppBLoC extends ChangeNotifier {
GlobalKey<ScaffoldMessengerState> get scaffoldKey => _scaffoldKey;
State? get scaffoldMessengerState => scaffoldKey.currentState;

String get healthConnectPackageName => _healthConnectPackageName;

/// Create the BLoC for the app.
StudyAppBLoC() : super() {
const dep =
Expand Down Expand Up @@ -151,6 +154,10 @@ class StudyAppBLoC extends ChangeNotifier {
/// The overall data model for this app
CarpStudyAppViewModel get appViewModel => _appViewModel;

final appCheck = AppCheck();

List<AppInfo>? installedApps;

/// Initialize this BLOC. Called before being used for anything.
Future<void> initialize() async {
if (isInitialized) return;
Expand Down Expand Up @@ -178,6 +185,19 @@ class StudyAppBLoC extends ChangeNotifier {
element == ConnectivityResult.wifi);
}

Future<bool> _isHealthConnectInstalled() async {
try {
final apps = await appCheck.getInstalledApps();
if (apps != null) {
return apps.any((app) => app.packageName == _healthConnectPackageName);
}
} catch (e) {
debug("Error checking Health Connect installation: $e");
return false;
}
return false;
}

/// Set the active study in the app based on an [invitation].
///
/// If a [context] is provided, the translation for this study is re-loaded
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:open_settings_plus/open_settings_plus.dart';
import 'package:open_settings_plus/core/open_settings_plus.dart';
import 'package:appcheck/appcheck.dart';

// the CARP packages
import 'package:carp_serializable/carp_serializable.dart';
Expand Down Expand Up @@ -77,6 +78,7 @@ part 'view_models/user_tasks.dart';
part 'carp_study_app.dart';
part 'ui/pages/informed_consent_page.dart';
part 'ui/pages/home_page.dart';
part 'ui/pages/home_page.install_health_connect_dialog.dart';
part 'ui/carp_study_style.dart';
part 'ui/colors.dart';
part 'ui/pages/data_visualization_page.dart';
Expand Down
10 changes: 5 additions & 5 deletions lib/main.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lib/ui/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ class HomePageState extends State<HomePage> {
// - starting sensing
askForLocationPermissions(context)
.then((_) => bloc.configureStudy().then((_) => bloc.start()));

if (Platform.isAndroid) {
// Check if HealthConnect is installed
_checkHealthConnectInstallation();
}
}

Future<void> _checkHealthConnectInstallation() async {
bool isInstalled = await bloc._isHealthConnectInstalled();
if (!isInstalled) {
showDialog<void>(
context: context,
barrierDismissible: true,
builder: (context) => InstallHealthConnectDialog(context),
);
}
}

@override
Expand Down
46 changes: 46 additions & 0 deletions lib/ui/pages/home_page.install_health_connect_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
part of carp_study_app;

class InstallHealthConnectDialog extends StatelessWidget {
const InstallHealthConnectDialog(BuildContext context, {super.key});

@override
Widget build(BuildContext context) {
RPLocalizations locale = RPLocalizations.of(context)!;
return AlertDialog(
titlePadding: const EdgeInsets.symmetric(vertical: 4),
insetPadding: const EdgeInsets.symmetric(vertical: 24, horizontal: 40),
title: const DialogTitle(
title: "pages.about.install_health_connect.title",
),
content: Text(
locale.translate('pages.about.install_health_connect.description'),
style: aboutCardContentStyle,
textAlign: TextAlign.justify,
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(locale.translate('cancel')),
),
TextButton(
child: Text(locale.translate('install')),
onPressed: () async {
_redirectToHealthConnectPlayStore();
Navigator.of(context).pop();
},
),
],
);
}

void _redirectToHealthConnectPlayStore() async {
final Uri url = Uri.parse(
'https://play.google.com/store/apps/details?id=${bloc.healthConnectPackageName}');
var canLaunch = await canLaunchUrl(url);
if (canLaunch) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
}
}
}
Loading

0 comments on commit dc2dcc7

Please sign in to comment.