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

Replaced search Icon with button and added progress indicator #7

Merged
merged 2 commits into from Aug 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 71 additions & 18 deletions lib/main.dart
Expand Up @@ -39,6 +39,7 @@ class AppName extends StatefulWidget {

class AppState extends State<AppName> {
TextEditingController searchBar = new TextEditingController();
bool fetchingSongs = false;

void initState() {
super.initState();
Expand Down Expand Up @@ -72,15 +73,21 @@ class AppState extends State<AppName> {
});
}

search(searchQuery) async {
search() async {
String searchQuery = searchBar.text;
if (searchQuery.isEmpty) return;
fetchingSongs = true;
setState(() {});
await fetchSongsList(searchQuery);
fetchingSongs = false;
setState(() {});
}

getSongDetails(String id, var context) async {
await fetchSongDetails(id);
checker = "Haa";
Navigator.push(context, MaterialPageRoute(builder: (context) => AudioApp()));
Navigator.push(
context, MaterialPageRoute(builder: (context) => AudioApp()));
}

downloadSong(id) async {
Expand Down Expand Up @@ -113,27 +120,31 @@ class AppState extends State<AppName> {
messageTextStyle: TextStyle(color: accent),
progressWidget: Padding(
padding: const EdgeInsets.all(20.0),
child: CircularProgressIndicator(valueColor: new AlwaysStoppedAnimation<Color>(accent)),
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(accent)),
),
);
await pr.show();

final filename = title + ".m4a";
final artname = title + "_artwork.jpg";

String dlPath = await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_MUSIC);
String dlPath = await ExtStorage.getExternalStoragePublicDirectory(
ExtStorage.DIRECTORY_MUSIC);
String filepath = dlPath + "/" + filename;
String filepath2 = dlPath + "/" + artname;
if (has_320 == "true") {
kUrl = raw_kUrl.replaceAll("_96.mp4", "_320.mp4");
final client = http.Client();
final request = new http.Request('HEAD', Uri.parse(kUrl))..followRedirects = false;
final request = new http.Request('HEAD', Uri.parse(kUrl))
..followRedirects = false;
final response = await client.send(request);
print(response.statusCode);
kUrl = (response.headers['location']);
print(raw_kUrl);
print(kUrl);
final request2 = new http.Request('HEAD', Uri.parse(kUrl))..followRedirects = false;
final request2 = new http.Request('HEAD', Uri.parse(kUrl))
..followRedirects = false;
final response2 = await client.send(request2);
if (response2.statusCode != 200) {
kUrl = kUrl.replaceAll(".mp4", ".mp3");
Expand Down Expand Up @@ -177,7 +188,13 @@ class AppState extends State<AppName> {
}
print("Done");
Fluttertoast.showToast(
msg: "Download Complete!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 1, backgroundColor: Colors.black, textColor: Color(0xff61e88a), fontSize: 14.0);
msg: "Download Complete!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Color(0xff61e88a),
fontSize: 14.0);
} else if (status.isDenied || status.isPermanentlyDenied) {
Fluttertoast.showToast(
msg: "Storage Permission Denied!\nCan't Download Songs",
Expand Down Expand Up @@ -251,7 +268,8 @@ class AppState extends State<AppName> {
),
Text(
" Now Playing",
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.w600),
)
],
),
Expand All @@ -271,7 +289,11 @@ class AppState extends State<AppName> {
else
Scaffold.of(contextt).showSnackBar(new SnackBar(
content: new Text("Nothing is Playing."),
action: SnackBarAction(label: 'Okay', textColor: accent, onPressed: Scaffold.of(contextt).hideCurrentSnackBar),
action: SnackBarAction(
label: 'Okay',
textColor: accent,
onPressed:
Scaffold.of(contextt).hideCurrentSnackBar),
backgroundColor: Colors.black38,
duration: Duration(seconds: 2),
))
Expand Down Expand Up @@ -315,15 +337,18 @@ class AppState extends State<AppName> {
icon: Icon(MdiIcons.dotsVertical),
color: accent,
onPressed: () => {
Navigator.push(context, MaterialPageRoute(builder: (context) => AboutPage())),
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AboutPage())),
}),
)
]),
),
new Padding(padding: EdgeInsets.only(top: 20)),
new TextField(
onSubmitted: (String value) {
search(value);
search();
},
controller: searchBar,
style: TextStyle(
Expand All @@ -344,9 +369,26 @@ class AppState extends State<AppName> {
borderRadius: BorderRadius.all(Radius.circular(100)),
borderSide: BorderSide(color: accent),
),
suffixIcon: Icon(
Icons.search,
suffixIcon: IconButton(
icon: fetchingSongs
? SizedBox(
height: 18,
width: 18,
child: Center(
child: CircularProgressIndicator(
valueColor:
new AlwaysStoppedAnimation<Color>(
accent)),
),
)
: Icon(
Icons.search,
color: accent,
),
color: accent,
onPressed: () {
search();
},
),
border: InputBorder.none,
hintText: "Search...",
Expand All @@ -370,12 +412,14 @@ class AppState extends State<AppName> {
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: Card(
color: Colors.black12,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
elevation: 0,
child: InkWell(
borderRadius: BorderRadius.circular(10.0),
onTap: () {
getSongDetails(searchedList[index]["id"], context);
getSongDetails(
searchedList[index]["id"], context);
},
splashColor: accent,
hoverColor: accent,
Expand All @@ -393,14 +437,23 @@ class AppState extends State<AppName> {
),
),
title: Text(
(searchedList[index]['title']).toString().split("(")[0].replaceAll("&quot;", "\"").replaceAll("&amp;", "&"),
(searchedList[index]['title'])
.toString()
.split("(")[0]
.replaceAll("&quot;", "\"")
.replaceAll("&amp;", "&"),
style: TextStyle(color: Colors.white),
),
subtitle: Text(
searchedList[index]['more_info']["singers"],
searchedList[index]['more_info']
["singers"],
style: TextStyle(color: Colors.white),
),
trailing: IconButton(color: accent, icon: Icon(MdiIcons.downloadOutline), onPressed: () => downloadSong(searchedList[index]["id"])),
trailing: IconButton(
color: accent,
icon: Icon(MdiIcons.downloadOutline),
onPressed: () => downloadSong(
searchedList[index]["id"])),
),
],
),
Expand Down