From dbf1bc83467636a84fad9bc37d0c75d6e85d06f4 Mon Sep 17 00:00:00 2001 From: MinhDV Date: Wed, 18 Oct 2023 14:38:44 +0700 Subject: [PATCH] TW-789 Can't open files for preview in android 13 --- lib/pages/chat/chat.dart | 17 +++++++---------- lib/utils/permission_service.dart | 4 ++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 35ac70ba0b..d259222981 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); } }); }); 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 ||