From aab4a37a7e7edf0c54bb82ecd27ba1fc57e2753e Mon Sep 17 00:00:00 2001 From: Levi Date: Sat, 21 Oct 2023 16:36:22 +0800 Subject: [PATCH] feat: adapt mobile extension list (#242) --- .../extension/views/extension_view.dart | 37 ++++++++++++++----- .../controllers/task_files_controller.dart | 6 +++ .../modules/task/views/task_files_view.dart | 11 ++++-- ui/flutter/lib/util/util.dart | 1 + 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/ui/flutter/lib/app/modules/extension/views/extension_view.dart b/ui/flutter/lib/app/modules/extension/views/extension_view.dart index 587d6d71d..2f7a3ad7f 100644 --- a/ui/flutter/lib/app/modules/extension/views/extension_view.dart +++ b/ui/flutter/lib/app/modules/extension/views/extension_view.dart @@ -21,6 +21,7 @@ import '../../../../api/model/install_extension.dart'; import '../../../../api/model/switch_extension.dart'; import '../../../../util/util.dart'; import '../../../views/icon_button_loading.dart'; +import '../../../views/responsive_builder.dart'; import '../controllers/extension_controller.dart'; class ExtensionView extends GetView { @@ -96,7 +97,7 @@ class ExtensionView extends GetView { itemBuilder: (context, index) { final extension = controller.extensions[index]; return SizedBox( - height: 112, + height: ResponsiveBuilder.isNarrow(context) ? 152 : 112, child: Card( elevation: 4.0, child: Column( @@ -145,23 +146,32 @@ class ExtensionView extends GetView { title: Row( children: () { final list = [ - Text(extension.title), + ResponsiveBuilder.isNarrow(context) + ? Expanded( + child: Text( + extension.title, + overflow: + TextOverflow.ellipsis, + ), + ) + : Text(extension.title), const SizedBox(width: 8), - Chip( - label: Text('v${extension.version}'), - ) + buildChip('v${extension.version}'), ]; if (extension.devMode) { list.add(const SizedBox(width: 8)); - list.add(Chip( - label: Text('dev'.tr), - backgroundColor: Colors.redAccent, - )); + list.add(buildChip('dev')); } return list; }(), ), - subtitle: Text(extension.description), + subtitle: ResponsiveBuilder.isNarrow(context) + ? Text( + extension.description, + maxLines: 2, + overflow: TextOverflow.ellipsis, + ) + : Text(extension.description), ), ), Row( @@ -233,6 +243,13 @@ class ExtensionView extends GetView { ); } + Widget buildChip(String text) { + return Chip( + padding: const EdgeInsets.all(0), + label: Text(text, style: const TextStyle(fontSize: 12)), + ); + } + Future _showSettingDialog(Extension extension) async { final formKey = GlobalKey(); final confrimController = RoundedLoadingButtonController(); diff --git a/ui/flutter/lib/app/modules/task/controllers/task_files_controller.dart b/ui/flutter/lib/app/modules/task/controllers/task_files_controller.dart index 0af0b5f49..3eadf2329 100644 --- a/ui/flutter/lib/app/modules/task/controllers/task_files_controller.dart +++ b/ui/flutter/lib/app/modules/task/controllers/task_files_controller.dart @@ -12,6 +12,12 @@ class FileItem { FileItem(this.isDirectory, this.path, this.name, this.size); String get fullPath => "${path == "/" ? path : "$path/"}$name"; + + String filePath(String optName) { + return optName.isEmpty + ? fullPath + : "${path == "/" ? path : "$path/"}$optName"; + } } class TaskFilesController extends GetxController { 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 dfefbd708..ed8c3421b 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 @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:open_file/open_file.dart'; +import 'package:path/path.dart'; import 'package:share_plus/share_plus.dart'; import '../../../../util/file_icon.dart'; @@ -52,13 +53,17 @@ class TaskFilesView extends GetView { itemBuilder: (context, index) { final meta = controller.task.value!.meta; final file = fileList[index]; - final filePath = Util.safePathJoin( - [meta.opts.path, meta.res!.name, file.fullPath]); + final filePath = Util.safePathJoin([ + meta.opts.path, + meta.res!.name, + file.filePath(meta.opts.name) + ]); + final fileName = basename(filePath); return ListTile( leading: file.isDirectory ? const Icon(Icons.folder) : Icon(FaIcons.allIcons[findIcon(file.name)]), - title: Text(fileList[index].name), + title: Text(fileName), subtitle: file.isDirectory ? Text('items'.trParams({ 'count': controller diff --git a/ui/flutter/lib/util/util.dart b/ui/flutter/lib/util/util.dart index 247a81f3c..8304dee3d 100644 --- a/ui/flutter/lib/util/util.dart +++ b/ui/flutter/lib/util/util.dart @@ -29,6 +29,7 @@ class Util { static String safePathJoin(List paths) { return paths + .where((e) => e.isNotEmpty) .map((e) => safeDir(e)) .join("/") .replaceAll(RegExp(r'//'), "/");