mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 14:23:42 +00:00
feat: new ui (#1455)
This commit is contained in:
742 files changed
+59951
-5934
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../views/buid_task_list_view.dart';
|
||||
import '../controllers/task_downloaded_controller.dart';
|
||||
|
||||
class TaskDownloadedView extends GetView<TaskDownloadedController> {
|
||||
const TaskDownloadedView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BuildTaskListView(
|
||||
tasks: controller.tasks, selectedTaskIds: controller.selectedTaskIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../views/buid_task_list_view.dart';
|
||||
import '../controllers/task_downloading_controller.dart';
|
||||
|
||||
class TaskDownloadingView extends GetView<TaskDownloadingController> {
|
||||
const TaskDownloadingView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BuildTaskListView(
|
||||
tasks: controller.tasks, selectedTaskIds: controller.selectedTaskIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:open_filex/open_filex.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../../../api/api.dart' as api;
|
||||
import '../../../../util/browser_download/browser_download.dart';
|
||||
import '../../../../util/util.dart';
|
||||
import '../../../views/breadcrumb_view.dart';
|
||||
import '../../../views/file_icon.dart';
|
||||
import '../controllers/task_files_controller.dart';
|
||||
|
||||
class TaskFilesView extends GetView<TaskFilesController> {
|
||||
const TaskFilesView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Get.rootDelegate.popRoute()),
|
||||
// actions: [],
|
||||
title: Obx(() => Text(controller.task.value?.meta.res?.name ?? "")),
|
||||
),
|
||||
body: Obx(() {
|
||||
final fileList = controller.fileList;
|
||||
final breadcrumbItems = ["/"];
|
||||
if (fileList.isNotEmpty) {
|
||||
final file = fileList.first;
|
||||
final path = file.path.substring(1);
|
||||
if (path.isNotEmpty) {
|
||||
final pathArr = path.split("/");
|
||||
for (int i = 0; i < pathArr.length; i++) {
|
||||
breadcrumbItems.add(pathArr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
Breadcrumb(
|
||||
items: breadcrumbItems,
|
||||
onItemTap: (index) {
|
||||
final targetDirArr = <String>[];
|
||||
for (int i = 0; i <= index; i++) {
|
||||
targetDirArr.add(breadcrumbItems[i]);
|
||||
}
|
||||
controller
|
||||
.toDir(targetDirArr.join("/").replaceFirst('//', '/'));
|
||||
}).paddingOnly(left: 16, top: 16, bottom: 8),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
final meta = controller.task.value!.meta;
|
||||
final file = fileList[index];
|
||||
// if resource is single file, use opts.name as file name
|
||||
final realFileName = meta.res!.name.isEmpty
|
||||
? (meta.opts.name.isEmpty ? file.name : meta.opts.name)
|
||||
: "";
|
||||
final fileRelativePath = file.filePath(realFileName);
|
||||
final filePath = Util.safePathJoin(
|
||||
[meta.opts.path, meta.res!.name, fileRelativePath]);
|
||||
final fileName = basename(filePath);
|
||||
return ListTile(
|
||||
leading:
|
||||
Icon(fileIcon(fileName, isFolder: file.isDirectory)),
|
||||
title: Text(fileName),
|
||||
subtitle: file.isDirectory
|
||||
? Text('items'.trParams({
|
||||
'count': controller
|
||||
.dirItemCount(file.fullPath)
|
||||
.toString()
|
||||
}))
|
||||
: Text(Util.fmtByte(file.size)),
|
||||
trailing: file.isDirectory
|
||||
? null
|
||||
: SizedBox(
|
||||
width: 100,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: Util.isWeb()
|
||||
? () {
|
||||
final accessUrl = api.join(
|
||||
"/fs/tasks/${controller.task.value!.id}$fileRelativePath");
|
||||
return [
|
||||
IconButton(
|
||||
icon:
|
||||
const Icon(Icons.open_in_new),
|
||||
onPressed: () {
|
||||
launchUrl(Uri.parse(accessUrl),
|
||||
webOnlyWindowName:
|
||||
"_blank");
|
||||
}),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.download),
|
||||
onPressed: () {
|
||||
download(accessUrl, fileName);
|
||||
})
|
||||
];
|
||||
}()
|
||||
: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.open_in_new),
|
||||
onPressed: () async {
|
||||
await OpenFilex.open(filePath);
|
||||
}),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.share),
|
||||
onPressed: () {
|
||||
final xfile = XFile(filePath);
|
||||
Share.shareXFiles([xfile]);
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
if (file.isDirectory) {
|
||||
controller.toDir(file.fullPath);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: controller.fileList.length,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:open_filex/open_filex.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import '../../../../api/model/task.dart';
|
||||
import '../../../../util/file_explorer.dart';
|
||||
import '../../../../util/util.dart';
|
||||
import '../../../routes/app_pages.dart';
|
||||
import '../../../views/copy_button.dart';
|
||||
import '../controllers/task_controller.dart';
|
||||
import '../controllers/task_downloaded_controller.dart';
|
||||
import '../controllers/task_downloading_controller.dart';
|
||||
import 'task_downloaded_view.dart';
|
||||
import 'task_downloading_view.dart';
|
||||
|
||||
class TaskView extends GetView<TaskController> {
|
||||
const TaskView({Key? key}) : super(key: key);
|
||||
|
||||
String? _displayTaskUrl(Task? task) {
|
||||
final rawUrl = task?.meta.req.rawUrl;
|
||||
if (rawUrl != null && rawUrl.isNotEmpty) {
|
||||
return rawUrl;
|
||||
}
|
||||
return task?.meta.req.url;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final selectTask = controller.selectTask;
|
||||
|
||||
return DefaultTabController(
|
||||
length: 2,
|
||||
child: Scaffold(
|
||||
key: controller.scaffoldKey,
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(56),
|
||||
child: AppBar(
|
||||
bottom: TabBar(
|
||||
tabs: const [
|
||||
Tab(
|
||||
icon: Icon(Icons.file_download),
|
||||
),
|
||||
Tab(
|
||||
icon: Icon(Icons.done),
|
||||
),
|
||||
],
|
||||
onTap: (index) {
|
||||
if (controller.tabIndex.value != index) {
|
||||
controller.tabIndex.value = index;
|
||||
final downloadingController =
|
||||
Get.find<TaskDownloadingController>();
|
||||
final downloadedController =
|
||||
Get.find<TaskDownloadedController>();
|
||||
switch (index) {
|
||||
case 0:
|
||||
downloadingController.start();
|
||||
downloadedController.stop();
|
||||
break;
|
||||
case 1:
|
||||
downloadingController.stop();
|
||||
downloadedController.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
)),
|
||||
body: const TabBarView(
|
||||
children: [
|
||||
TaskDownloadingView(),
|
||||
TaskDownloadedView(),
|
||||
],
|
||||
),
|
||||
endDrawer: Drawer(
|
||||
// Add a ListView to the drawer. This ensures the user can scroll
|
||||
// through the options in the drawer if there isn't enough vertical
|
||||
// space to fit everything.
|
||||
child: Obx(() => ListView(
|
||||
// Important: Remove any padding from the ListView.
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).padding.top + 65,
|
||||
child: DrawerHeader(
|
||||
child: Text(
|
||||
'taskDetail'.tr,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
)),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('taskName'.tr),
|
||||
subtitle: buildTooltipSubtitle(selectTask.value?.name)),
|
||||
ListTile(
|
||||
title: Text('taskUrl'.tr),
|
||||
subtitle: buildTooltipSubtitle(_displayTaskUrl(selectTask.value)),
|
||||
trailing: CopyButton(_displayTaskUrl(selectTask.value)),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('downloadPath'.tr),
|
||||
subtitle:
|
||||
buildTooltipSubtitle(selectTask.value?.explorerUrl),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.folder_open),
|
||||
onPressed: () {
|
||||
selectTask.value?.explorer();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildTooltipSubtitle(String? text) {
|
||||
final showText = text ?? "";
|
||||
return Tooltip(
|
||||
message: showText,
|
||||
child: Text(
|
||||
showText,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension TaskEnhance on Task {
|
||||
bool get isFolder {
|
||||
return meta.res?.name.isNotEmpty ?? false;
|
||||
}
|
||||
|
||||
String get explorerUrl {
|
||||
return path.join(Util.safeDir(meta.opts.path), Util.safeDir(name));
|
||||
}
|
||||
|
||||
Future<void> explorer() async {
|
||||
if (Util.isDesktop()) {
|
||||
await FileExplorer.openAndSelectFile(explorerUrl);
|
||||
} else {
|
||||
Get.rootDelegate.toNamed(Routes.TASK_FILES, parameters: {'id': id});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> open() async {
|
||||
if (status != Status.done) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isFolder) {
|
||||
await explorer();
|
||||
} else {
|
||||
await OpenFilex.open(explorerUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user