Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-789 Can't open files for preview in android 13 #829

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
22 changes: 12 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 All @@ -623,6 +620,11 @@ class ChatController extends State<Chat>
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,
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