Skip to content

Commit

Permalink
feat: improve file select tree view (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Dec 25, 2024
1 parent edd189a commit a3f559c
Show file tree
Hide file tree
Showing 18 changed files with 651 additions and 3,151 deletions.
Binary file removed ui/flutter/assets/fonts/FontAwesome.ttf
Binary file not shown.
Binary file added ui/flutter/assets/fonts/Gopeed.ttf
Binary file not shown.
13 changes: 11 additions & 2 deletions ui/flutter/lib/app/modules/create/views/create_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:autoscale_tabbarview/autoscale_tabbarview.dart';
import 'package:checkable_treeview/checkable_treeview.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
Expand All @@ -16,10 +17,11 @@ import '../../../../database/database.dart';
import '../../../../util/input_formatter.dart';
import '../../../../util/message.dart';
import '../../../../util/util.dart';
import '../../../../util/extensions.dart';
import '../../../routes/app_pages.dart';
import '../../../views/compact_checkbox.dart';
import '../../../views/directory_selector.dart';
import '../../../views/file_list_view.dart';
import '../../../views/file_tree_view.dart';
import '../../app/controllers/app_controller.dart';
import '../../history/views/history_view.dart';
import '../controllers/create_controller.dart';
Expand All @@ -40,6 +42,7 @@ class CreateView extends GetView<CreateController> {
final _httpCookieController = TextEditingController();
final _httpRefererController = TextEditingController();
final _btTrackerController = TextEditingController();
final _fileTreeViewKey = GlobalKey<TreeViewState<int>>();

final _availableSchemes = ["http:", "https:", "magnet:"];

Expand Down Expand Up @@ -698,7 +701,13 @@ class CreateView extends GetView<CreateController> {
child: Form(
key: createFormKey,
autovalidateMode: AutovalidateMode.always,
child: FileListView(files: rr.res.files)),
child: FileTreeView(
files: rr.res.files,
initialValues: rr.res.files.asMap().keys.toList(),
onSelectionChanged: (List<int> values) {
controller.selectedIndexes.value = values;
},
)),
);
},
),
Expand Down
7 changes: 3 additions & 4 deletions ui/flutter/lib/app/modules/task/views/task_files_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import 'package:url_launcher/url_launcher.dart';

import '../../../../api/api.dart' as api;
import '../../../../util/browser_download/browser_download.dart';
import '../../../../util/file_icon.dart';
import '../../../../util/icons.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> {
Expand Down Expand Up @@ -66,8 +65,8 @@ class TaskFilesView extends GetView<TaskFilesController> {
final fileName = basename(filePath);
return ListTile(
leading: file.isDirectory
? const Icon(Icons.folder)
: Icon(FaIcons.allIcons[findIcon(fileName)]),
? const Icon(folderIcon)
: Icon(fileIcon(fileName)),
title: Text(fileName),
subtitle: file.isDirectory
? Text('items'.trParams({
Expand Down
7 changes: 3 additions & 4 deletions ui/flutter/lib/app/views/buid_task_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import 'package:styled_widget/styled_widget.dart';

import '../../api/api.dart';
import '../../api/model/task.dart';
import '../../util/file_icon.dart';
import '../../util/icons.dart';
import '../../util/message.dart';
import '../../util/util.dart';
import '../modules/app/controllers/app_controller.dart';
import '../modules/task/controllers/task_controller.dart';
import '../modules/task/views/task_view.dart';
import '../routes/app_pages.dart';
import 'file_icon.dart';

class BuildTaskListView extends GetView {
final List<Task> tasks;
Expand Down Expand Up @@ -185,8 +184,8 @@ class BuildTaskListView extends GetView {
ListTile(
title: Text(task.name),
leading: isFolderTask()
? const Icon(FaIcons.folder)
: Icon(FaIcons.allIcons[findIcon(task.name)])),
? const Icon(folderIcon)
: Icon(fileIcon(task.name))),
Row(
children: [
Expanded(
Expand Down
79 changes: 79 additions & 0 deletions ui/flutter/lib/app/views/file_icon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:flutter/material.dart';

import '../../icon/gopeed_icons.dart';

final Map<IconData, List<String>> iconConfigMap = {
Gopeed.install: ['exe', 'msi', 'dmg', 'deb', 'rpm'],
Gopeed.android: ['apk'],
Gopeed.app_store_ios: ['ipa'],
Gopeed.file_bt: ['torrent'],
Gopeed.cd: ['iso'],
Gopeed.html5: ['html', 'htm'],
Gopeed.file_alt: ['txt', 'md', 'log', 'csv', 'tsv', 'json', 'yaml', 'yml'],
Gopeed.file_pdf: ['pdf'],
Gopeed.file_word: ['doc', 'docx'],
Gopeed.file_excel: ['xls', 'xlsx'],
Gopeed.file_powerpoint: ['ppt', 'pptx'],
Gopeed.file_archive: ['zip', 'rar', '7z', 'tar', 'gz', 'bz2', 'xz'],
Gopeed.file_image: [
'jpg',
'jpeg',
'png',
'gif',
'bmp',
'tiff',
'svg',
'webp'
],
Gopeed.file_audio: ['mp3', 'wav', 'flac', 'aac', 'ogg', 'wma', 'm4a'],
Gopeed.file_video: ['mp4', 'avi', 'mkv', 'mov', 'wmv', 'flv', 'webm'],
Gopeed.file_code: [
'js',
'css',
'json',
'xml',
'java',
'cpp',
'dart',
'py',
'rb',
'php',
'ts',
'swift',
'go',
'rs'
],
Gopeed.file: [''],
};

final Map<String, IconData> _iconCache = Map.fromEntries(
iconConfigMap.entries.expand(
(entry) => entry.value.map((ext) => MapEntry(ext, entry.key)),
),
);

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

String fileExt(String? name) {
if (name == null) {
return '';
}

final ext = name.split('.').last;
if (ext.length > 8) {
return '';
}

return ext.toLowerCase();
}

IconData fileIcon(String? name,
{bool isFolder = false, bool isBitTorrent = false}) {
if (isFolder) {
return isBitTorrent ? folderBtIcon : folderIcon;
}

final ext = fileExt(name);
return _iconCache[ext] ?? Gopeed.file;
}
Loading

0 comments on commit a3f559c

Please sign in to comment.