Skip to content

Commit

Permalink
feat: Add receiving intent to download YouTube URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinkey04 committed Nov 29, 2021
1 parent e1eb1d7 commit b4890fe
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 21 deletions.
18 changes: 18 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</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" />
<!--TODO: Add this filter, if you want support opening urls into your app-->
<data
android:scheme="https"
android:host="youtube.com"
android:pathPrefix=""/>
</intent-filter>

<!--TODO: Add this filter, if you want to support sharing text into your app-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
1 change: 0 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.flutterFFmpegPackage = 'audio-lts'
repositories {
google()
jcenter()
Expand Down
1 change: 0 additions & 1 deletion lib/provider/audio_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ String formatDuration(Duration d) {
bool isValidYouTubeURL(String url) {
url =
url.replaceAll('://m.y', '://www.y'); //For changing mobile URL to web URL
print('Web URL: ' + url);
RegExp youtubeVideoRegExp = new RegExp(
r'http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([(\w)\-\_]*)(&(amp;)?[(\w)\?=]*)?');
var matches = youtubeVideoRegExp.allMatches(url);
Expand Down
43 changes: 41 additions & 2 deletions lib/view/home_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,54 @@ import 'package:raag/view/download_music.dart';
import 'package:raag/view/playback_controls.dart';
import 'package:raag/view/settings.dart';
import 'package:raag/widgets/my_music_list.dart';
import 'package:raag/provider/audio_helper.dart';

import 'package:receive_sharing_intent/receive_sharing_intent.dart';

class HomeScaffold extends StatefulWidget {
@override
State<HomeScaffold> createState() => _HomeScaffoldState();
}

class _HomeScaffoldState extends State<HomeScaffold> {
@override
void initState() {
super.initState();
receiveDownloadURLIntent();
}

void receiveDownloadURLIntent() {
// For sharing or opening urls/text coming from outside the app while the app is in the memory
ReceiveSharingIntent.getTextStream().listen((String value) {
if (value != null) launchDownloader(value);
}, onError: (err) {
print("getLinkStream error: $err");
});

// For sharing or opening urls/text coming from outside the app while the app is closed
ReceiveSharingIntent.getInitialText().then((String value) {
if (value != null) launchDownloader(value);
});
}

void launchDownloader(String url) {
debugPrint("Received URL: $url");
if (isValidYouTubeURL(url)) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DownloadMusic(url: url),
));
}
}

class HomeScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
final themeProvider = Provider.of<SettingsProvider>(context);

return Scaffold(
appBar: AppBar(
toolbarHeight: 70,
toolbarHeight: 70,
systemOverlayStyle: themeProvider.darkTheme
? SystemUiOverlayStyle.dark
: SystemUiOverlayStyle.light,
Expand Down
9 changes: 2 additions & 7 deletions lib/view/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,22 @@ class SplashScreen extends StatefulWidget {
}

class _SplashScreenState extends State<SplashScreen> {
bool leaveSplash = false;

@override
void initState() {
super.initState();
onBoarding();
awaitPopulateSongs();
}

void onBoarding() async{
if(! await _preferencesProvider.getBool(Preferences.ON_BOARDING_DONE))
void onBoarding() async {
if (!await _preferencesProvider.getBool(Preferences.ON_BOARDING_DONE))
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => OnBoarding()));
_preferencesProvider.setBool(Preferences.ON_BOARDING_DONE, true);
}

awaitPopulateSongs() async {
await SplashScreen.populateSongsIntoDB();
setState(() {
leaveSplash = true;
});
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => HomeScaffold()));
}
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.1"
receive_sharing_intent:
dependency: "direct main"
description:
name: receive_sharing_intent
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.5"
rflutter_alert:
dependency: "direct main"
description:
Expand Down
15 changes: 5 additions & 10 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,30 @@ dependencies:
audio_manager: ^0.8.2
clipboard: ^0.1.2+8
connectivity: ^3.0.6
cupertino_icons: ^1.0.0
ext_storage: ^1.0.3
flutter:
sdk: flutter
flutter_audio_query: ^0.3.5+6
fluttertoast: ^8.0.8
http: ^0.13.3
marquee: ^2.2.0
open_file: ^3.2.0
path_provider: ^2.0.0-nullsafety.1
provider: ^6.0.1
receive_sharing_intent: ^1.4.5
rflutter_alert: ^2.0.4
shared_preferences: ^2.0.3
sqflite: ^2.0.0+3
webview_flutter: ^2.1.1
youtube_explode_dart: ^1.10.6

flutter:
sdk: flutter


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.0

dev_dependencies:
flutter_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
uses-material-design: true
Expand All @@ -71,4 +66,4 @@ flutter:
- asset: assets/fonts/Alata-Regular.ttf
- family: YouTubeIcon
fonts:
- asset: assets/fonts/YouTubeIcon.ttf
- asset: assets/fonts/YouTubeIcon.ttf

0 comments on commit b4890fe

Please sign in to comment.