Skip to content

Commit

Permalink
TW-789 Can't open files for preview in android 13
Browse files Browse the repository at this point in the history
  • Loading branch information
drminh2807 committed Oct 18, 2023
1 parent e488398 commit dbf1bc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -523,6 +524,9 @@ class ChatController extends State<Chat>

void onFileTappedMobile(Event event) async {
final permissionHandler = PermissionHandlerService();
if (await permissionHandler.noNeedStoragePermission()) {
return _handleDownloadFileForPreviewMobile(event: event);
}
final storagePermissionStatus =
await permissionHandler.storagePermissionStatus;
switch (storagePermissionStatus) {
Expand Down Expand Up @@ -597,23 +601,16 @@ class ChatController extends State<Chat>
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);
}
});
});
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/permission_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class PermissionHandlerService {
return (await _deviceInfoPlugin.androidInfo).version.sdkInt;
}

Future<bool> noNeedStoragePermission() async {
return Platform.isAndroid && (await _getCurrentAndroidVersion() >= 33);
}

Future<PermissionStatus> requestPermissionForCameraActions() async {
final currentStatus = await Permission.camera.status;
if (currentStatus == PermissionStatus.denied ||
Expand Down

0 comments on commit dbf1bc8

Please sign in to comment.