mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-06 13:59:19 +08:00
Update task detail page
This commit is contained in:
@@ -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<TaskDownloadSingleProgress> details;
|
||||
factory TaskDownloadProgess.fromJson(Map<String, dynamic> json) =>
|
||||
_$TaskDownloadProgessFromJson(json);
|
||||
|
||||
@@ -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<String, dynamic> _$TaskDownloadSingleProgressToJson(
|
||||
@@ -58,6 +60,8 @@ Map<String, dynamic> _$TaskDownloadSingleProgressToJson(
|
||||
'total': instance.total,
|
||||
'started': TaskDownloadSingleProgress._toJson(instance.started),
|
||||
'downloaded': instance.downloaded,
|
||||
'speed': instance.speed,
|
||||
'last_updated': instance.lastUpdated,
|
||||
};
|
||||
|
||||
TaskDownloadProgess _$TaskDownloadProgessFromJson(Map<String, dynamic> json) =>
|
||||
@@ -69,6 +73,8 @@ TaskDownloadProgess _$TaskDownloadProgessFromJson(Map<String, dynamic> json) =>
|
||||
.map((e) =>
|
||||
TaskDownloadSingleProgress.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
started: (json['started'] as num).toInt(),
|
||||
downloadedBytes: (json['downloaded_bytes'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TaskDownloadProgessToJson(
|
||||
@@ -77,6 +83,8 @@ Map<String, dynamic> _$TaskDownloadProgessToJson(
|
||||
'downloaded_page': instance.downloadedPage,
|
||||
'failed_page': instance.failedPage,
|
||||
'total_page': instance.totalPage,
|
||||
'started': instance.started,
|
||||
'downloaded_bytes': instance.downloadedBytes,
|
||||
'details': instance.details,
|
||||
};
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ class _TaskView extends State<TaskView> {
|
||||
LinearPercentIndicator(
|
||||
animation: true,
|
||||
animateFromLastPercent: true,
|
||||
animationDuration: 200,
|
||||
progressColor: Colors.green,
|
||||
lineHeight: 20.0,
|
||||
barRadius: const Radius.circular(10),
|
||||
|
||||
@@ -116,14 +116,18 @@ class _TaskPage extends State<TaskPage> {
|
||||
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<TaskPage> {
|
||||
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<TaskPage> {
|
||||
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<TaskPage> {
|
||||
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<TaskPage> {
|
||||
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"),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -170,5 +170,16 @@
|
||||
"fetchingMetadata": "获取元数据中…",
|
||||
"downloadedPages": "已下载页数",
|
||||
"failedPages": "下载失败的页数",
|
||||
"totalPages": "总页数"
|
||||
"totalPages": "总页数",
|
||||
"downloadedSize": "已下载 {size}",
|
||||
"@downloadedSize": {
|
||||
"placeholders": {
|
||||
"size": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
},
|
||||
"comma": ",",
|
||||
"downloadedSize2": "已下载大小",
|
||||
"speed": "速度"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user