Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add app link handling #55

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with https://YOUR_HOST -->
<data
android:scheme="https"
android:host="spotvideo.app" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
Binary file modified assets/images/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
22230FEC84FAAF7E8AA781A7 /* Pods-Runner.release-development.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release-development.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release-development.xcconfig"; sourceTree = "<group>"; };
230C707E8D6A9E6A1DC18028 /* Pods-Runner.release-staging.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release-staging.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release-staging.xcconfig"; sourceTree = "<group>"; };
2D785F1A266C2C4E00E43AE3 /* config */ = {isa = PBXFileReference; lastKnownFileType = folder; path = config; sourceTree = "<group>"; };
2DBBAF542734E8E30043162B /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4019077285505CC6EADC6A13 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
451976F66DC4F31C5F96421B /* Pods-Runner.profile-development.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile-development.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile-development.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -103,6 +104,7 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
2DBBAF542734E8E30043162B /* Runner.entitlements */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
97C146FD1CF9000F007C117D /* Assets.xcassets */,
97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -408,6 +410,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -545,6 +548,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -574,6 +578,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -658,6 +663,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -740,6 +746,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -819,6 +826,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -903,6 +911,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -985,6 +994,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down Expand Up @@ -1064,6 +1074,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
Expand Down
10 changes: 10 additions & 0 deletions ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:spotvideo.app</string>
</array>
</dict>
</plist>
4 changes: 2 additions & 2 deletions ios/fastlane/metadata/en-US/release_notes.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Nearby videos will be clustered together
- Sharing videos will now share spot web page
- Fixed a bug where clicking on shared video link does not open the video page within the app
- Updated the defualt user icon
5 changes: 4 additions & 1 deletion lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:spot/cubits/notification/notification_cubit.dart';
import 'package:spot/data_profiders/app_link_provider.dart';
import 'package:spot/data_profiders/location_provider.dart';
import 'package:spot/pages/tab_page.dart';
import 'package:spot/repositories/repository.dart';
Expand Down Expand Up @@ -86,7 +87,9 @@ class App extends StatelessWidget {
navigatorObservers: [
FirebaseAnalyticsObserver(analytics: _analytics),
],
home: TabPage(),
home: TabPage(
appLinkProvider: AppLinkProvider(),
),
),
),
);
Expand Down
32 changes: 32 additions & 0 deletions lib/data_profiders/app_link_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:spot/pages/view_video_page.dart';
import 'package:spot/utils/constants.dart';
import 'package:uni_links/uni_links.dart';

/// Takes care of app links
class AppLinkProvider {
/// Sets up the receiver of app links
Future<void> setupAppLinks(BuildContext context) async {
/// Quick and dirty way of
/// waiting until TabPage gets added to the widget tree.
await Future.delayed(const Duration(milliseconds: 300));

try {
final initialUri = await getInitialUri();
_handleAppLink(uri: initialUri, context: context);
uriLinkStream.listen((uri) => _handleAppLink(uri: uri, context: context));
} catch (_) {
context.showErrorSnackbar('Error opening the video.');
}
}

void _handleAppLink({required Uri? uri, required BuildContext context}) {
if (uri != null) {
final path = uri.path;
if (path.split('/').first == 'post') {
final videoId = path.split('/').last;
Navigator.of(context).push(ViewVideoPage.route(videoId: videoId));
}
}
}
}
17 changes: 8 additions & 9 deletions lib/pages/tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:spot/components/gradient_border.dart';
import 'package:spot/components/gradient_button.dart';
import 'package:spot/components/notification_dot.dart';
import 'package:spot/cubits/notification/notification_cubit.dart';
import 'package:spot/data_profiders/app_link_provider.dart';
import 'package:spot/pages/record_page.dart';
import 'package:spot/pages/tabs/map_tab.dart';
import 'package:spot/pages/tabs/notifications_tab.dart';
Expand All @@ -22,16 +23,13 @@ import 'record_page.dart';
/// Page that holds tab navigation at the bottom.
/// This is the first page presented to the user.
class TabPage extends StatefulWidget {
/// Name of this page within `RouteSettinngs`
static const name = 'TabPage';
/// Page that holds tab navigation at the bottom.
/// This is the first page presented to the user.
const TabPage({Key? key, required AppLinkProvider appLinkProvider})
: _appLinkProvider = appLinkProvider,
super(key: key);

/// Method ot create this page with necessary `BlocProvider`
static Route<void> route() {
return MaterialPageRoute(
settings: const RouteSettings(name: name),
builder: (_) => TabPage(),
);
}
final AppLinkProvider _appLinkProvider;

@override
TabPageState createState() => TabPageState();
Expand Down Expand Up @@ -196,6 +194,7 @@ class TabPageState extends State<TabPage> {
@override
void initState() {
super.initState();
widget._appLinkProvider.setupAppLinks(context);
WidgetsBinding.instance
?.addObserver(LifecycleEventHandler(resumeCallBack: onResumed));
}
Expand Down
11 changes: 4 additions & 7 deletions lib/pages/view_video_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import 'package:spot/utils/functions.dart';
import 'package:video_player/video_player.dart';

import '../utils/constants.dart';
import 'tab_page.dart';

@visibleForTesting

Expand Down Expand Up @@ -412,9 +411,8 @@ class __DeletingDialogContentState extends State<_DeletingDialogContent> {
_loading = true;
});
await widget._videoCubit.delete();
Navigator.of(context).popUntil(
(route) => route.settings.name == TabPage.name,
);
Navigator.of(context)
.popUntil((route) => route.isFirst);
} catch (err) {
setState(() {
_loading = false;
Expand Down Expand Up @@ -482,9 +480,8 @@ class __BlockingDialogContentState extends State<_BlockingDialogContent> {
_loading = true;
});
await widget._videoCubit.block(widget._blockedUserId);
Navigator.of(context).popUntil(
(route) => route.settings.name == TabPage.name,
);
Navigator.of(context)
.popUntil((route) => route.isFirst);
} catch (err) {
setState(() {
_loading = false;
Expand Down
21 changes: 21 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
uni_links:
dependency: "direct main"
description:
name: uni_links
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.1"
uni_links_platform_interface:
dependency: transitive
description:
name: uni_links_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
uni_links_web:
dependency: transitive
description:
name: uni_links_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
universal_io:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: spot
description: Find local video posts
version: 1.4.2+64
version: 1.4.3+65
publish_to: none

environment:
Expand Down Expand Up @@ -32,6 +32,7 @@ dependencies:
flutter_video_info: ^1.2.0
shared_preferences: ^2.0.6
google_maps_cluster_manager: ^3.0.0+1
uni_links: ^0.5.1

dev_dependencies:
flutter_test:
Expand Down
Loading