Skip to content

Commit

Permalink
TW-1581: Preview unknown file instead of sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Mar 26, 2024
1 parent e8d8e50 commit 5ae20ba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/pages/chat/events/message_download_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class _MessageDownloadContentState extends State<MessageDownloadContent>
if (state is DownloadedPresentationState) {
return InkWell(
onTap: () async {
openDownloadedFileForPreview(
handleDownloadFileForPreviewSuccess(
filePath: state.filePath,
mimeType: widget.event.mimeType,
);
Expand Down
43 changes: 38 additions & 5 deletions lib/widgets/mixins/handle_download_and_preview_file_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mixin HandleDownloadAndPreviewFileMixin {
TwakeDialog.hideLoadingDialog(context);
}, (success) {
if (success is DownloadFileForPreviewSuccess) {
openDownloadedFileForPreview(
handleDownloadFileForPreviewSuccess(
filePath: success.downloadFileForPreviewResponse.filePath,
mimeType: success.downloadFileForPreviewResponse.mimeType,
);
Expand All @@ -154,12 +154,32 @@ mixin HandleDownloadAndPreviewFileMixin {
});
}

void openDownloadedFileForPreview({
void handleDownloadFileForPreviewSuccess({
required String filePath,
required String? mimeType,
}) {
if (PlatformInfos.isAndroid) {
_openDownloadedFileForPreviewAndroid(
filePath: filePath,
mimeType: mimeType,
);
return;
}

if (PlatformInfos.isIOS) {
_openDownloadedFileForPreviewIos(
filePath: filePath,
mimeType: mimeType,
);
return;
}
}

void _openDownloadedFileForPreviewAndroid({
required String filePath,
required String? mimeType,
}) async {
if (PlatformInfos.isAndroid &&
SupportedPreviewFileTypes.apkMimeTypes.contains(mimeType)) {
if (SupportedPreviewFileTypes.apkMimeTypes.contains(mimeType)) {
await Share.shareXFiles([XFile(filePath)]);
return;
}
Expand All @@ -170,7 +190,7 @@ mixin HandleDownloadAndPreviewFileMixin {
.value,
);
Logs().d(
'ChatController:_openDownloadedFileForPreview(): ${openResults.message}',
'ChatController:_openDownloadedFileForPreviewAndroid(): ${openResults.message}',
);

if (openResults.type != ResultType.done) {
Expand All @@ -179,6 +199,19 @@ mixin HandleDownloadAndPreviewFileMixin {
}
}

void _openDownloadedFileForPreviewIos({
required String filePath,
required String? mimeType,
}) async {
Logs().d(
'ChatController:_openDownloadedFileForPreviewIos(): $filePath',
);
await OpenFile.open(
filePath,
type: mimeType,
);
}

void previewPdfWeb(BuildContext context, Event event) async {
final pdf = await event.getFile(context);
if (pdf.result == null || event.sizeString != pdf.result?.sizeString) {
Expand Down

0 comments on commit 5ae20ba

Please sign in to comment.