Skip to content

Commit

Permalink
TW-1586: change openFileMethod to have less param
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Mar 25, 2024
1 parent 080d661 commit 9b9c944
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/widgets/mixins/handle_download_and_preview_file_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/app_state/preview_file/download_file_for_preview_failure.dart';
import 'package:fluffychat/domain/app_state/preview_file/download_file_for_preview_loading.dart';
import 'package:fluffychat/domain/app_state/preview_file/download_file_for_preview_success.dart';
import 'package:fluffychat/domain/model/download_file/download_file_for_preview_response.dart';
import 'package:fluffychat/domain/model/preview_file/document_uti.dart';
import 'package:fluffychat/domain/model/preview_file/supported_preview_file_types.dart';
import 'package:fluffychat/domain/usecase/download_file_for_preview_interactor.dart';
Expand Down Expand Up @@ -40,7 +39,7 @@ mixin HandleDownloadAndPreviewFileMixin {
required Event event,
required BuildContext context,
}) {
return _handlePreviewWeb(event: event, context: context);
return handlePreviewWeb(event: event, context: context);
}

void onFileTappedMobile({
Expand Down Expand Up @@ -107,7 +106,7 @@ mixin HandleDownloadAndPreviewFileMixin {
}
}

void _handlePreviewWeb({
void handlePreviewWeb({
required Event event,
required BuildContext context,
}) async {
Expand Down Expand Up @@ -143,9 +142,9 @@ mixin HandleDownloadAndPreviewFileMixin {
TwakeDialog.hideLoadingDialog(context);
}, (success) {
if (success is DownloadFileForPreviewSuccess) {
_openDownloadedFileForPreview(
downloadFileForPreviewResponse:
success.downloadFileForPreviewResponse,
openDownloadedFileForPreview(
filePath: success.downloadFileForPreviewResponse.filePath,
mimeType: success.downloadFileForPreviewResponse.mimeType,
);
TwakeDialog.hideLoadingDialog(context);
} else if (success is DownloadFileForPreviewLoading) {
Expand All @@ -155,17 +154,17 @@ mixin HandleDownloadAndPreviewFileMixin {
});
}

void _openDownloadedFileForPreview({
required DownloadFileForPreviewResponse downloadFileForPreviewResponse,
void openDownloadedFileForPreview({
required String filePath,
required String? mimeType,
}) async {
final mimeType = downloadFileForPreviewResponse.mimeType;
if (PlatformInfos.isAndroid &&
SupportedPreviewFileTypes.apkMimeTypes.contains(mimeType)) {
await Share.shareXFiles([XFile(downloadFileForPreviewResponse.filePath)]);
await Share.shareXFiles([XFile(filePath)]);
return;
}
final openResults = await OpenFile.open(
downloadFileForPreviewResponse.filePath,
filePath,
type: mimeType,
uti: DocumentUti(SupportedPreviewFileTypes.iOSSupportedTypes[mimeType])
.value,
Expand All @@ -175,7 +174,7 @@ mixin HandleDownloadAndPreviewFileMixin {
);

if (openResults.type != ResultType.done) {
await Share.shareXFiles([XFile(downloadFileForPreviewResponse.filePath)]);
await Share.shareXFiles([XFile(filePath)]);
return;
}
}
Expand Down

0 comments on commit 9b9c944

Please sign in to comment.