diff --git a/lib/domain/model/preview_file/supported_preview_file_types.dart b/lib/domain/model/preview_file/supported_preview_file_types.dart index 18d280c924..4609d91c2d 100644 --- a/lib/domain/model/preview_file/supported_preview_file_types.dart +++ b/lib/domain/model/preview_file/supported_preview_file_types.dart @@ -29,6 +29,8 @@ class SupportedPreviewFileTypes { static const pdfMimeTypes = ['application/pdf', 'application/rtf']; + static const apkMimeTypes = ['application/vnd.android.package-archive']; + static const xlsMimeTypes = [ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.oasis.opendocument.spreadsheet', diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 35ac70ba0b..cf068d335c 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -32,6 +32,7 @@ import 'package:fluffychat/presentation/mixins/send_files_mixin.dart'; import 'package:fluffychat/presentation/model/forward/forward_argument.dart'; import 'package:fluffychat/utils/adaptive_bottom_sheet.dart'; import 'package:fluffychat/utils/clipboard.dart'; +import 'package:fluffychat/utils/dialog/twake_loading_dialog.dart'; import 'package:fluffychat/utils/extension/build_context_extension.dart'; import 'package:fluffychat/utils/extension/value_notifier_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; @@ -523,6 +524,9 @@ class ChatController extends State void onFileTappedMobile(Event event) async { final permissionHandler = PermissionHandlerService(); + if (await permissionHandler.noNeedStoragePermission()) { + return _handleDownloadFileForPreviewMobile(event: event); + } final storagePermissionStatus = await permissionHandler.storagePermissionStatus; switch (storagePermissionStatus) { @@ -597,23 +601,16 @@ class ChatController extends State if (failure is DownloadFileForPreviewFailure) { TwakeSnackBar.show(context, 'Error: ${failure.exception}'); } + TwakeLoadingDialog.hideLoadingDialog(context); }, (success) { if (success is DownloadFileForPreviewSuccess) { _openDownloadedFileForPreview( downloadFileForPreviewResponse: success.downloadFileForPreviewResponse, ); - Navigator.of(context).pop(); + TwakeLoadingDialog.hideLoadingDialog(context); } else if (success is DownloadFileForPreviewLoading) { - showDialog( - context: context, - useRootNavigator: false, - builder: (BuildContext context) { - return const Center( - child: CircularProgressIndicator(), - ); - }, - ); + TwakeLoadingDialog.showLoadingDialog(context); } }); }); @@ -623,6 +620,11 @@ class ChatController extends State required DownloadFileForPreviewResponse downloadFileForPreviewResponse, }) async { final mimeType = downloadFileForPreviewResponse.mimeType; + if (Platform.isAndroid && + SupportedPreviewFileTypes.apkMimeTypes.contains(mimeType)) { + await Share.shareXFiles([XFile(downloadFileForPreviewResponse.filePath)]); + return; + } final openResults = await OpenFile.open( downloadFileForPreviewResponse.filePath, type: mimeType, diff --git a/lib/utils/permission_service.dart b/lib/utils/permission_service.dart index 16043277c0..be9dcd0d65 100644 --- a/lib/utils/permission_service.dart +++ b/lib/utils/permission_service.dart @@ -31,6 +31,10 @@ class PermissionHandlerService { return (await _deviceInfoPlugin.androidInfo).version.sdkInt; } + Future noNeedStoragePermission() async { + return Platform.isAndroid && (await _getCurrentAndroidVersion() >= 33); + } + Future requestPermissionForCameraActions() async { final currentStatus = await Permission.camera.status; if (currentStatus == PermissionStatus.denied ||