Skip to content

Commit

Permalink
feat(#661): get deep link (not handled correctly yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Nov 14, 2024
1 parent 67e9164 commit f2fcff6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
12 changes: 12 additions & 0 deletions app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- BEGIN receive deep links config -->
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Agreed to use app ID but must not contain underscores -->
<data android:scheme="pharme" />
<!-- Host we agreed upon -->
<data android:host="open_file" />
</intent-filter>
<!-- END receive deep links config -->
</activity>
<!-- Used for Sign-In Flow -->
<activity
Expand Down
19 changes: 17 additions & 2 deletions app/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,23 @@ class PharMeApp extends StatelessWidget {
appRouter: _appRouter,
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(deepLinkBuilder: getInitialRoute),
routerConfig: _appRouter.config(
deepLinkBuilder: (deepLink) async {
final queryParameters = deepLink.uri.queryParameters;
final isDeepLinkShareRequest = deepLink.path == '' &&
queryParameters.containsKey('provider_url');
if (isDeepLinkShareRequest) {
MetaData.instance.deepLinkSharePublishUrl =
queryParameters['provider_url'];
await MetaData.save();
if (_appRouter.currentPath != '/') {
return DeepLink.path(_appRouter.currentPath);
}
}
// default route
return getInitialRoute();
},
),
theme: PharMeTheme.light,
localizationsDelegates: [
AppLocalizations.delegate,
Expand Down
3 changes: 3 additions & 0 deletions app/lib/common/models/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class MetaData {

@HiveField(5)
bool? tutorialDone;

@HiveField(6)
String? deepLinkSharePublishUrl;
}

/// Initializes the user's metadata by registering all necessary adapters and
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/utilities/routing_utils.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '../../secure/module.dart';
import '../module.dart';

DeepLink getInitialRoute(_) {
DeepLink getInitialRoute() {
final isLoggedIn = MetaData.instance.isLoggedIn ?? false;
final onboardingDone = MetaData.instance.onboardingDone ?? false;
final initialDrugSelectionDone =
Expand Down
19 changes: 13 additions & 6 deletions app/lib/login/models/deep_link_share_flow_lab.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/foundation.dart';

import '../../common/module.dart';
import 'lab.dart';

Expand All @@ -19,19 +21,24 @@ class DeepLinkShareFlowLab extends Lab {
String? authLoadingMessage() =>
'Please open the $shareAppName and share your data with PharMe';

Future<void> _waitForDeepLinkSharePublishUrl() async {
var waitingForDeepLinkSharePublishUrl = true;
while (waitingForDeepLinkSharePublishUrl) {
waitingForDeepLinkSharePublishUrl =
MetaData.instance.deepLinkSharePublishUrl == null;
await Future.delayed(Duration(seconds: 1));
}
}

@override
Future<void> authenticate() async {
// THIS IS FOR TESTING, SHOULD WAIT UNTIL A DEEP LINK IS RECEIVED
// (if possible like this but could set metadata field when deep link
// caught and wait here until it was set)
await Future.delayed(Duration(seconds: 7));
await _waitForDeepLinkSharePublishUrl();
}

@override
Future<(List<LabResult>, List<String>)> loadData() async {
// THIS IS FOR TESTING, SHOULD GET FROM DWA
publishUrl = Uri.parse(
'https://hpi-datastore.duckdns.org/userdata?id=1e006a69-b693-43d2-a318-22904e305b5c',
MetaData.instance.deepLinkSharePublishUrl!,
);
publishHeaders = null;
return fetchData(
Expand Down
1 change: 1 addition & 0 deletions pharme.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"drugclass",
"drugid",
"drugrecommendation",
"drugselection",
"duckdns",
"duloxetine",
"endoxifen",
Expand Down

0 comments on commit f2fcff6

Please sign in to comment.