Skip to content

Commit

Permalink
feat: Add paste and download buttons
Browse files Browse the repository at this point in the history
wip: Create WebView for YouTube mobile

fix: Change JDK version for GitHub actions
  • Loading branch information
ashwinkey04 committed Jan 27, 2021
1 parent 1dd23a2 commit d709d31
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
java-version: '8.x'
- uses: subosito/flutter-action@v1
with:
channel: 'dev'
Expand Down
119 changes: 87 additions & 32 deletions lib/view/download_music.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:io';
import 'package:clipboard/clipboard.dart';
import 'package:downloads_path_provider_28/downloads_path_provider_28.dart';
import 'package:flutter/material.dart';
import 'package:raag/model/connectivity.dart';
import 'package:raag/model/strings.dart';
import 'package:raag/provider/theme.dart';
import 'package:raag/view/youtube_search.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart';

Expand All @@ -16,6 +18,10 @@ class _DownloadMusicState extends State<DownloadMusic> {
String alertBody = "";
String alertTitle = "";
double progressOpacity = 0;
var thumbnailURL =
"https://user-images.githubusercontent.com/20596763/104451609-cceeff80-55c7-11eb-92f9-828dc8940daf.png";
final urlFieldController = TextEditingController();


void setTitle(String title) {
setState(() {
Expand All @@ -35,6 +41,17 @@ class _DownloadMusicState extends State<DownloadMusic> {
});
}

void setThumbnail(String url) {
setState(() {
thumbnailURL = url;
});
}

@override
void dispose(){
urlFieldController.dispose();
super.dispose();
}
Future<int> downloadMusic(String url, BuildContext context) async {
if (await isConnected() == false) {
Alert(
Expand All @@ -58,6 +75,7 @@ class _DownloadMusicState extends State<DownloadMusic> {
setBody("$downloading $title");
setTitle(fetchingStream);

setThumbnail(video.thumbnails.mediumResUrl);
var streamManifest = await yt.videos.streamsClient.getManifest(video.id);
var streamInfo = streamManifest.audioOnly.withHighestBitrate();

Expand Down Expand Up @@ -94,41 +112,76 @@ class _DownloadMusicState extends State<DownloadMusic> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios_outlined),
onPressed: () {
Navigator.pop(context);
}),
title: Text("Download music",
style: Theme.of(context).textTheme.headline3),
centerTitle: true),
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back_ios_outlined),
onPressed: () => Navigator.pop(context)),
title: Text("Download music",
style: Theme.of(context).textTheme.headline3),
centerTitle: true,
actions: [
IconButton(
icon: Icon(
Icons.search_rounded,
color: Theme.of(context).accentColor,
),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => YoutubeSearch(),
)),
)
],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(16),
color: Theme.of(context).backgroundColor,
child: TextField(
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headline3,
autocorrect: false,
textInputAction: TextInputAction.search,
onSubmitted: (url) {
downloadMusic(url, context);
},
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).accentColor)),
border: UnderlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).accentColor)),
hintText: pasteYoutube,
hintStyle: Theme.of(context).textTheme.subtitle1,
fillColor: Theme.of(context).accentColor,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: MediaQuery.of(context).size.width/1.5,
padding: EdgeInsets.all(16),
color: Theme.of(context).backgroundColor,
child: TextField(
controller: urlFieldController,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headline3,
autocorrect: false,
textInputAction: TextInputAction.search,
onSubmitted: (url) {
downloadMusic(url, context);
},
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).accentColor)),
border: UnderlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).accentColor)),
hintText: pasteYoutube,
hintStyle: Theme.of(context).textTheme.subtitle1,
fillColor: Theme.of(context).accentColor,
),
),
),
),
IconButton(
onPressed: () {
urlFieldController.clear();
FlutterClipboard.paste().then((value) {
urlFieldController.text=value;
urlFieldController.selection = TextSelection.fromPosition(TextPosition(offset: urlFieldController.text.length));
});
},
icon: Icon(Icons.paste_rounded,
color: Theme.of(context).accentColor,),
),
IconButton(
onPressed: () => downloadMusic(urlFieldController.text, context),
icon: Icon(Icons.download_rounded,
color: Theme.of(context).accentColor,),
)
],
),
Padding(
padding: EdgeInsets.symmetric(vertical: 16, horizontal: 32),
Expand All @@ -145,7 +198,9 @@ class _DownloadMusicState extends State<DownloadMusic> {
Text(
alertBody,
style: Theme.of(context).textTheme.subtitle1,
)
),
SizedBox(height: 32),
Image.network(thumbnailURL)
],
),
),
Expand Down
12 changes: 5 additions & 7 deletions lib/view/home_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ class HomeScaffold extends StatelessWidget {
Icons.download_rounded,
color: Theme.of(context).accentColor,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DownloadMusic(),
));
}),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DownloadMusic(),
))),
actions: <Widget>[
ThemeButton(),
],
Expand Down
17 changes: 17 additions & 0 deletions lib/view/youtube_search.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class YoutubeSearch extends StatefulWidget {
@override
_YoutubeSearchState createState() => _YoutubeSearchState();
}

class _YoutubeSearchState extends State<YoutubeSearch> {
@override
Widget build(BuildContext context) {
return WebView(

initialUrl: 'https://m.youtube.com',
);
}
}
61 changes: 41 additions & 20 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.1"
version: "2.5.0-nullsafety.3"
audio_manager:
dependency: "direct main"
description:
Expand Down Expand Up @@ -42,35 +42,42 @@ packages:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0-nullsafety.3"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0-nullsafety.5"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0-nullsafety.3"
clipboard:
dependency: "direct main"
description:
name: clipboard
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2+8"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0-nullsafety.3"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
version: "1.15.0-nullsafety.5"
connectivity:
dependency: "direct main"
description:
Expand Down Expand Up @@ -147,7 +154,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0-nullsafety.3"
ffi:
dependency: transitive
description:
Expand Down Expand Up @@ -226,6 +233,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3-nullsafety.3"
json_annotation:
dependency: transitive
description:
Expand All @@ -246,14 +260,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.1"
version: "0.12.10-nullsafety.3"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0-nullsafety.6"
nested:
dependency: transitive
description:
Expand All @@ -267,7 +281,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
version: "1.8.0-nullsafety.3"
path_provider_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -391,56 +405,63 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.2"
version: "1.8.0-nullsafety.4"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0-nullsafety.6"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0-nullsafety.3"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0-nullsafety.3"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0-nullsafety.3"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.2"
version: "0.2.19-nullsafety.6"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0-nullsafety.5"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0-nullsafety.5"
webview_flutter:
dependency: "direct main"
description:
name: webview_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
win32:
dependency: transitive
description:
Expand Down Expand Up @@ -470,5 +491,5 @@ packages:
source: hosted
version: "1.7.5"
sdks:
dart: ">=2.10.0-110 <=2.11.0-177.0.dev"
flutter: ">=1.16.0 <2.0.0"
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=1.22.0"
Loading

0 comments on commit d709d31

Please sign in to comment.