TF-359 Open mailto link outside the Tmail app in mobile/tablet
This commit is contained in:
@@ -82,8 +82,7 @@ class EmailController extends BaseController {
|
||||
);
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
void onInit() {
|
||||
mailboxDashBoardController.selectedEmail.listen((presentationEmail) {
|
||||
log('EmailController::onReady(): ${presentationEmail.toString()}');
|
||||
if (_currentEmailId != presentationEmail?.id) {
|
||||
@@ -97,6 +96,7 @@ class EmailController extends BaseController {
|
||||
}
|
||||
}
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_email_cac
|
||||
import 'package:tmail_ui_user/features/home/presentation/home_controller.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/get_credential_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
|
||||
|
||||
class HomeBindings extends BaseBindings {
|
||||
|
||||
@@ -25,6 +26,7 @@ class HomeBindings extends BaseBindings {
|
||||
Get.find<DynamicUrlInterceptors>(),
|
||||
Get.find<AuthorizationInterceptors>(),
|
||||
Get.find<CleanupEmailCacheInteractor>(),
|
||||
Get.find<EmailReceiveManager>(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,32 +2,43 @@ import 'package:core/core.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/model/cleanup_rule.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_email_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/state/get_credential_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/get_credential_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
|
||||
|
||||
class HomeController extends GetxController {
|
||||
final GetCredentialInteractor _getCredentialInteractor;
|
||||
final DynamicUrlInterceptors _dynamicUrlInterceptors;
|
||||
final AuthorizationInterceptors _authorizationInterceptors;
|
||||
final CleanupEmailCacheInteractor _cleanupEmailCacheInteractor;
|
||||
final EmailReceiveManager _emailReceiveManager;
|
||||
|
||||
HomeController(
|
||||
this._getCredentialInteractor,
|
||||
this._dynamicUrlInterceptors,
|
||||
this._authorizationInterceptors,
|
||||
this._cleanupEmailCacheInteractor,
|
||||
this._emailReceiveManager,
|
||||
);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
log('HomeController::onInit(): ');
|
||||
if (!kIsWeb) {
|
||||
_initFlutterDownloader();
|
||||
_registerReceivingSharingIntent();
|
||||
}
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
if (!kIsWeb) {
|
||||
_initFlutterDownloader();
|
||||
}
|
||||
_cleanupEmailCache();
|
||||
}
|
||||
|
||||
@@ -51,6 +62,16 @@ class HomeController extends GetxController {
|
||||
(success) => success is GetCredentialViewState ? _goToMailbox(success) : _goToLogin()));
|
||||
}
|
||||
|
||||
void _registerReceivingSharingIntent() {
|
||||
_emailReceiveManager.receivingSharingStream.listen((uri) {
|
||||
log('HomeController::onReady(): Received Email: ${uri.toString()}');
|
||||
if (uri != null) {
|
||||
log('HomeController::onReady(): Address: ${uri.path}');
|
||||
_emailReceiveManager.setPendingEmailAddress(EmailAddress(null, uri.path));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _goToLogin() {
|
||||
pushAndPop(AppRoutes.LOGIN);
|
||||
}
|
||||
|
||||
@@ -104,15 +104,19 @@ class MailboxController extends BaseMailboxController {
|
||||
) : super(treeBuilder);
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
void onInit() {
|
||||
mailboxDashBoardController.accountId.listen((accountId) {
|
||||
log('MailboxController::onReady(): accountId: $accountId');
|
||||
if (accountId != null) {
|
||||
getAllMailboxAction(accountId);
|
||||
}
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
mailboxDashBoardController.viewState.listen((state) {
|
||||
state.fold(
|
||||
(failure) {
|
||||
|
||||
@@ -44,6 +44,7 @@ import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:tmail_ui_user/main/routes/router_arguments.dart';
|
||||
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
|
||||
|
||||
class MailboxDashBoardController extends ReloadableController {
|
||||
|
||||
@@ -55,6 +56,7 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
final CachingManager _cachingManager = Get.find<CachingManager>();
|
||||
final Connectivity _connectivity = Get.find<Connectivity>();
|
||||
final ResponsiveUtils _responsiveUtils = Get.find<ResponsiveUtils>();
|
||||
final EmailReceiveManager _emailReceiveManager = Get.find<EmailReceiveManager>();
|
||||
|
||||
final MoveToTrashInteractor _moveToTrashInteractor;
|
||||
final MoveToMailboxInteractor _moveToMailboxInteractor;
|
||||
@@ -79,6 +81,7 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
FocusNode searchFocus = FocusNode();
|
||||
RouterArguments? routerArguments;
|
||||
late StreamSubscription _connectivityStreamSubscription;
|
||||
late StreamSubscription _emailReceiveManagerStreamSubscription;
|
||||
|
||||
MailboxDashBoardController(
|
||||
this._moveToTrashInteractor,
|
||||
@@ -88,8 +91,9 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
_registerNetworkConnectivityState();
|
||||
_registerPendingEmailAddress();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -178,23 +182,36 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
});
|
||||
}
|
||||
|
||||
void _registerPendingEmailAddress() {
|
||||
_emailReceiveManagerStreamSubscription =
|
||||
_emailReceiveManager.pendingEmailAddressInfo.stream.listen((emailAddress) {
|
||||
log('MailboxDashBoardController::_registerPendingEmailAddress(): ${emailAddress?.email}');
|
||||
if (emailAddress != null && emailAddress.email?.isNotEmpty == true) {
|
||||
_emailReceiveManager.clearPendingEmailAddress();
|
||||
final arguments = ComposerArguments(
|
||||
emailActionType: EmailActionType.composeFromEmailAddress,
|
||||
emailAddress: emailAddress,
|
||||
mailboxRole: selectedMailbox.value?.role);
|
||||
goToComposer(arguments);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _getUserProfile() async {
|
||||
consumeState(_getUserProfileInteractor.execute());
|
||||
}
|
||||
|
||||
void _setSessionCurrent() {
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
final arguments = Get.arguments;
|
||||
log('MailboxDashBoardController::_setSessionCurrent(): arguments = $arguments');
|
||||
if (arguments is Session) {
|
||||
sessionCurrent = Get.arguments as Session;
|
||||
accountId.value = sessionCurrent?.accounts.keys.first;
|
||||
} else {
|
||||
if (kIsWeb) {
|
||||
reload();
|
||||
}
|
||||
final arguments = Get.arguments;
|
||||
log('MailboxDashBoardController::_setSessionCurrent(): arguments = $arguments');
|
||||
if (arguments is Session) {
|
||||
sessionCurrent = arguments;
|
||||
accountId.value = sessionCurrent?.accounts.keys.first;
|
||||
} else {
|
||||
if (kIsWeb) {
|
||||
reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initPackageInfo() async {
|
||||
@@ -393,6 +410,16 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
}
|
||||
}
|
||||
|
||||
void goToComposer(ComposerArguments arguments) {
|
||||
if (kIsWeb) {
|
||||
if (dashBoardAction != DashBoardAction.compose) {
|
||||
dispatchDashBoardAction(DashBoardAction.compose, arguments: arguments);
|
||||
}
|
||||
} else {
|
||||
push(AppRoutes.COMPOSER, arguments: arguments);
|
||||
}
|
||||
}
|
||||
|
||||
void _deleteCredential() async {
|
||||
await _deleteCredentialInteractor.execute();
|
||||
}
|
||||
@@ -409,6 +436,8 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
_emailReceiveManager.closeEmailReceiveManagerStream();
|
||||
_emailReceiveManagerStreamSubscription.cancel();
|
||||
_connectivityStreamSubscription.cancel();
|
||||
searchInputController.dispose();
|
||||
searchFocus.dispose();
|
||||
|
||||
@@ -127,12 +127,6 @@ class ThreadController extends BaseController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
dispatchState(Right(LoadingState()));
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
mailboxDashBoardController.selectedMailbox.listen((selectedMailbox) {
|
||||
if (_currentMailboxId != selectedMailbox?.id) {
|
||||
log('ThreadController::onReady(): selectMailbox: ${selectedMailbox?.name?.name}(${selectedMailbox?.id})');
|
||||
@@ -141,7 +135,13 @@ class ThreadController extends BaseController {
|
||||
_getAllEmail();
|
||||
}
|
||||
});
|
||||
super.onInit();
|
||||
dispatchState(Right(LoadingState()));
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
mailboxDashBoardController.viewState.listen((state) {
|
||||
state.map((success) {
|
||||
log('ThreadController::onReady(): ${success.runtimeType}');
|
||||
@@ -262,7 +262,6 @@ class ThreadController extends BaseController {
|
||||
canLoadMore = true;
|
||||
disableSearch();
|
||||
cancelSelectEmail();
|
||||
listEmailController.animateTo(0, duration: Duration(milliseconds: 500), curve: Curves.fastOutSlowIn);
|
||||
mailboxDashBoardController.dispatchRoute(AppRoutes.THREAD);
|
||||
}
|
||||
|
||||
@@ -270,6 +269,9 @@ class ThreadController extends BaseController {
|
||||
log('ThreadController::_getAllEmailSuccess(): ${success.emailList.length}');
|
||||
_currentEmailState = success.currentEmailState;
|
||||
emailList.value = success.emailList;
|
||||
if (listEmailController.hasClients) {
|
||||
listEmailController.animateTo(0, duration: Duration(milliseconds: 500), curve: Curves.fastOutSlowIn);
|
||||
}
|
||||
}
|
||||
|
||||
void _refreshChangesAllEmailSuccess(RefreshChangesAllEmailSuccess success) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
|
||||
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
|
||||
|
||||
class CoreBindings extends Bindings {
|
||||
|
||||
@@ -16,6 +17,7 @@ class CoreBindings extends Bindings {
|
||||
_bindingTransformer();
|
||||
_bindingToast();
|
||||
_bindingDeviceManager();
|
||||
_bindingReceivingSharingStream();
|
||||
}
|
||||
|
||||
void _bindingAppImagePaths() {
|
||||
@@ -47,4 +49,8 @@ class CoreBindings extends Bindings {
|
||||
Get.put(DeviceInfoPlugin());
|
||||
Get.put(DeviceManager(Get.find<DeviceInfoPlugin>()));
|
||||
}
|
||||
|
||||
void _bindingReceivingSharingStream() {
|
||||
Get.put(EmailReceiveManager());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
class EmailReceiveManager {
|
||||
|
||||
BehaviorSubject<EmailAddress?> _pendingEmailAddressInfo = BehaviorSubject.seeded(null);
|
||||
BehaviorSubject<EmailAddress?> get pendingEmailAddressInfo => _pendingEmailAddressInfo;
|
||||
|
||||
Stream<Uri?> get receivingSharingStream {
|
||||
return Rx.merge([
|
||||
Stream.fromFuture(ReceiveSharingIntent.getInitialTextAsUri()),
|
||||
ReceiveSharingIntent.getTextStreamAsUri()
|
||||
]);
|
||||
}
|
||||
Stream<List<SharedMediaFile>> get receivingSharingStream2 {
|
||||
return Rx.merge([
|
||||
Stream.fromFuture(ReceiveSharingIntent.getInitialMedia()),
|
||||
ReceiveSharingIntent.getMediaStream()
|
||||
]);
|
||||
}
|
||||
|
||||
void setPendingEmailAddress(EmailAddress emailAddress) async {
|
||||
clearPendingEmailAddress();
|
||||
_pendingEmailAddressInfo.add(emailAddress);
|
||||
}
|
||||
|
||||
void clearPendingEmailAddress() {
|
||||
if(_pendingEmailAddressInfo.isClosed) {
|
||||
_pendingEmailAddressInfo = BehaviorSubject.seeded(null);
|
||||
} else {
|
||||
_pendingEmailAddressInfo.add(null);
|
||||
}
|
||||
}
|
||||
|
||||
void closeEmailReceiveManagerStream() {
|
||||
_pendingEmailAddressInfo.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user