mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Update task detail page
This commit is contained in:
@@ -63,6 +63,8 @@ class TaskDownloadSingleProgress {
|
|||||||
required this.total,
|
required this.total,
|
||||||
required this.started,
|
required this.started,
|
||||||
required this.downloaded,
|
required this.downloaded,
|
||||||
|
required this.speed,
|
||||||
|
required this.lastUpdated,
|
||||||
});
|
});
|
||||||
final int index;
|
final int index;
|
||||||
final String token;
|
final String token;
|
||||||
@@ -75,6 +77,9 @@ class TaskDownloadSingleProgress {
|
|||||||
@JsonKey(fromJson: _fromJson, toJson: _toJson)
|
@JsonKey(fromJson: _fromJson, toJson: _toJson)
|
||||||
final DateTime started;
|
final DateTime started;
|
||||||
final int downloaded;
|
final int downloaded;
|
||||||
|
final double speed;
|
||||||
|
@JsonKey(name: 'last_updated')
|
||||||
|
final int lastUpdated;
|
||||||
static DateTime _fromJson(int d) =>
|
static DateTime _fromJson(int d) =>
|
||||||
DateTime.fromMillisecondsSinceEpoch(d, isUtc: true);
|
DateTime.fromMillisecondsSinceEpoch(d, isUtc: true);
|
||||||
static int _toJson(DateTime d) => d.millisecondsSinceEpoch;
|
static int _toJson(DateTime d) => d.millisecondsSinceEpoch;
|
||||||
@@ -90,6 +95,8 @@ class TaskDownloadProgess implements TaskProgressBasicType {
|
|||||||
required this.failedPage,
|
required this.failedPage,
|
||||||
required this.totalPage,
|
required this.totalPage,
|
||||||
required this.details,
|
required this.details,
|
||||||
|
required this.started,
|
||||||
|
required this.downloadedBytes,
|
||||||
});
|
});
|
||||||
@JsonKey(name: 'downloaded_page')
|
@JsonKey(name: 'downloaded_page')
|
||||||
final int downloadedPage;
|
final int downloadedPage;
|
||||||
@@ -97,6 +104,9 @@ class TaskDownloadProgess implements TaskProgressBasicType {
|
|||||||
final int failedPage;
|
final int failedPage;
|
||||||
@JsonKey(name: 'total_page')
|
@JsonKey(name: 'total_page')
|
||||||
final int totalPage;
|
final int totalPage;
|
||||||
|
final int started;
|
||||||
|
@JsonKey(name: 'downloaded_bytes')
|
||||||
|
final int downloadedBytes;
|
||||||
final List<TaskDownloadSingleProgress> details;
|
final List<TaskDownloadSingleProgress> details;
|
||||||
factory TaskDownloadProgess.fromJson(Map<String, dynamic> json) =>
|
factory TaskDownloadProgess.fromJson(Map<String, dynamic> json) =>
|
||||||
_$TaskDownloadProgessFromJson(json);
|
_$TaskDownloadProgessFromJson(json);
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ TaskDownloadSingleProgress _$TaskDownloadSingleProgressFromJson(
|
|||||||
started: TaskDownloadSingleProgress._fromJson(
|
started: TaskDownloadSingleProgress._fromJson(
|
||||||
(json['started'] as num).toInt()),
|
(json['started'] as num).toInt()),
|
||||||
downloaded: (json['downloaded'] 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(
|
Map<String, dynamic> _$TaskDownloadSingleProgressToJson(
|
||||||
@@ -58,6 +60,8 @@ Map<String, dynamic> _$TaskDownloadSingleProgressToJson(
|
|||||||
'total': instance.total,
|
'total': instance.total,
|
||||||
'started': TaskDownloadSingleProgress._toJson(instance.started),
|
'started': TaskDownloadSingleProgress._toJson(instance.started),
|
||||||
'downloaded': instance.downloaded,
|
'downloaded': instance.downloaded,
|
||||||
|
'speed': instance.speed,
|
||||||
|
'last_updated': instance.lastUpdated,
|
||||||
};
|
};
|
||||||
|
|
||||||
TaskDownloadProgess _$TaskDownloadProgessFromJson(Map<String, dynamic> json) =>
|
TaskDownloadProgess _$TaskDownloadProgessFromJson(Map<String, dynamic> json) =>
|
||||||
@@ -69,6 +73,8 @@ TaskDownloadProgess _$TaskDownloadProgessFromJson(Map<String, dynamic> json) =>
|
|||||||
.map((e) =>
|
.map((e) =>
|
||||||
TaskDownloadSingleProgress.fromJson(e as Map<String, dynamic>))
|
TaskDownloadSingleProgress.fromJson(e as Map<String, dynamic>))
|
||||||
.toList(),
|
.toList(),
|
||||||
|
started: (json['started'] as num).toInt(),
|
||||||
|
downloadedBytes: (json['downloaded_bytes'] as num).toInt(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$TaskDownloadProgessToJson(
|
Map<String, dynamic> _$TaskDownloadProgessToJson(
|
||||||
@@ -77,6 +83,8 @@ Map<String, dynamic> _$TaskDownloadProgessToJson(
|
|||||||
'downloaded_page': instance.downloadedPage,
|
'downloaded_page': instance.downloadedPage,
|
||||||
'failed_page': instance.failedPage,
|
'failed_page': instance.failedPage,
|
||||||
'total_page': instance.totalPage,
|
'total_page': instance.totalPage,
|
||||||
|
'started': instance.started,
|
||||||
|
'downloaded_bytes': instance.downloadedBytes,
|
||||||
'details': instance.details,
|
'details': instance.details,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ class _TaskView extends State<TaskView> {
|
|||||||
LinearPercentIndicator(
|
LinearPercentIndicator(
|
||||||
animation: true,
|
animation: true,
|
||||||
animateFromLastPercent: true,
|
animateFromLastPercent: true,
|
||||||
|
animationDuration: 200,
|
||||||
progressColor: Colors.green,
|
progressColor: Colors.green,
|
||||||
lineHeight: 20.0,
|
lineHeight: 20.0,
|
||||||
barRadius: const Radius.circular(10),
|
barRadius: const Radius.circular(10),
|
||||||
|
|||||||
@@ -116,14 +116,18 @@ class _TaskPage extends State<TaskPage> {
|
|||||||
if (p.totalPage == 0) {
|
if (p.totalPage == 0) {
|
||||||
return Text(i18n.fetchingMetadata);
|
return Text(i18n.fetchingMetadata);
|
||||||
}
|
}
|
||||||
|
double speed = 0;
|
||||||
|
for (final e in p.details) {
|
||||||
|
speed += e.speed;
|
||||||
|
}
|
||||||
if (p.failedPage == 0) {
|
if (p.failedPage == 0) {
|
||||||
final percent = p.downloadedPage / p.totalPage;
|
final percent = p.downloadedPage / p.totalPage;
|
||||||
final percentText = "${(percent * 100).toStringAsFixed(2)}%";
|
final percentText = "${(percent * 100).toStringAsFixed(2)}%";
|
||||||
return Row(children: [
|
return Column(children: [
|
||||||
Expanded(
|
LinearPercentIndicator(
|
||||||
child: LinearPercentIndicator(
|
|
||||||
animation: true,
|
animation: true,
|
||||||
animateFromLastPercent: true,
|
animateFromLastPercent: true,
|
||||||
|
animationDuration: 200,
|
||||||
progressColor: Colors.green,
|
progressColor: Colors.green,
|
||||||
lineHeight: 20.0,
|
lineHeight: 20.0,
|
||||||
barRadius: const Radius.circular(10),
|
barRadius: const Radius.circular(10),
|
||||||
@@ -131,8 +135,13 @@ class _TaskPage extends State<TaskPage> {
|
|||||||
center:
|
center:
|
||||||
Text(percentText, style: const TextStyle(color: Colors.black)),
|
Text(percentText, style: const TextStyle(color: Colors.black)),
|
||||||
percent: percent,
|
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: [
|
return Column(children: [
|
||||||
@@ -140,6 +149,9 @@ class _TaskPage extends State<TaskPage> {
|
|||||||
fontSize: 16),
|
fontSize: 16),
|
||||||
_KeyValue(i18n.failedPages, p.failedPage.toString(), fontSize: 16),
|
_KeyValue(i18n.failedPages, p.failedPage.toString(), fontSize: 16),
|
||||||
_KeyValue(i18n.totalPages, p.totalPage.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;
|
int now = 0;
|
||||||
@@ -167,6 +179,7 @@ class _TaskPage extends State<TaskPage> {
|
|||||||
child: LinearPercentIndicator(
|
child: LinearPercentIndicator(
|
||||||
animation: true,
|
animation: true,
|
||||||
animateFromLastPercent: true,
|
animateFromLastPercent: true,
|
||||||
|
animationDuration: 200,
|
||||||
progressColor: Colors.green,
|
progressColor: Colors.green,
|
||||||
lineHeight: 20.0,
|
lineHeight: 20.0,
|
||||||
barRadius: const Radius.circular(10),
|
barRadius: const Radius.circular(10),
|
||||||
@@ -190,24 +203,27 @@ class _TaskPage extends State<TaskPage> {
|
|||||||
itemCount: p.details.length,
|
itemCount: p.details.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final d = p.details[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)}%";
|
final percentText = "${(percent * 100).toStringAsFixed(2)}%";
|
||||||
return Column(children: [
|
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
Text("${d.name}(${d.width}x${d.height})"),
|
SelectableText("${d.name}(${d.width}x${d.height})"),
|
||||||
Row(children: [
|
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(
|
Expanded(
|
||||||
child: LinearPercentIndicator(
|
child: Text(
|
||||||
animation: true,
|
"${getFileSize(d.downloaded)}/${getFileSize(d.total)}")),
|
||||||
animateFromLastPercent: true,
|
Text("${getFileSize((d.speed * 1000).toInt())}/s"),
|
||||||
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)}"),
|
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -170,5 +170,16 @@
|
|||||||
"fetchingMetadata": "Fetching metadata ...",
|
"fetchingMetadata": "Fetching metadata ...",
|
||||||
"downloadedPages": "Downloaded pages",
|
"downloadedPages": "Downloaded pages",
|
||||||
"failedPages": "Download failed 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": "获取元数据中…",
|
"fetchingMetadata": "获取元数据中…",
|
||||||
"downloadedPages": "已下载页数",
|
"downloadedPages": "已下载页数",
|
||||||
"failedPages": "下载失败的页数",
|
"failedPages": "下载失败的页数",
|
||||||
"totalPages": "总页数"
|
"totalPages": "总页数",
|
||||||
|
"downloadedSize": "已下载 {size}",
|
||||||
|
"@downloadedSize": {
|
||||||
|
"placeholders": {
|
||||||
|
"size": {
|
||||||
|
"type": "String"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"comma": ",",
|
||||||
|
"downloadedSize2": "已下载大小",
|
||||||
|
"speed": "速度"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user