Handle some case about share intent from android phone

This commit is contained in:
Huy Nguyễn
2023-03-07 00:15:11 +07:00
committed by Dat Vu
parent abc9cebe3f
commit 1e0013260f
5 changed files with 52 additions and 8 deletions
@@ -110,12 +110,15 @@ class HomeController extends BaseController {
_emailReceiveManager.receivingSharingStream.listen((uri) { _emailReceiveManager.receivingSharingStream.listen((uri) {
log('HomeController::onReady(): Received Email: ${uri.toString()}'); log('HomeController::onReady(): Received Email: ${uri.toString()}');
if (uri != null) { if (uri != null) {
if(GetUtils.isEmail(uri.path)) { if (GetUtils.isEmail(uri.path)) {
log('HomeController::onReady(): Address: ${uri.path}'); log('HomeController::onReady(): Address: ${uri.path}');
_emailReceiveManager.setPendingEmailAddress(EmailAddress(null, uri.path)); _emailReceiveManager.setPendingEmailAddress(EmailAddress(null, uri.path));
} else { } else if (uri.scheme == "file") {
log('HomeController::onInit(): SharedMediaFilePath: ${uri.path}'); log('HomeController::onReady(): SharedMediaFilePath: ${uri.path}');
_emailReceiveManager.setPendingFileInfo([SharedMediaFile(uri.path, null, null, SharedMediaType.FILE)]); _emailReceiveManager.setPendingFileInfo([SharedMediaFile(uri.path, null, null, SharedMediaType.FILE)]);
} else {
log('HomeController::onReady(): EmailContent: ${uri.path}');
_emailReceiveManager.setPendingEmailContent(EmailContent(EmailContentType.textPlain, Uri.decodeComponent(uri.path)));
} }
} }
}); });
@@ -216,6 +216,7 @@ class MailboxDashBoardController extends ReloadableController {
@override @override
void onReady() { void onReady() {
_registerPendingEmailAddress(); _registerPendingEmailAddress();
_registerPendingEmailContents();
_registerPendingFileInfo(); _registerPendingFileInfo();
_getSessionCurrent(); _getSessionCurrent();
_getAppVersion(); _getAppVersion();
@@ -358,6 +359,21 @@ class MailboxDashBoardController extends ReloadableController {
}); });
} }
void _registerPendingEmailContents() {
_emailReceiveManagerStreamSubscription =
_emailReceiveManager.pendingEmailContentInfo.stream.listen((emailContent) {
log('MailboxDashBoardController::_registerPendingEmailContents(): ${emailContent?.content}');
if (emailContent != null && emailContent.content.isNotEmpty == true) {
_emailReceiveManager.clearPendingEmailContent();
final arguments = ComposerArguments(
emailActionType: EmailActionType.edit,
emailContents: [emailContent],
mailboxRole: selectedMailbox.value?.role);
goToComposer(arguments);
}
});
}
void _registerPendingFileInfo() { void _registerPendingFileInfo() {
_fileReceiveManagerStreamSubscription = _fileReceiveManagerStreamSubscription =
_emailReceiveManager.pendingFileInfo.stream.listen((listFile) { _emailReceiveManager.pendingFileInfo.stream.listen((listFile) {
+17
View File
@@ -1,5 +1,6 @@
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/email/email_content.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
@@ -8,6 +9,9 @@ class EmailReceiveManager {
BehaviorSubject<EmailAddress?> _pendingEmailAddressInfo = BehaviorSubject.seeded(null); BehaviorSubject<EmailAddress?> _pendingEmailAddressInfo = BehaviorSubject.seeded(null);
BehaviorSubject<EmailAddress?> get pendingEmailAddressInfo => _pendingEmailAddressInfo; BehaviorSubject<EmailAddress?> get pendingEmailAddressInfo => _pendingEmailAddressInfo;
BehaviorSubject<EmailContent?> _pendingEmailContentInfo = BehaviorSubject.seeded(null);
BehaviorSubject<EmailContent?> get pendingEmailContentInfo => _pendingEmailContentInfo;
BehaviorSubject<List<SharedMediaFile>> _pendingFileInfo = BehaviorSubject.seeded(List.empty(growable: true)); BehaviorSubject<List<SharedMediaFile>> _pendingFileInfo = BehaviorSubject.seeded(List.empty(growable: true));
BehaviorSubject<List<SharedMediaFile>> get pendingFileInfo => _pendingFileInfo; BehaviorSubject<List<SharedMediaFile>> get pendingFileInfo => _pendingFileInfo;
@@ -29,6 +33,19 @@ class EmailReceiveManager {
_pendingEmailAddressInfo.add(emailAddress); _pendingEmailAddressInfo.add(emailAddress);
} }
void setPendingEmailContent(EmailContent emailContent) async {
clearPendingEmailAddress();
_pendingEmailContentInfo.add(emailContent);
}
void clearPendingEmailContent() {
if(_pendingEmailContentInfo.isClosed) {
_pendingEmailContentInfo = BehaviorSubject.seeded(null);
} else {
_pendingEmailContentInfo.add(null);
}
}
void clearPendingEmailAddress() { void clearPendingEmailAddress() {
if(_pendingEmailAddressInfo.isClosed) { if(_pendingEmailAddressInfo.isClosed) {
_pendingEmailAddressInfo = BehaviorSubject.seeded(null); _pendingEmailAddressInfo = BehaviorSubject.seeded(null);
+11 -3
View File
@@ -1291,9 +1291,9 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
path: "." path: "."
ref: master ref: handle-share-for-vcard-and-mailto
resolved-ref: e1a945c3da610cdb0ec2788f1b89a96e3f0c6f32 resolved-ref: "48f12f2f2dca76fbfac39b31d638cacef6d1d95e"
url: "https://github.com/KasemJaffer/receive_sharing_intent.git" url: "https://github.com/nqhhdev/receive_sharing_intent.git"
source: git source: git
version: "1.4.5" version: "1.4.5"
rich_text_composer: rich_text_composer:
@@ -1480,10 +1480,18 @@ packages:
super_tag_editor: super_tag_editor:
dependency: "direct main" dependency: "direct main"
description: description:
<<<<<<< HEAD
name: super_tag_editor name: super_tag_editor
sha256: "381896629b7004b30079f485196b9f067340313e717b239506e0fcc893b667a7" sha256: "381896629b7004b30079f485196b9f067340313e717b239506e0fcc893b667a7"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
=======
path: "."
ref: master
resolved-ref: "1df7366f29940c68788de240aba114ebbc38bef8"
url: "https://github.com/dab246/super_tag_editor.git"
source: git
>>>>>>> 2c179930 (Handle some case about share intent from android phone)
version: "0.1.0" version: "0.1.0"
syncfusion_flutter_core: syncfusion_flutter_core:
dependency: transitive dependency: transitive
+2 -2
View File
@@ -68,8 +68,8 @@ dependencies:
receive_sharing_intent: receive_sharing_intent:
git: git:
url: https://github.com/KasemJaffer/receive_sharing_intent.git url: https://github.com/nqhhdev/receive_sharing_intent.git
ref: master ref: handle-share-for-vcard-and-mailto
flutter_appauth_web: flutter_appauth_web:
git: git: