Skip to content

Commit

Permalink
feat: file tree view responsive support (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Dec 27, 2024
1 parent f5891ee commit 727b7ed
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 59 deletions.
5 changes: 2 additions & 3 deletions ui/flutter/lib/app/modules/task/views/task_files_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ class TaskFilesView extends GetView<TaskFilesController> {
[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({
Expand Down
8 changes: 5 additions & 3 deletions ui/flutter/lib/app/views/buid_task_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions ui/flutter/lib/app/views/file_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ final Map<String, IconData> _iconCache = Map.fromEntries(
),
);

const folderIcon = Gopeed.folder;
const folderBtIcon = Gopeed.folder_bt;

String fileExt(String? name) {
if (name == null) {
return '';
Expand All @@ -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);
Expand Down
100 changes: 54 additions & 46 deletions ui/flutter/lib/app/views/file_tree_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const _toggleSwitchIcons = [
Gopeed.file_audio,
Gopeed.file_image,
];
const _sizeGapWidth = 72.0;

class FileTreeView extends StatefulWidget {
final List<FileInfo> files;
Expand Down Expand Up @@ -50,7 +51,7 @@ class _FileTreeViewState extends State<FileTreeView> {
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,
Expand Down Expand Up @@ -144,52 +145,59 @@ class _FileTreeViewState extends State<FileTreeView> {
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,
),
],
),
),
],
),
Expand Down Expand Up @@ -241,7 +249,7 @@ class _FileTreeViewState extends State<FileTreeView> {
return size > 0
? Text(Util.fmtByte(calcSelectedSize(node)),
style: Theme.of(context).textTheme.bodySmall)
: const SizedBox();
: const SizedBox(width: _sizeGapWidth);
},
children: [],
);
Expand All @@ -265,7 +273,7 @@ class _FileTreeViewState extends State<FileTreeView> {
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: [],
Expand Down
4 changes: 2 additions & 2 deletions ui/flutter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ui/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 727b7ed

Please sign in to comment.