2024-02-24 14:42:33 +08:00
|
|
|
|
import 'package:file_sizes/file_sizes.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:starcitizen_doctor/base/ui.dart';
|
|
|
|
|
import 'package:starcitizen_doctor/base/ui_model.dart';
|
2024-02-24 17:55:03 +08:00
|
|
|
|
import 'package:starcitizen_doctor/common/io/aria2c.dart';
|
2024-02-24 14:42:33 +08:00
|
|
|
|
|
2024-02-25 11:33:16 +08:00
|
|
|
|
import 'downloader_ui_model.dart';
|
2024-02-24 14:42:33 +08:00
|
|
|
|
|
2024-02-25 11:33:16 +08:00
|
|
|
|
class DownloaderUI extends BaseUI<DownloaderUIModel> {
|
2024-02-24 14:42:33 +08:00
|
|
|
|
final DateFormat formatter = DateFormat('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
@override
|
2024-02-25 11:33:16 +08:00
|
|
|
|
Widget? buildBody(BuildContext context, DownloaderUIModel model) {
|
2024-02-24 14:42:33 +08:00
|
|
|
|
return makeDefaultPage(context, model,
|
|
|
|
|
content: Column(
|
2024-02-24 17:55:03 +08:00
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-02-24 14:42:33 +08:00
|
|
|
|
children: [
|
|
|
|
|
const SizedBox(height: 12),
|
2024-02-24 14:57:52 +08:00
|
|
|
|
Row(
|
|
|
|
|
children: [
|
2024-02-24 17:10:28 +08:00
|
|
|
|
const Spacer(),
|
|
|
|
|
const SizedBox(width: 24),
|
2024-02-24 17:55:03 +08:00
|
|
|
|
const SizedBox(width: 12),
|
2024-02-24 14:57:52 +08:00
|
|
|
|
for (final item in <MapEntry<String, IconData>, String>{
|
2024-02-24 17:10:28 +08:00
|
|
|
|
const MapEntry("settings", FluentIcons.settings): "限速设置",
|
2024-02-24 14:57:52 +08:00
|
|
|
|
if (model.tasks.isNotEmpty)
|
2024-02-24 17:55:03 +08:00
|
|
|
|
const MapEntry("pause_all", FluentIcons.pause): "全部暂停",
|
|
|
|
|
if (model.waitingTasks.isNotEmpty)
|
2024-02-24 14:57:52 +08:00
|
|
|
|
const MapEntry("resume_all", FluentIcons.download): "恢复全部",
|
2024-02-24 17:55:03 +08:00
|
|
|
|
if (model.tasks.isNotEmpty || model.waitingTasks.isNotEmpty)
|
|
|
|
|
const MapEntry("cancel_all", FluentIcons.cancel): "全部取消",
|
2024-02-24 14:57:52 +08:00
|
|
|
|
}.entries)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 6, right: 6),
|
|
|
|
|
child: Button(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Icon(item.key.value),
|
|
|
|
|
const SizedBox(width: 6),
|
|
|
|
|
Text(item.value),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () => model.onTapButton(item.key.key)),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
],
|
|
|
|
|
),
|
2024-02-24 17:10:28 +08:00
|
|
|
|
if (model.getTasksLen() == 0)
|
|
|
|
|
const Expanded(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text("无下载任务"),
|
|
|
|
|
))
|
|
|
|
|
else
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
final (task, type, isFirstType) = model.getTaskAndType(index);
|
2024-02-25 11:33:16 +08:00
|
|
|
|
final nt = DownloaderUIModel.getTaskTypeAndName(task);
|
2024-02-24 17:10:28 +08:00
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
if (isFirstType)
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
left: 24,
|
|
|
|
|
right: 24,
|
|
|
|
|
top: index == 0 ? 0 : 12,
|
|
|
|
|
bottom: 12),
|
|
|
|
|
margin: const EdgeInsets.only(top: 6, bottom: 6),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"${model.listHeaderStatusMap[type]}",
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 24,
|
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
|
left: 12, right: 12, top: 12, bottom: 12),
|
|
|
|
|
margin: const EdgeInsets.only(
|
|
|
|
|
left: 12, right: 12, top: 6, bottom: 6),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: FluentTheme.of(context)
|
|
|
|
|
.cardColor
|
|
|
|
|
.withOpacity(.06),
|
|
|
|
|
borderRadius: BorderRadius.circular(7),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-02-24 14:42:33 +08:00
|
|
|
|
children: [
|
2024-02-24 17:10:28 +08:00
|
|
|
|
Text(
|
|
|
|
|
nt.value,
|
2024-02-24 14:42:33 +08:00
|
|
|
|
style: const TextStyle(
|
2024-02-24 17:10:28 +08:00
|
|
|
|
fontSize: 18,
|
2024-02-24 14:42:33 +08:00
|
|
|
|
fontWeight: FontWeight.bold),
|
2024-02-24 17:10:28 +08:00
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 6),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
2024-02-24 14:42:33 +08:00
|
|
|
|
Text(
|
2024-02-24 17:10:28 +08:00
|
|
|
|
"总大小:${FileSize.getSize(task.totalLength ?? 0)}",
|
2024-02-24 14:42:33 +08:00
|
|
|
|
style: const TextStyle(fontSize: 14),
|
|
|
|
|
),
|
2024-02-24 17:10:28 +08:00
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
if (nt.key == "torrent" &&
|
|
|
|
|
task.verifiedLength != null &&
|
|
|
|
|
task.verifiedLength != 0)
|
|
|
|
|
Text(
|
|
|
|
|
"校验中...(${FileSize.getSize(task.verifiedLength)})",
|
|
|
|
|
style: const TextStyle(fontSize: 14),
|
|
|
|
|
)
|
|
|
|
|
else if (task.status == "active")
|
|
|
|
|
Text(
|
2024-02-24 21:02:06 +08:00
|
|
|
|
"下载中... (${((task.completedLength ?? 0) * 100 / (task.totalLength ?? 1)).toStringAsFixed(4)}%)")
|
2024-02-24 17:10:28 +08:00
|
|
|
|
else
|
|
|
|
|
Text(
|
|
|
|
|
"状态:${model.statusMap[task.status]}",
|
|
|
|
|
style: const TextStyle(fontSize: 14),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 24),
|
|
|
|
|
if (task.status == "active" &&
|
|
|
|
|
task.verifiedLength == null)
|
|
|
|
|
Text(
|
|
|
|
|
"ETA: ${formatter.format(DateTime.now().add(Duration(seconds: model.getETA(task))))}"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const Spacer(),
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"已上传:${FileSize.getSize(task.uploadLength)}"),
|
|
|
|
|
Text(
|
|
|
|
|
"已下载:${FileSize.getSize(task.completedLength)}"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 18),
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"↑:${FileSize.getSize(task.uploadSpeed)}/s"),
|
|
|
|
|
Text(
|
|
|
|
|
"↓:${FileSize.getSize(task.downloadSpeed)}/s"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 32),
|
|
|
|
|
if (type != "stopped")
|
|
|
|
|
DropDownButton(
|
|
|
|
|
closeAfterClick: false,
|
|
|
|
|
title: const Padding(
|
|
|
|
|
padding: EdgeInsets.all(3),
|
|
|
|
|
child: Text('选项'),
|
|
|
|
|
),
|
|
|
|
|
items: [
|
|
|
|
|
if (task.status == "paused")
|
|
|
|
|
MenuFlyoutItem(
|
|
|
|
|
leading:
|
|
|
|
|
const Icon(FluentIcons.download),
|
|
|
|
|
text: const Text('继续下载'),
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
model.resumeTask(task.gid))
|
|
|
|
|
else if (task.status == "active")
|
|
|
|
|
MenuFlyoutItem(
|
|
|
|
|
leading: const Icon(FluentIcons.pause),
|
|
|
|
|
text: const Text('暂停下载'),
|
|
|
|
|
onPressed: () =>
|
|
|
|
|
model.pauseTask(task.gid)),
|
|
|
|
|
const MenuFlyoutSeparator(),
|
2024-02-24 14:42:33 +08:00
|
|
|
|
MenuFlyoutItem(
|
2024-02-24 17:10:28 +08:00
|
|
|
|
leading: const Icon(
|
|
|
|
|
FluentIcons.chrome_close,
|
|
|
|
|
size: 14,
|
|
|
|
|
),
|
|
|
|
|
text: const Text('取消下载'),
|
2024-02-24 14:42:33 +08:00
|
|
|
|
onPressed: () =>
|
2024-02-24 17:10:28 +08:00
|
|
|
|
model.cancelTask(task.gid)),
|
2024-02-24 14:42:33 +08:00
|
|
|
|
MenuFlyoutItem(
|
2024-02-24 17:10:28 +08:00
|
|
|
|
leading: const Icon(
|
|
|
|
|
FluentIcons.folder_open,
|
|
|
|
|
size: 14,
|
|
|
|
|
),
|
|
|
|
|
text: const Text('打开文件夹'),
|
|
|
|
|
onPressed: () => model.openFolder(task)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
],
|
|
|
|
|
),
|
2024-02-24 14:42:33 +08:00
|
|
|
|
),
|
2024-02-24 17:10:28 +08:00
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
itemCount: model.getTasksLen(),
|
2024-02-24 17:55:03 +08:00
|
|
|
|
)),
|
|
|
|
|
Container(
|
|
|
|
|
color: FluentTheme.of(context).cardColor.withOpacity(.06),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 12, bottom: 3, top: 3),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
width: 8,
|
|
|
|
|
height: 8,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Aria2cManager.isAvailable
|
|
|
|
|
? Colors.green
|
|
|
|
|
: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(1000),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Text(
|
|
|
|
|
"下载: ${FileSize.getSize(model.globalStat?.downloadSpeed ?? 0)}/s 上传:${FileSize.getSize(model.globalStat?.uploadSpeed ?? 0)}/s",
|
|
|
|
|
style: const TextStyle(fontSize: 12),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2024-02-24 14:42:33 +08:00
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2024-02-25 11:33:16 +08:00
|
|
|
|
String getUITitle(BuildContext context, DownloaderUIModel model) => "下载管理";
|
2024-02-24 14:42:33 +08:00
|
|
|
|
}
|