From be003839664ddb2d2defa1963e1cbf23c6ab17ce Mon Sep 17 00:00:00 2001 From: stonegate Date: Sun, 23 Aug 2020 17:41:43 +0800 Subject: [PATCH] Change download style, you can cancel downlaod when paused. --- lib/episodes/episode_download.dart | 49 +++++++++++++++++++++--------- lib/home/download_list.dart | 38 ++++++++++++++++------- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/lib/episodes/episode_download.dart b/lib/episodes/episode_download.dart index 934bb2d..52e98a3 100644 --- a/lib/episodes/episode_download.dart +++ b/lib/episodes/episode_download.dart @@ -11,6 +11,7 @@ import 'package:provider/provider.dart'; import '../state/audio_state.dart'; import '../state/download_state.dart'; import '../state/setting_state.dart'; +import '../type/episode_task.dart'; import '../type/episodebrief.dart'; import '../util/custom_widget.dart'; import '../util/extension_helper.dart'; @@ -167,8 +168,8 @@ class _DownloadButtonState extends State { builder: (_, data, __) => _buttonOnMenu( Center( child: SizedBox( - height: 18, - width: 18, + height: 20, + width: 20, child: CustomPaint( painter: DownloadPainter( color: Colors.grey[700], @@ -196,11 +197,11 @@ class _DownloadButtonState extends State { duration: Duration(milliseconds: 1000), tween: Tween(begin: 0.0, end: 1.0), builder: (context, fraction, child) => SizedBox( - height: 18, - width: 18, + height: 20, + width: 20, child: CustomPaint( painter: DownloadPainter( - color: Colors.grey[700], + color: context.accentColor, fraction: fraction, progressColor: context.accentColor, progress: task.progress / 100), @@ -226,11 +227,11 @@ class _DownloadButtonState extends State { duration: Duration(milliseconds: 500), tween: Tween(begin: 0.0, end: 1.0), builder: (context, fraction, child) => SizedBox( - height: 18, - width: 18, + height: 20, + width: 20, child: CustomPaint( painter: DownloadPainter( - color: Colors.grey[700], + color: context.accentColor, fraction: 1, progressColor: context.accentColor, progress: task.progress / 100, @@ -245,13 +246,31 @@ class _DownloadButtonState extends State { case 3: Provider.of(context, listen: false) .updateMediaItem(task.episode); - return _buttonOnMenu( - Icon( - Icons.done_all, - color: Theme.of(context).accentColor, - ), () { - _deleteDownload(task.episode); - }); + return Material( + color: Colors.transparent, + child: InkWell( + onTap: () { + _deleteDownload(task.episode); + }, + child: Container( + height: 50.0, + alignment: Alignment.center, + padding: EdgeInsets.symmetric(horizontal: 18), + child: SizedBox( + height: 20, + width: 20, + child: CustomPaint( + painter: DownloadPainter( + color: context.accentColor, + fraction: 1, + progressColor: context.accentColor, + progress: 1, + ), + ), + ), + ), + ), + ); break; case 4: return _buttonOnMenu(Icon(Icons.refresh, color: Colors.red), diff --git a/lib/home/download_list.dart b/lib/home/download_list.dart index 3831460..a9f3a3d 100644 --- a/lib/home/download_list.dart +++ b/lib/home/download_list.dart @@ -4,6 +4,7 @@ import 'package:provider/provider.dart'; import '../episodes/episode_detail.dart'; import '../state/download_state.dart'; +import '../type/episode_task.dart'; import '../util/pageroute.dart'; class DownloadList extends StatefulWidget { @@ -17,11 +18,20 @@ Widget _downloadButton(EpisodeTask task, BuildContext context) { var downloader = Provider.of(context, listen: false); switch (task.status.value) { case 2: - return IconButton( - icon: Icon( - Icons.pause_circle_filled, - ), - onPressed: () => downloader.pauseTask(task.episode), + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + icon: Icon( + Icons.pause_circle_filled, + ), + onPressed: () => downloader.pauseTask(task.episode), + ), + IconButton( + icon: Icon(Icons.close), + onPressed: () => downloader.delTask(task.episode), + ), + ], ); case 4: return Row( @@ -38,10 +48,16 @@ Widget _downloadButton(EpisodeTask task, BuildContext context) { ], ); case 6: - return IconButton( - icon: Icon(Icons.play_circle_filled), - onPressed: () => downloader.resumeTask(task.episode), - ); + return Row(mainAxisSize: MainAxisSize.min, children: [ + IconButton( + icon: Icon(Icons.play_circle_filled), + onPressed: () => downloader.resumeTask(task.episode), + ), + IconButton( + icon: Icon(Icons.close), + onPressed: () => downloader.delTask(task.episode), + ), + ]); break; default: return Center(); @@ -54,12 +70,12 @@ class _DownloadListState extends State { return SliverPadding( padding: EdgeInsets.zero, sliver: Consumer(builder: (_, downloader, __) { - var tasks = downloader.episodeTasks + final tasks = downloader.episodeTasks .where((task) => task.status.value != 3) .toList(); return tasks.length > 0 ? SliverPadding( - padding: EdgeInsets.all(5.0), + padding: EdgeInsets.symmetric(vertical: 5.0), sliver: SliverList( delegate: SliverChildBuilderDelegate( (context, index) {