mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-11 17:37:31 +00:00
feat(android): add intent share support
This commit is contained in:
parent
7cad452d82
commit
f5917e5b65
@ -48,6 +48,22 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
<data
|
||||||
|
android:scheme="https"
|
||||||
|
android:host="open.spotify.com"
|
||||||
|
/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<data android:mimeType="text/*" />
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
import 'package:spotube/collections/routes.dart';
|
import 'package:spotube/collections/routes.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
import 'package:spotube/provider/spotify_provider.dart';
|
||||||
|
import 'package:flutter_sharing_intent/flutter_sharing_intent.dart';
|
||||||
|
import 'package:flutter_sharing_intent/model/sharing_file.dart';
|
||||||
|
|
||||||
void useDeepLinking(WidgetRef ref) {
|
void useDeepLinking(WidgetRef ref) {
|
||||||
// single instance no worries
|
// single instance no worries
|
||||||
@ -13,6 +15,45 @@ void useDeepLinking(WidgetRef ref) {
|
|||||||
final queryClient = useQueryClient();
|
final queryClient = useQueryClient();
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
|
void uriListener(List<SharedFile> files) async {
|
||||||
|
for (final file in files) {
|
||||||
|
if (file.type != SharedMediaType.URL) continue;
|
||||||
|
final url = Uri.parse(file.value!);
|
||||||
|
if (url.pathSegments.length != 2) continue;
|
||||||
|
|
||||||
|
switch (url.pathSegments.first) {
|
||||||
|
case "album":
|
||||||
|
router.push(
|
||||||
|
"/album/${url.pathSegments.last}",
|
||||||
|
extra: await queryClient.fetchQuery<Album, dynamic>(
|
||||||
|
"album/${url.pathSegments.last}",
|
||||||
|
() => spotify.albums.get(url.pathSegments.last),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "artist":
|
||||||
|
router.push("/artist/${url.pathSegments.last}");
|
||||||
|
break;
|
||||||
|
case "playlist":
|
||||||
|
router.push(
|
||||||
|
"/playlist/${url.pathSegments.last}",
|
||||||
|
extra: await queryClient.fetchQuery<Playlist, dynamic>(
|
||||||
|
"playlist/${url.pathSegments.last}",
|
||||||
|
() => spotify.playlists.get(url.pathSegments.last),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FlutterSharingIntent.instance.getInitialSharing().then(uriListener);
|
||||||
|
|
||||||
|
final mediaStream =
|
||||||
|
FlutterSharingIntent.instance.getMediaStream().listen(uriListener);
|
||||||
|
|
||||||
final subscription = appLinks.allStringLinkStream.listen((uri) async {
|
final subscription = appLinks.allStringLinkStream.listen((uri) async {
|
||||||
final startSegment = uri.split(":").take(2).join(":");
|
final startSegment = uri.split(":").take(2).join(":");
|
||||||
final endSegment = uri.split(":").last;
|
final endSegment = uri.split(":").last;
|
||||||
@ -44,6 +85,9 @@ void useDeepLinking(WidgetRef ref) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return subscription.cancel;
|
return () {
|
||||||
|
mediaStream.cancel();
|
||||||
|
subscription.cancel();
|
||||||
|
};
|
||||||
}, [spotify, queryClient]);
|
}, [spotify, queryClient]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -915,6 +915,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.0"
|
version: "3.0.0"
|
||||||
|
flutter_sharing_intent:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_sharing_intent
|
||||||
|
sha256: "6eb896e6523b735e8230eeb206fd3b9f220f11ce879c2400a90b443147036ff9"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0"
|
||||||
flutter_svg:
|
flutter_svg:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@ -121,6 +121,7 @@ dependencies:
|
|||||||
skeletonizer: ^0.8.0
|
skeletonizer: ^0.8.0
|
||||||
app_links: ^3.5.0
|
app_links: ^3.5.0
|
||||||
win32_registry: ^1.1.2
|
win32_registry: ^1.1.2
|
||||||
|
flutter_sharing_intent: ^1.1.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.3.2
|
build_runner: ^2.3.2
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user