From ddee58eee0eb2e40ef4a54cf45510a90d006a6ef Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sat, 25 May 2024 14:35:21 +0800 Subject: [PATCH] Update task detail page --- lib/api/task.dart | 10 +++++++ lib/api/task.g.dart | 8 ++++++ lib/components/task.dart | 1 + lib/dialog/task_page.dart | 58 +++++++++++++++++++++++++-------------- lib/l10n/app_en.arb | 13 ++++++++- lib/l10n/app_zh.arb | 13 ++++++++- 6 files changed, 80 insertions(+), 23 deletions(-) diff --git a/lib/api/task.dart b/lib/api/task.dart index 05085c2..3033cbc 100644 --- a/lib/api/task.dart +++ b/lib/api/task.dart @@ -63,6 +63,8 @@ class TaskDownloadSingleProgress { required this.total, required this.started, required this.downloaded, + required this.speed, + required this.lastUpdated, }); final int index; final String token; @@ -75,6 +77,9 @@ class TaskDownloadSingleProgress { @JsonKey(fromJson: _fromJson, toJson: _toJson) final DateTime started; final int downloaded; + final double speed; + @JsonKey(name: 'last_updated') + final int lastUpdated; static DateTime _fromJson(int d) => DateTime.fromMillisecondsSinceEpoch(d, isUtc: true); static int _toJson(DateTime d) => d.millisecondsSinceEpoch; @@ -90,6 +95,8 @@ class TaskDownloadProgess implements TaskProgressBasicType { required this.failedPage, required this.totalPage, required this.details, + required this.started, + required this.downloadedBytes, }); @JsonKey(name: 'downloaded_page') final int downloadedPage; @@ -97,6 +104,9 @@ class TaskDownloadProgess implements TaskProgressBasicType { final int failedPage; @JsonKey(name: 'total_page') final int totalPage; + final int started; + @JsonKey(name: 'downloaded_bytes') + final int downloadedBytes; final List details; factory TaskDownloadProgess.fromJson(Map json) => _$TaskDownloadProgessFromJson(json); diff --git a/lib/api/task.g.dart b/lib/api/task.g.dart index 39db23e..c940804 100644 --- a/lib/api/task.g.dart +++ b/lib/api/task.g.dart @@ -44,6 +44,8 @@ TaskDownloadSingleProgress _$TaskDownloadSingleProgressFromJson( started: TaskDownloadSingleProgress._fromJson( (json['started'] as num).toInt()), downloaded: (json['downloaded'] as num).toInt(), + speed: (json['speed'] as num).toDouble(), + lastUpdated: (json['last_updated'] as num).toInt(), ); Map _$TaskDownloadSingleProgressToJson( @@ -58,6 +60,8 @@ Map _$TaskDownloadSingleProgressToJson( 'total': instance.total, 'started': TaskDownloadSingleProgress._toJson(instance.started), 'downloaded': instance.downloaded, + 'speed': instance.speed, + 'last_updated': instance.lastUpdated, }; TaskDownloadProgess _$TaskDownloadProgessFromJson(Map json) => @@ -69,6 +73,8 @@ TaskDownloadProgess _$TaskDownloadProgessFromJson(Map json) => .map((e) => TaskDownloadSingleProgress.fromJson(e as Map)) .toList(), + started: (json['started'] as num).toInt(), + downloadedBytes: (json['downloaded_bytes'] as num).toInt(), ); Map _$TaskDownloadProgessToJson( @@ -77,6 +83,8 @@ Map _$TaskDownloadProgessToJson( 'downloaded_page': instance.downloadedPage, 'failed_page': instance.failedPage, 'total_page': instance.totalPage, + 'started': instance.started, + 'downloaded_bytes': instance.downloadedBytes, 'details': instance.details, }; diff --git a/lib/components/task.dart b/lib/components/task.dart index ead0ec5..37a5f0f 100644 --- a/lib/components/task.dart +++ b/lib/components/task.dart @@ -99,6 +99,7 @@ class _TaskView extends State { LinearPercentIndicator( animation: true, animateFromLastPercent: true, + animationDuration: 200, progressColor: Colors.green, lineHeight: 20.0, barRadius: const Radius.circular(10), diff --git a/lib/dialog/task_page.dart b/lib/dialog/task_page.dart index 6348b65..bf9d315 100644 --- a/lib/dialog/task_page.dart +++ b/lib/dialog/task_page.dart @@ -116,14 +116,18 @@ class _TaskPage extends State { if (p.totalPage == 0) { return Text(i18n.fetchingMetadata); } + double speed = 0; + for (final e in p.details) { + speed += e.speed; + } if (p.failedPage == 0) { final percent = p.downloadedPage / p.totalPage; final percentText = "${(percent * 100).toStringAsFixed(2)}%"; - return Row(children: [ - Expanded( - child: LinearPercentIndicator( + return Column(children: [ + LinearPercentIndicator( animation: true, animateFromLastPercent: true, + animationDuration: 200, progressColor: Colors.green, lineHeight: 20.0, barRadius: const Radius.circular(10), @@ -131,8 +135,13 @@ class _TaskPage extends State { center: Text(percentText, style: const TextStyle(color: Colors.black)), percent: percent, - )), - Text("${p.downloadedPage}/${p.totalPage}"), + ), + Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Expanded( + child: Text(i18n.downloadedSize( + "${getFileSize(p.downloadedBytes)}${i18n.comma}${p.downloadedPage}/${p.totalPage}"))), + Text("${getFileSize((speed * 1000).toInt())}/s"), + ]), ]); } return Column(children: [ @@ -140,6 +149,9 @@ class _TaskPage extends State { fontSize: 16), _KeyValue(i18n.failedPages, p.failedPage.toString(), fontSize: 16), _KeyValue(i18n.totalPages, p.totalPage.toString(), fontSize: 16), + _KeyValue(i18n.downloadedSize2, getFileSize(p.downloadedBytes), + fontSize: 16), + _KeyValue(i18n.speed, "${getFileSize((speed * 1000).toInt())}/s", fontSize: 16), ]); } int now = 0; @@ -167,6 +179,7 @@ class _TaskPage extends State { child: LinearPercentIndicator( animation: true, animateFromLastPercent: true, + animationDuration: 200, progressColor: Colors.green, lineHeight: 20.0, barRadius: const Radius.circular(10), @@ -190,24 +203,27 @@ class _TaskPage extends State { itemCount: p.details.length, itemBuilder: (context, index) { final d = p.details[index]; - final percent = d.downloaded / d.total; + final percent = d.total == 0 ? 0.0 : d.downloaded / d.total; final percentText = "${(percent * 100).toStringAsFixed(2)}%"; - return Column(children: [ - Text("${d.name}(${d.width}x${d.height})"), - Row(children: [ + return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + SelectableText("${d.name}(${d.width}x${d.height})"), + LinearPercentIndicator( + animation: true, + animateFromLastPercent: true, + animationDuration: 200, + progressColor: Colors.green, + lineHeight: 20.0, + barRadius: const Radius.circular(10), + padding: EdgeInsets.zero, + center: + Text(percentText, style: const TextStyle(color: Colors.black)), + percent: percent, + ), + Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( - child: LinearPercentIndicator( - animation: true, - animateFromLastPercent: true, - progressColor: Colors.green, - lineHeight: 20.0, - barRadius: const Radius.circular(10), - padding: EdgeInsets.zero, - center: Text(percentText, - style: const TextStyle(color: Colors.black)), - percent: percent, - )), - Text("${getFileSize(d.downloaded)}/${getFileSize(d.total)}"), + child: Text( + "${getFileSize(d.downloaded)}/${getFileSize(d.total)}")), + Text("${getFileSize((d.speed * 1000).toInt())}/s"), ]), ]); }, diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4947c1e..13bbb0f 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -170,5 +170,16 @@ "fetchingMetadata": "Fetching metadata ...", "downloadedPages": "Downloaded pages", "failedPages": "Download failed pages", - "totalPages": "Total pages" + "totalPages": "Total pages", + "downloadedSize": "Downloaded {size}", + "@downloadedSize": { + "placeholders": { + "size": { + "type": "String" + } + } + }, + "comma": ", ", + "downloadedSize2": "Downloaded size", + "speed": "Speed" } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 233e060..df6111d 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -170,5 +170,16 @@ "fetchingMetadata": "获取元数据中…", "downloadedPages": "已下载页数", "failedPages": "下载失败的页数", - "totalPages": "总页数" + "totalPages": "总页数", + "downloadedSize": "已下载 {size}", + "@downloadedSize": { + "placeholders": { + "size": { + "type": "String" + } + } + }, + "comma": ",", + "downloadedSize2": "已下载大小", + "speed": "速度" }