From 0d1d8a922288f08e3f683b5731a98db7c1bf9994 Mon Sep 17 00:00:00 2001 From: stonegate Date: Thu, 13 Feb 2020 10:51:46 +0800 Subject: [PATCH] modified: lib/episodes/episodedetail.dart modified: lib/episodes/episodedownload.dart modified: lib/podcasts/podcastdetail.dart Added bottom menu ripple --- lib/episodes/episodedetail.dart | 90 +++++++++++++--------- lib/episodes/episodedownload.dart | 121 ++++++++++++++++-------------- lib/podcasts/podcastdetail.dart | 4 +- 3 files changed, 122 insertions(+), 93 deletions(-) diff --git a/lib/episodes/episodedetail.dart b/lib/episodes/episodedetail.dart index 007d4e2..846beb3 100644 --- a/lib/episodes/episodedetail.dart +++ b/lib/episodes/episodedetail.dart @@ -5,6 +5,7 @@ import 'package:provider/provider.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:tsacdop/class/audiostate.dart'; import 'package:tsacdop/class/episodebrief.dart'; import 'package:tsacdop/class/sqflite_localpodcast.dart'; @@ -204,6 +205,17 @@ class _MenuBarState extends State { _like = widget.episodeItem.liked; } + Widget _buttonOnMenu(Widget widget, Function() onTap) => Material( + color: Colors.transparent, + child: InkWell( + onTap: onTap, + child: Container( + height: 50.0, + padding: EdgeInsets.symmetric(horizontal: 15.0), + child: widget), + ), + ); + @override Widget build(BuildContext context) { final urlChange = Provider.of(context); @@ -241,44 +253,50 @@ class _MenuBarState extends State { ), ), (_like == 0 && !_liked) - ? InkWell( - onTap: () => saveLiked(widget.episodeItem.title), - child: Container( - padding: EdgeInsets.symmetric(horizontal: 10.0), - child: Icon( - Icons.favorite_border, - color: Colors.grey[700], - ), - ), - ) - : InkWell( - onTap: () => setUnliked(widget.episodeItem.title), - child: Container( - padding: EdgeInsets.symmetric(horizontal: 10.0), - child: Icon( - Icons.favorite, - color: Colors.red, - ), - ), - ), - DownloadButton(episodeBrief: widget.episodeItem), - IconButton( - icon: Icon(Icons.playlist_add, color: Colors.grey[700]), - onPressed: () {/*TODO*/}, - ), - Spacer(), - (widget.episodeItem.title != urlchange.title) - ? IconButton( - icon: Icon( - Icons.play_arrow, + ? _buttonOnMenu( + Icon( + Icons.favorite_border, color: Colors.grey[700], ), - onPressed: () { - urlChange.audioUrl = widget.episodeItem.enclosureUrl; - urlChange.rssTitle = widget.episodeItem.title; - urlChange.feedTitle = widget.episodeItem.feedTitle; - urlChange.imageUrl = widget.episodeItem.imageUrl; - }, + () => saveLiked(widget.episodeItem.title)) + : _buttonOnMenu( + Icon( + Icons.favorite, + color: Colors.red, + ), + () => setUnliked(widget.episodeItem.title)), + DownloadButton(episodeBrief: widget.episodeItem), + _buttonOnMenu(Icon(Icons.playlist_add, color: Colors.grey[700]), + () { + Fluttertoast.showToast( + msg: 'Not support yet', + gravity: ToastGravity.BOTTOM, + ); + /*TODO*/ + }), + Spacer(), + (widget.episodeItem.title != urlchange.title) + ? Material( + color: Colors.transparent, + child: InkWell( + borderRadius: BorderRadius.only( + topRight: Radius.circular(5.0), + bottomRight: Radius.circular(5.0)), + onTap: () { + urlChange.audioUrl = widget.episodeItem.enclosureUrl; + urlChange.rssTitle = widget.episodeItem.title; + urlChange.feedTitle = widget.episodeItem.feedTitle; + urlChange.imageUrl = widget.episodeItem.imageUrl; + }, + child: Container( + height: 50.0, + padding: EdgeInsets.symmetric(horizontal: 20.0), + child: Icon( + Icons.play_arrow, + color: Colors.grey[700], + ), + ), + ), ) : (widget.episodeItem.title == urlchange.title && urlchange.audioState == AudioState.play) diff --git a/lib/episodes/episodedownload.dart b/lib/episodes/episodedownload.dart index 936d7ae..6b30720 100644 --- a/lib/episodes/episodedownload.dart +++ b/lib/episodes/episodedownload.dart @@ -140,7 +140,7 @@ class _DownloadButtonState extends State { task.taskId = newTaskId; var dbHelper = DBHelper(); await dbHelper.saveDownloaded(task.taskId, task.link); - Fluttertoast.showToast( + Fluttertoast.showToast( msg: 'Download again', gravity: ToastGravity.BOTTOM, ); @@ -190,6 +190,17 @@ class _DownloadButtonState extends State { } } + Widget _buttonOnMenu(Widget widget, Function() onTap) => Material( + color: Colors.transparent, + child: InkWell( + onTap: onTap, + child: Container( + height: 50.0, + padding: EdgeInsets.symmetric(horizontal: 15.0), + child: widget), + ), + ); + @override Widget build(BuildContext context) { return _downloadButton(_task); @@ -199,72 +210,70 @@ class _DownloadButtonState extends State { if (_isLoading) return Center(); else if (task.status == DownloadTaskStatus.undefined) { - - return IconButton( - onPressed: () { - _requestDownload(task); - }, - icon: Icon( - Icons.arrow_downward, - color: Colors.grey[700], - ), - ); + return _buttonOnMenu( + Icon( + Icons.arrow_downward, + color: Colors.grey[700], + ), + () => _requestDownload(task)); } else if (task.status == DownloadTaskStatus.running) { - return InkWell( - onTap: () { - _pauseDownload(task); - }, - child: Container( - padding: EdgeInsets.symmetric(horizontal: 18), - child: SizedBox( - height: 18, - width: 18, - child: CircularProgressIndicator( - backgroundColor: Colors.grey[200], - strokeWidth: 2, - valueColor: AlwaysStoppedAnimation(Colors.blue), - value: task.progress / 100, + return Material( + color: Colors.transparent, + child: InkWell( + onTap: () { + _pauseDownload(task); + }, + child: Container( + height: 50.0, + alignment: Alignment.center, + padding: EdgeInsets.symmetric(horizontal: 18.0), + child: SizedBox( + height: 18, + width: 18, + child: CircularProgressIndicator( + backgroundColor: Colors.grey[500], + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation(Colors.blue), + value: task.progress / 100, + ), ), ), ), ); } else if (task.status == DownloadTaskStatus.paused) { - return InkWell( - onTap: () { - _resumeDownload(task); - }, - child: Container( - padding: EdgeInsets.symmetric(horizontal: 18), - child: SizedBox( - height: 18, - width: 18, - child: CircularProgressIndicator( - backgroundColor: Colors.grey[200], - strokeWidth: 2, - valueColor: AlwaysStoppedAnimation(Colors.red), - value: task.progress / 100, + return Material( + color: Colors.transparent, + child: InkWell( + onTap: () { + _resumeDownload(task); + }, + child: Container( + height: 50.0, + alignment: Alignment.center, + padding: EdgeInsets.symmetric(horizontal: 18), + child: SizedBox( + height: 18, + width: 18, + child: CircularProgressIndicator( + backgroundColor: Colors.grey[500], + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation(Colors.red), + value: task.progress / 100, + ), ), ), ), ); } else if (task.status == DownloadTaskStatus.complete) { - - return IconButton( - icon: Icon( - Icons.done_all, - color: Colors.blue, - ), - onPressed: () { - _deleteDownload(task); - }, - ); + return _buttonOnMenu( + Icon( + Icons.done_all, + color: Colors.blue, + ), + () => _deleteDownload(task)); } else if (task.status == DownloadTaskStatus.failed) { - return IconButton( - icon: Icon(Icons.refresh, color: Colors.red), - onPressed: () { - _retryDownload(task); - }, - ); + return _buttonOnMenu( + Icon(Icons.refresh, color: Colors.red), () => _retryDownload(task)); } return Center(); } @@ -279,4 +288,4 @@ class _TaskInfo { DownloadTaskStatus status = DownloadTaskStatus.undefined; _TaskInfo({this.name, this.link}); -} \ No newline at end of file +} diff --git a/lib/podcasts/podcastdetail.dart b/lib/podcasts/podcastdetail.dart index 1aa39e5..e081e31 100644 --- a/lib/podcasts/podcastdetail.dart +++ b/lib/podcasts/podcastdetail.dart @@ -7,6 +7,7 @@ import 'package:tsacdop/class/podcastlocal.dart'; import 'package:tsacdop/class/episodebrief.dart'; import 'package:tsacdop/class/sqflite_localpodcast.dart'; import 'package:tsacdop/util/episodegrid.dart'; +import 'package:tsacdop/webfeed/webfeed.dart'; class PodcastDetail extends StatefulWidget { PodcastDetail({Key key, this.podcastLocal}) : super(key: key); @@ -22,7 +23,8 @@ class _PodcastDetailState extends State { Future _updateRssItem(PodcastLocal podcastLocal) async { var dbHelper = DBHelper(); final response = await Dio().get(podcastLocal.rssUrl); - final result = await dbHelper.savePodcastRss(response.data); + var _p = RssFeed.parse(response.data); + final result = await dbHelper.savePodcastRss(_p); if (result == 0 && mounted) setState(() {}); }