From eb446af438158c3661c2767d544c35f0cb94c6e4 Mon Sep 17 00:00:00 2001 From: Krille Date: Tue, 25 Feb 2025 17:11:29 +0100 Subject: [PATCH] chore: Follow up gallery picker --- lib/pages/chat/chat.dart | 30 +++++---------- lib/pages/chat/chat_input_row.dart | 16 +++++++- lib/utils/file_selector.dart | 62 ++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 22 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 9187a2dbe..23058cd26 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -522,8 +522,12 @@ class ChatController extends State }); } - void sendFileAction() async { - final files = await selectFiles(context, allowMultiple: true); + void sendFileAction({FileSelectorType type = FileSelectorType.any}) async { + final files = await selectFiles( + context, + allowMultiple: true, + type: type, + ); if (files.isEmpty) return; await showAdaptiveDialog( context: context, @@ -547,23 +551,6 @@ class ChatController extends State ); } - void sendImageAction() async { - final files = await ImagePicker().pickMultipleMedia( - imageQuality: null, - requestFullMetadata: false, - ); - if (files.isEmpty) return; - - await showAdaptiveDialog( - context: context, - builder: (c) => SendFileDialog( - files: files, - room: room, - outerContext: context, - ), - ); - } - void openCameraAction() async { // Make sure the textfield is unfocused before opening the camera FocusScope.of(context).requestFocus(FocusNode()); @@ -1139,7 +1126,10 @@ class ChatController extends State sendFileAction(); } if (choice == 'image') { - sendImageAction(); + sendFileAction(type: FileSelectorType.images); + } + if (choice == 'video') { + sendFileAction(type: FileSelectorType.videos); } if (choice == 'camera') { openCameraAction(); diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index 23f1d406c..88860a77e 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -143,9 +143,21 @@ class ChatInputRow extends StatelessWidget { leading: CircleAvatar( backgroundColor: theme.colorScheme.onPrimaryContainer, foregroundColor: theme.colorScheme.primaryContainer, - child: const Icon(Icons.photo_album_outlined), + child: const Icon(Icons.photo_outlined), ), - title: Text(L10n.of(context).openGallery), + title: Text(L10n.of(context).sendImage), + contentPadding: const EdgeInsets.all(0), + ), + ), + PopupMenuItem( + value: 'video', + child: ListTile( + leading: CircleAvatar( + backgroundColor: theme.colorScheme.onPrimaryContainer, + foregroundColor: theme.colorScheme.primaryContainer, + child: const Icon(Icons.video_camera_back_outlined), + ), + title: Text(L10n.of(context).sendVideo), contentPadding: const EdgeInsets.all(0), ), ), diff --git a/lib/utils/file_selector.dart b/lib/utils/file_selector.dart index 015eca533..8cc5e7552 100644 --- a/lib/utils/file_selector.dart +++ b/lib/utils/file_selector.dart @@ -62,10 +62,72 @@ enum FileSelectorType { label: 'WEBP', extensions: ['WebP', 'WEBP'], ), + XTypeGroup( + label: 'GIF', + extensions: ['gif', 'GIF'], + ), + XTypeGroup( + label: 'BMP', + extensions: ['bmp', 'BMP'], + ), + XTypeGroup( + label: 'TIFF', + extensions: ['tiff', 'TIFF', 'tif', 'TIF'], + ), + XTypeGroup( + label: 'HEIC', + extensions: ['heic', 'HEIC'], + ), + XTypeGroup( + label: 'SVG', + extensions: ['svg', 'SVG'], + ), ], FileType.image, null, ), + videos( + [ + XTypeGroup( + label: 'MP4', + extensions: ['mp4', 'MP4'], + ), + XTypeGroup( + label: 'AVI', + extensions: ['avi', 'AVI'], + ), + XTypeGroup( + label: 'MOV', + extensions: ['mov', 'MOV'], + ), + XTypeGroup( + label: 'MKV', + extensions: ['mkv', 'MKV'], + ), + XTypeGroup( + label: 'WMV', + extensions: ['wmv', 'WMV'], + ), + XTypeGroup( + label: 'FLV', + extensions: ['flv', 'FLV'], + ), + XTypeGroup( + label: 'MPEG', + extensions: ['mpeg', 'MPEG'], + ), + XTypeGroup( + label: '3GP', + extensions: ['3gp', '3GP'], + ), + XTypeGroup( + label: 'OGG', + extensions: ['ogg', 'OGG'], + ), + ], + FileType.video, + null, + ), zip( [ XTypeGroup(