From 0702ee98bce8e44279f7f09c6c11cf7e11c243c9 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 13 Mar 2025 18:32:10 +0530 Subject: [PATCH] [mob][photos] Ensure that the shared data received through the intent is a photo or video before showing a dialog specific to shared media --- mobile/lib/ui/tabs/home_widget.dart | 92 +++++++++++++++-------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/mobile/lib/ui/tabs/home_widget.dart b/mobile/lib/ui/tabs/home_widget.dart index dff167fb3e..4357297f4e 100644 --- a/mobile/lib/ui/tabs/home_widget.dart +++ b/mobile/lib/ui/tabs/home_widget.dart @@ -446,53 +446,57 @@ class _HomeWidgetState extends State { return; } - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - actions: [ - const SizedBox(height: 24), - ButtonWidget( - labelText: S.of(context).openFile, - buttonType: ButtonType.primary, - onTap: () async { - Navigator.of(context).pop(true); + if (value.isNotEmpty && + (value[0].mimeType == "image/*" || + value[0].mimeType == "video/*")) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + actions: [ + const SizedBox(height: 24), + ButtonWidget( + labelText: S.of(context).openFile, + buttonType: ButtonType.primary, + onTap: () async { + Navigator.of(context).pop(true); + }, + ), + const SizedBox( + height: 12, + ), + ButtonWidget( + buttonType: ButtonType.secondary, + labelText: S.of(context).backupFile, + onTap: () async { + Navigator.of(context).pop(false); + }, + ), + ], + ); + }, + ).then((shouldOpenFile) { + if (shouldOpenFile) { + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (_) { + return FileViewer( + sharedMediaFile: value[0], + ); }, ), - const SizedBox( - height: 12, - ), - ButtonWidget( - buttonType: ButtonType.secondary, - labelText: S.of(context).backupFile, - onTap: () async { - Navigator.of(context).pop(false); - }, - ), - ], - ); - }, - ).then((shouldOpenFile) { - if (shouldOpenFile) { - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (_) { - return FileViewer( - sharedMediaFile: value[0], - ); - }, - ), - ); - } else { - if (mounted) { - setState(() { - _shouldRenderCreateCollectionSheet = true; - _sharedFiles = value; - }); + ); + } else { + if (mounted) { + setState(() { + _shouldRenderCreateCollectionSheet = true; + _sharedFiles = value; + }); + } } - } - }); + }); + } }, onError: (err) { _logger.severe("getIntentDataStream error: $err");