From ef6647a1ea9e3de1f1ca2f35450548d6e37ff16b Mon Sep 17 00:00:00 2001 From: liwei Date: Fri, 27 Dec 2024 10:18:49 +0800 Subject: [PATCH 1/2] feat: file tree view responsive support --- ui/flutter/lib/app/views/file_tree_view.dart | 100 ++++++++++--------- ui/flutter/pubspec.lock | 4 +- ui/flutter/pubspec.yaml | 2 +- 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/ui/flutter/lib/app/views/file_tree_view.dart b/ui/flutter/lib/app/views/file_tree_view.dart index 7d1bd4b07..354bc1a97 100644 --- a/ui/flutter/lib/app/views/file_tree_view.dart +++ b/ui/flutter/lib/app/views/file_tree_view.dart @@ -14,6 +14,7 @@ const _toggleSwitchIcons = [ Gopeed.file_audio, Gopeed.file_image, ]; +const _sizeGapWidth = 72.0; class FileTreeView extends StatefulWidget { final List files; @@ -50,7 +51,7 @@ class _FileTreeViewState extends State { final selectedFileCount = key.currentState?.getSelectedValues().where((e) => e != null).length ?? widget.files.length; - final selectdFileSize = calcSelectedSize(null); + final selectedFileSize = calcSelectedSize(null); return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -144,52 +145,59 @@ class _FileTreeViewState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ - InkWell( - onTap: () {}, - child: ToggleSwitch( - minHeight: 32, - cornerRadius: 8, - doubleTapDisable: true, - inactiveBgColor: Theme.of(context).dividerColor, - activeBgColor: [Theme.of(context).colorScheme.primary], - initialLabelIndex: toggleSwitchIndex, - icons: _toggleSwitchIcons, - onToggle: (index) { - toggleSwitchIndex = index; - if (index == null) { - key.currentState?.setSelectedValues(List.empty()); - return; - } + Flexible( + flex: 4, + child: InkWell( + onTap: () {}, + child: ToggleSwitch( + minHeight: 32, + cornerRadius: 8, + doubleTapDisable: true, + inactiveBgColor: Theme.of(context).dividerColor, + activeBgColor: [Theme.of(context).colorScheme.primary], + initialLabelIndex: toggleSwitchIndex, + icons: _toggleSwitchIcons, + onToggle: (index) { + toggleSwitchIndex = index; + if (index == null) { + key.currentState?.setSelectedValues(List.empty()); + return; + } - final iconFileExtArr = - iconConfigMap[_toggleSwitchIcons[index]] ?? []; - final selectedFileIndexes = widget.files - .asMap() - .entries - .where( - (e) => iconFileExtArr.contains(fileExt(e.value.name))) - .map((e) => e.key) - .toList(); - key.currentState?.setSelectedValues(selectedFileIndexes); - }, + final iconFileExtArr = + iconConfigMap[_toggleSwitchIcons[index]] ?? []; + final selectedFileIndexes = widget.files + .asMap() + .entries + .where((e) => + iconFileExtArr.contains(fileExt(e.value.name))) + .map((e) => e.key) + .toList(); + key.currentState?.setSelectedValues(selectedFileIndexes); + }, + ), ), ), - Row( - children: [ - Text('fileSelectedCount'.tr), - Text( - selectedFileCount.toString(), - style: Theme.of(context).textTheme.bodySmall, - ), - const SizedBox(width: 16), - Text('fileSelectedSize'.tr), - Text( - selectedFileCount > 0 && selectdFileSize == 0 - ? 'unknown'.tr - : Util.fmtByte(selectdFileSize), - style: Theme.of(context).textTheme.bodySmall, - ), - ], + Flexible( + flex: 6, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text('fileSelectedCount'.tr), + Text( + selectedFileCount.toString(), + style: Theme.of(context).textTheme.bodySmall, + ), + const SizedBox(width: 12), + Text('fileSelectedSize'.tr), + Text( + selectedFileCount > 0 && selectedFileSize == 0 + ? 'unknown'.tr + : Util.fmtByte(selectedFileSize), + style: Theme.of(context).textTheme.bodySmall, + ), + ], + ), ), ], ), @@ -241,7 +249,7 @@ class _FileTreeViewState extends State { return size > 0 ? Text(Util.fmtByte(calcSelectedSize(node)), style: Theme.of(context).textTheme.bodySmall) - : const SizedBox(); + : const SizedBox(width: _sizeGapWidth); }, children: [], ); @@ -265,7 +273,7 @@ class _FileTreeViewState extends State { return file.size > 0 ? Text(Util.fmtByte(file.size), style: Theme.of(context).textTheme.bodySmall) - : const SizedBox(); + : const SizedBox(width: _sizeGapWidth); }, isSelected: widget.initialValues.contains(i), children: [], diff --git a/ui/flutter/pubspec.lock b/ui/flutter/pubspec.lock index a0a719b9c..65efd339d 100644 --- a/ui/flutter/pubspec.lock +++ b/ui/flutter/pubspec.lock @@ -149,10 +149,10 @@ packages: dependency: "direct main" description: name: checkable_treeview - sha256: e38cf0a1088b803707a1f0b271ac46210108aac81c2dad506d0d56e7932ab690 + sha256: "3d7543e2c93a968864a57ca0666fc3b5827d89d13b22cb637a427596032f9272" url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" checked_yaml: dependency: transitive description: diff --git a/ui/flutter/pubspec.yaml b/ui/flutter/pubspec.yaml index 9ba4cb490..7d7891c59 100644 --- a/ui/flutter/pubspec.yaml +++ b/ui/flutter/pubspec.yaml @@ -68,7 +68,7 @@ dependencies: toggle_switch: ^2.3.0 permission_handler: ^11.3.1 device_info_plus: ^9.1.2 - checkable_treeview: ^1.3.0 + checkable_treeview: ^1.3.1 dependency_overrides: permission_handler_windows: git: From c269c9151ccdf916c7015701412d2611ebf191fa Mon Sep 17 00:00:00 2001 From: liwei Date: Fri, 27 Dec 2024 11:15:39 +0800 Subject: [PATCH 2/2] fix: torrent folder icon --- .../lib/app/modules/task/views/task_files_view.dart | 5 ++--- ui/flutter/lib/app/views/buid_task_list_view.dart | 8 +++++--- ui/flutter/lib/app/views/file_icon.dart | 5 +---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ui/flutter/lib/app/modules/task/views/task_files_view.dart b/ui/flutter/lib/app/modules/task/views/task_files_view.dart index 5dcde3336..8bccc6df2 100644 --- a/ui/flutter/lib/app/modules/task/views/task_files_view.dart +++ b/ui/flutter/lib/app/modules/task/views/task_files_view.dart @@ -64,9 +64,8 @@ class TaskFilesView extends GetView { [meta.opts.path, meta.res!.name, fileRelativePath]); final fileName = basename(filePath); return ListTile( - leading: file.isDirectory - ? const Icon(folderIcon) - : Icon(fileIcon(fileName)), + leading: + Icon(fileIcon(fileName, isFolder: file.isDirectory)), title: Text(fileName), subtitle: file.isDirectory ? Text('items'.trParams({ diff --git a/ui/flutter/lib/app/views/buid_task_list_view.dart b/ui/flutter/lib/app/views/buid_task_list_view.dart index 69b37d686..41b3ab927 100644 --- a/ui/flutter/lib/app/views/buid_task_list_view.dart +++ b/ui/flutter/lib/app/views/buid_task_list_view.dart @@ -183,9 +183,11 @@ class BuildTaskListView extends GetView { children: [ ListTile( title: Text(task.name), - leading: isFolderTask() - ? const Icon(folderIcon) - : Icon(fileIcon(task.name))), + leading: Icon( + fileIcon(task.name, + isFolder: isFolderTask(), + isBitTorrent: task.protocol == Protocol.bt), + )), Row( children: [ Expanded( diff --git a/ui/flutter/lib/app/views/file_icon.dart b/ui/flutter/lib/app/views/file_icon.dart index ea118c6e0..4a62edd86 100644 --- a/ui/flutter/lib/app/views/file_icon.dart +++ b/ui/flutter/lib/app/views/file_icon.dart @@ -52,9 +52,6 @@ final Map _iconCache = Map.fromEntries( ), ); -const folderIcon = Gopeed.folder; -const folderBtIcon = Gopeed.folder_bt; - String fileExt(String? name) { if (name == null) { return ''; @@ -71,7 +68,7 @@ String fileExt(String? name) { IconData fileIcon(String? name, {bool isFolder = false, bool isBitTorrent = false}) { if (isFolder) { - return isBitTorrent ? folderBtIcon : folderIcon; + return isBitTorrent ? Gopeed.folder_bt : Gopeed.folder; } final ext = fileExt(name);