TF-3416 Handle download attachment in EML previewer on mobile
This commit is contained in:
@@ -10,4 +10,7 @@ class Constant {
|
||||
static const textVCardMimeType = 'text/x-vcard';
|
||||
static const textPlainMimeType = 'text/plain';
|
||||
static const emlMimeType = 'message/rfc822';
|
||||
static const mailtoScheme = 'mailto';
|
||||
static const attachmentScheme = 'attachment';
|
||||
static const emlPreviewerScheme = 'eml-previewer';
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:core/data/constants/constant.dart';
|
||||
import 'package:core/presentation/views/loading/cupertino_loading_widget.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/html/html_interaction.dart';
|
||||
import 'package:core/utils/html/html_utils.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:core/utils/preview_eml_file_utils.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
@@ -18,6 +18,7 @@ typedef OnScrollHorizontalEndAction = Function(bool leftDirection);
|
||||
typedef OnLoadWidthHtmlViewerAction = Function(bool isScrollPageViewActivated);
|
||||
typedef OnMailtoDelegateAction = Future<void> Function(Uri? uri);
|
||||
typedef OnPreviewEMLDelegateAction = Future<void> Function(Uri? uri);
|
||||
typedef OnDownloadAttachmentDelegateAction = Future<void> Function(Uri? uri);
|
||||
|
||||
class HtmlContentViewer extends StatefulWidget {
|
||||
|
||||
@@ -29,6 +30,7 @@ class HtmlContentViewer extends StatefulWidget {
|
||||
final OnMailtoDelegateAction? onMailtoDelegateAction;
|
||||
final OnScrollHorizontalEndAction? onScrollHorizontalEnd;
|
||||
final OnPreviewEMLDelegateAction? onPreviewEMLDelegateAction;
|
||||
final OnDownloadAttachmentDelegateAction? onDownloadAttachmentDelegateAction;
|
||||
|
||||
const HtmlContentViewer({
|
||||
Key? key,
|
||||
@@ -39,6 +41,7 @@ class HtmlContentViewer extends StatefulWidget {
|
||||
this.onMailtoDelegateAction,
|
||||
this.onScrollHorizontalEnd,
|
||||
this.onPreviewEMLDelegateAction,
|
||||
this.onDownloadAttachmentDelegateAction,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@@ -261,17 +264,23 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
|
||||
|
||||
final requestUri = Uri.parse(url);
|
||||
if (widget.onMailtoDelegateAction != null &&
|
||||
requestUri.isScheme('mailto')) {
|
||||
requestUri.isScheme(Constant.mailtoScheme)) {
|
||||
await widget.onMailtoDelegateAction?.call(requestUri);
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
|
||||
if (widget.onPreviewEMLDelegateAction != null &&
|
||||
requestUri.isScheme(PreviewEmlFileUtils.emlPreviewerScheme)) {
|
||||
requestUri.isScheme(Constant.emlPreviewerScheme)) {
|
||||
await widget.onPreviewEMLDelegateAction?.call(requestUri);
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
|
||||
if (widget.onDownloadAttachmentDelegateAction != null &&
|
||||
requestUri.isScheme(Constant.attachmentScheme)) {
|
||||
await widget.onDownloadAttachmentDelegateAction?.call(requestUri);
|
||||
return NavigationActionPolicy.CANCEL;
|
||||
}
|
||||
|
||||
if (await launcher.canLaunchUrl(Uri.parse(url))) {
|
||||
await launcher.launchUrl(
|
||||
Uri.parse(url),
|
||||
|
||||
@@ -7,8 +7,6 @@ import 'package:html/dom.dart';
|
||||
import 'package:html/parser.dart';
|
||||
|
||||
class PreviewEmlFileUtils {
|
||||
static const String emlPreviewerScheme = 'eml-previewer';
|
||||
|
||||
Element? _createEmailElement({
|
||||
required String subjectPrefix,
|
||||
required String fromPrefix,
|
||||
|
||||
Reference in New Issue
Block a user