TF-4058 Automatically save to storage when attachment export fails on mobile
This commit is contained in:
@@ -36,7 +36,6 @@ import 'package:model/error_type_handler/unknown_uri_exception.dart';
|
|||||||
import 'package:model/model.dart';
|
import 'package:model/model.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||||
import 'package:share_plus/share_plus.dart';
|
|
||||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
|
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
|
||||||
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_manager.dart';
|
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_manager.dart';
|
||||||
@@ -968,6 +967,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
logError('SingleEmailController::_exportAttachmentAction(): $e');
|
logError('SingleEmailController::_exportAttachmentAction(): $e');
|
||||||
consumeState(Stream.value(Left(ExportAttachmentFailure(e))));
|
consumeState(Stream.value(Left(ExportAttachmentFailure(e))));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
consumeState(Stream.value(Left(ExportAttachmentFailure(NotFoundAccountIdException()))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1034,35 +1035,35 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
|
|
||||||
void _exportAllAttachmentsSuccessAction(ExportAllAttachmentsSuccess success) {
|
void _exportAllAttachmentsSuccessAction(ExportAllAttachmentsSuccess success) {
|
||||||
popBack();
|
popBack();
|
||||||
_saveDownloadedZipAttachments(success.downloadedResponse.filePath);
|
_saveFileToStorage(success.downloadedResponse.filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openDownloadedPreviewWorkGroupDocument(DownloadedResponse downloadedResponse) async {
|
void _openDownloadedPreviewWorkGroupDocument(DownloadedResponse downloadedResponse) async {
|
||||||
log('SingleEmailController::_openDownloadedPreviewWorkGroupDocument(): $downloadedResponse');
|
log('SingleEmailController::_openDownloadedPreviewWorkGroupDocument(): $downloadedResponse');
|
||||||
if (downloadedResponse.mediaType == null) {
|
final filePath = downloadedResponse.filePath;
|
||||||
await Share.shareXFiles([XFile(downloadedResponse.filePath)]);
|
final mediaType = downloadedResponse.mediaType;
|
||||||
|
|
||||||
|
if (mediaType == null) {
|
||||||
|
_saveFileToStorage(filePath);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final openResult = await open_file.OpenFile.open(
|
final openResult = await open_file.OpenFile.open(
|
||||||
downloadedResponse.filePath,
|
filePath,
|
||||||
type: Platform.isAndroid ? downloadedResponse.mediaType!.mimeType : null,
|
type: Platform.isAndroid ? mediaType.mimeType : null,
|
||||||
// "xdg" is default value
|
// "xdg" is default value
|
||||||
linuxDesktopName: Platform.isIOS
|
linuxDesktopName: Platform.isIOS
|
||||||
? downloadedResponse.mediaType!.getDocumentUti().value ?? 'xdg'
|
? mediaType.getDocumentUti().value ?? 'xdg'
|
||||||
: 'xdg',
|
: 'xdg',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (openResult.type != open_file.ResultType.done) {
|
if (openResult.type != open_file.ResultType.done) {
|
||||||
logError('SingleEmailController::_openDownloadedPreviewWorkGroupDocument(): no preview available');
|
logError('SingleEmailController::_openDownloadedPreviewWorkGroupDocument(): no preview available');
|
||||||
if (currentOverlayContext != null && currentContext != null) {
|
_saveFileToStorage(filePath);
|
||||||
appToast.showToastErrorMessage(
|
|
||||||
currentOverlayContext!,
|
|
||||||
AppLocalizations.of(currentContext!).noPreviewAvailable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _saveDownloadedZipAttachments(String filePath) async {
|
Future<void> _saveFileToStorage(String filePath) async {
|
||||||
final params = SaveFileDialogParams(sourceFilePath: filePath);
|
final params = SaveFileDialogParams(sourceFilePath: filePath);
|
||||||
await FlutterFileDialog.saveFile(params: params);
|
await FlutterFileDialog.saveFile(params: params);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user