From 6e224cf11c9581f9db7ffa579658ab1f0a3f5718 Mon Sep 17 00:00:00 2001 From: S1m Date: Wed, 22 Dec 2021 08:45:36 +0000 Subject: [PATCH] feat: Add button to record a video on Android --- assets/l10n/intl_en.arb | 5 +++++ lib/pages/chat/chat.dart | 22 ++++++++++++++++++++++ lib/pages/chat/chat_input_row.dart | 13 +++++++++++++ 3 files changed, 40 insertions(+) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index fa907b97..36221a20 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -1596,6 +1596,11 @@ "type": "text", "placeholders": {} }, + "openVideoCamera": "Open camera for a video", + "@openVideoCamera": { + "type": "text", + "placeholders": {} + }, "oneClientLoggedOut": "One of your clients has been logged out", "@oneClientLoggedOut": {}, "addAccount": "Add account", diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 2620dddf..d6cd819e 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -347,6 +347,25 @@ class ChatController extends State { ); } + void openVideoCameraAction() async { + // Make sure the textfield is unfocused before opening the camera + FocusScope.of(context).requestFocus(FocusNode()); + final file = await ImagePicker().pickVideo(source: ImageSource.camera); + if (file == null) return; + final bytes = await file.readAsBytes(); + await showDialog( + context: context, + useRootNavigator: false, + builder: (c) => SendFileDialog( + file: MatrixVideoFile( + bytes: bytes, + name: file.path, + ), + room: room, + ), + ); + } + void sendStickerAction() async { final sticker = await showModalBottomSheet( context: context, @@ -764,6 +783,9 @@ class ChatController extends State { if (choice == 'camera') { openCameraAction(); } + if (choice == 'camera-video') { + openVideoCameraAction(); + } if (choice == 'sticker') { sendStickerAction(); } diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index deadcfb9..62c751ef 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -129,6 +129,19 @@ class ChatInputRow extends StatelessWidget { contentPadding: const EdgeInsets.all(0), ), ), + if (PlatformInfos.isMobile) + PopupMenuItem( + value: 'camera-video', + child: ListTile( + leading: const CircleAvatar( + backgroundColor: Colors.red, + foregroundColor: Colors.white, + child: Icon(Icons.videocam_outlined), + ), + title: Text(L10n.of(context).openVideoCamera), + contentPadding: const EdgeInsets.all(0), + ), + ), if (controller.room .getImagePacks(ImagePackUsage.sticker) .isNotEmpty)