TF-438 Handle trigger on resume app to refresh ui
This commit is contained in:
@@ -133,11 +133,11 @@ class SearchEmailByQueryAction extends DashBoardAction {
|
|||||||
List<Object?> get props => [navigationRouter];
|
List<Object?> get props => [navigationRouter];
|
||||||
}
|
}
|
||||||
|
|
||||||
class RefreshChangedEmailAction extends DashBoardAction {
|
class RefreshChangeEmailAction extends DashBoardAction {
|
||||||
|
|
||||||
final jmap.State? newState;
|
final jmap.State? newState;
|
||||||
|
|
||||||
RefreshChangedEmailAction(this.newState);
|
RefreshChangeEmailAction(this.newState);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [newState];
|
List<Object?> get props => [newState];
|
||||||
|
|||||||
+65
-10
@@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
|
import 'package:fcm/model/type_name.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
@@ -17,6 +18,7 @@ import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
|
|||||||
import 'package:model/model.dart';
|
import 'package:model/model.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||||
|
import 'package:rxdart/transformers.dart';
|
||||||
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
|
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
|
||||||
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
|
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_drafts_state.dart';
|
import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_drafts_state.dart';
|
||||||
@@ -53,6 +55,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller
|
|||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/composer_overlay_state.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/composer_overlay_state.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/refresh_action_view_event.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/quick_search_filter.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/quick_search_filter.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_vacation_state.dart';
|
import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_vacation_state.dart';
|
||||||
@@ -64,7 +67,11 @@ import 'package:tmail_ui_user/features/manage_account/presentation/extensions/va
|
|||||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/account_menu_item.dart';
|
import 'package:tmail_ui_user/features/manage_account/presentation/model/account_menu_item.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/manage_account_arguments.dart';
|
import 'package:tmail_ui_user/features/manage_account/presentation/model/manage_account_arguments.dart';
|
||||||
import 'package:tmail_ui_user/features/network_status_handle/presentation/network_connnection_controller.dart';
|
import 'package:tmail_ui_user/features/network_status_handle/presentation/network_connnection_controller.dart';
|
||||||
|
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart';
|
||||||
|
import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart';
|
||||||
|
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_controller.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_controller.dart';
|
||||||
|
import 'package:tmail_ui_user/features/push_notification/presentation/services/fcm_service.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart';
|
import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';
|
import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart';
|
import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart';
|
||||||
@@ -109,6 +116,8 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
|
|
||||||
GetAllVacationInteractor? _getAllVacationInteractor;
|
GetAllVacationInteractor? _getAllVacationInteractor;
|
||||||
UpdateVacationInteractor? _updateVacationInteractor;
|
UpdateVacationInteractor? _updateVacationInteractor;
|
||||||
|
GetEmailStateToRefreshInteractor? _getEmailStateToRefreshInteractor;
|
||||||
|
DeleteEmailStateToRefreshInteractor? _deleteEmailStateToRefreshInteractor;
|
||||||
|
|
||||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
final selectedMailbox = Rxn<PresentationMailbox>();
|
final selectedMailbox = Rxn<PresentationMailbox>();
|
||||||
@@ -141,6 +150,9 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
StreamController<Either<Failure, Success>>.broadcast();
|
StreamController<Either<Failure, Success>>.broadcast();
|
||||||
Stream<Either<Failure, Success>> get progressState => _progressStateController.stream;
|
Stream<Either<Failure, Success>> get progressState => _progressStateController.stream;
|
||||||
|
|
||||||
|
final StreamController<RefreshActionViewEvent> _refreshActionEventController =
|
||||||
|
StreamController<RefreshActionViewEvent>.broadcast();
|
||||||
|
|
||||||
MailboxDashBoardController(
|
MailboxDashBoardController(
|
||||||
LogoutOidcInteractor logoutOidcInteractor,
|
LogoutOidcInteractor logoutOidcInteractor,
|
||||||
DeleteAuthorityOidcInteractor deleteAuthorityOidcInteractor,
|
DeleteAuthorityOidcInteractor deleteAuthorityOidcInteractor,
|
||||||
@@ -162,7 +174,7 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
_registerProgressState();
|
_registerStreamListener();
|
||||||
super.onInit();
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,16 +215,25 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
@override
|
@override
|
||||||
void onData(Either<Failure, Success> newState) {
|
void onData(Either<Failure, Success> newState) {
|
||||||
super.onData(newState);
|
super.onData(newState);
|
||||||
viewState.value.map((success) {
|
viewState.value.fold(
|
||||||
if (success is SendingEmailState) {
|
(failure) {
|
||||||
if (currentOverlayContext != null && currentContext != null) {
|
log('MailboxDashBoardController::onData():failure $failure');
|
||||||
_appToast.showToastWithIcon(
|
},
|
||||||
currentOverlayContext!,
|
(success) {
|
||||||
message: AppLocalizations.of(currentContext!).your_email_being_sent,
|
log('MailboxDashBoardController::onData():success $success');
|
||||||
icon: _imagePaths.icSendToast);
|
if (success is SendingEmailState) {
|
||||||
|
if (currentOverlayContext != null && currentContext != null) {
|
||||||
|
_appToast.showToastWithIcon(
|
||||||
|
currentOverlayContext!,
|
||||||
|
message: AppLocalizations.of(currentContext!).your_email_being_sent,
|
||||||
|
icon: _imagePaths.icSendToast);
|
||||||
|
}
|
||||||
|
} else if (success is GetEmailStateToRefreshSuccess) {
|
||||||
|
dispatchAction(RefreshChangeEmailAction(success.storedState));
|
||||||
|
_deleteEmailStateToRefreshAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -314,10 +335,14 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _registerProgressState() async {
|
void _registerStreamListener() {
|
||||||
progressState.listen((state) {
|
progressState.listen((state) {
|
||||||
viewStateMarkAsReadMailbox.value = state;
|
viewStateMarkAsReadMailbox.value = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_refreshActionEventController.stream
|
||||||
|
.debounceTime(const Duration(milliseconds: FcmService.durationMessageComing))
|
||||||
|
.listen(_handleRefreshActionWhenBackToApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getUserProfile() async {
|
void _getUserProfile() async {
|
||||||
@@ -1252,12 +1277,42 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
return !searchController.isSearchEmailRunning && selectedMailbox.value != null && selectedMailbox.value!.isDrafts;
|
return !searchController.isSearchEmailRunning && selectedMailbox.value != null && selectedMailbox.value!.isDrafts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refreshActionWhenBackToApp() {
|
||||||
|
log('MailboxDashBoardController::refreshActionWhenBackToApp():');
|
||||||
|
_refreshActionEventController.add(RefreshActionViewEvent());
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleRefreshActionWhenBackToApp(RefreshActionViewEvent viewEvent) {
|
||||||
|
log('MailboxDashBoardController::_handleRefreshActionWhenBackToApp():');
|
||||||
|
try {
|
||||||
|
_getEmailStateToRefreshInteractor = Get.find<GetEmailStateToRefreshInteractor>();
|
||||||
|
} catch (e) {
|
||||||
|
logError('MailboxDashBoardController::_handleRefreshActionWhenBackToApp(): $e');
|
||||||
|
}
|
||||||
|
if (_getEmailStateToRefreshInteractor != null) {
|
||||||
|
consumeState(_getEmailStateToRefreshInteractor!.execute());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _deleteEmailStateToRefreshAction() {
|
||||||
|
log('MailboxDashBoardController::_deleteEmailStateToRefreshAction():');
|
||||||
|
try {
|
||||||
|
_deleteEmailStateToRefreshInteractor = Get.find<DeleteEmailStateToRefreshInteractor>();
|
||||||
|
} catch (e) {
|
||||||
|
logError('MailboxDashBoardController::_deleteEmailStateToRefreshAction(): $e');
|
||||||
|
}
|
||||||
|
if (_deleteEmailStateToRefreshInteractor != null) {
|
||||||
|
consumeState(_deleteEmailStateToRefreshInteractor!.execute(TypeName.emailType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
_emailReceiveManager.closeEmailReceiveManagerStream();
|
_emailReceiveManager.closeEmailReceiveManagerStream();
|
||||||
_emailReceiveManagerStreamSubscription.cancel();
|
_emailReceiveManagerStreamSubscription.cancel();
|
||||||
_fileReceiveManagerStreamSubscription.cancel();
|
_fileReceiveManagerStreamSubscription.cancel();
|
||||||
_progressStateController.close();
|
_progressStateController.close();
|
||||||
|
_refreshActionEventController.close();
|
||||||
Get.delete<DownloadController>();
|
Get.delete<DownloadController>();
|
||||||
FcmController.instance.dispose();
|
FcmController.instance.dispose();
|
||||||
super.onClose();
|
super.onClose();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||||
import 'package:core/presentation/views/responsive/responsive_widget.dart';
|
import 'package:core/presentation/views/responsive/responsive_widget.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:focus_detector/focus_detector.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/email_view.dart';
|
import 'package:tmail_ui_user/features/email/presentation/email_view.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/presentation/mailbox_view.dart';
|
import 'package:tmail_ui_user/features/mailbox/presentation/mailbox_view.dart';
|
||||||
@@ -25,55 +26,58 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return FocusDetector(
|
||||||
drawerEnableOpenDragGesture: responsiveUtils.hasLeftMenuDrawerActive(context),
|
onFocusGained: controller.refreshActionWhenBackToApp,
|
||||||
body: Stack(children: [
|
child: Scaffold(
|
||||||
Obx(() {
|
drawerEnableOpenDragGesture: responsiveUtils.hasLeftMenuDrawerActive(context),
|
||||||
switch(controller.dashboardRoute.value) {
|
body: Stack(children: [
|
||||||
case DashboardRoutes.thread:
|
Obx(() {
|
||||||
return ResponsiveWidget(
|
switch(controller.dashboardRoute.value) {
|
||||||
responsiveUtils: responsiveUtils,
|
case DashboardRoutes.thread:
|
||||||
desktop: controller.searchController.isSearchEmailRunning
|
return ResponsiveWidget(
|
||||||
? EmailView()
|
responsiveUtils: responsiveUtils,
|
||||||
: bodyLandscapeTablet,
|
desktop: controller.searchController.isSearchEmailRunning
|
||||||
tabletLarge: controller.searchController.isSearchEmailRunning
|
? EmailView()
|
||||||
? EmailView()
|
: bodyLandscapeTablet,
|
||||||
: bodyLandscapeTablet,
|
tabletLarge: controller.searchController.isSearchEmailRunning
|
||||||
landscapeTablet: controller.searchController.isSearchEmailRunning
|
? EmailView()
|
||||||
? EmailView()
|
: bodyLandscapeTablet,
|
||||||
: bodyLandscapeTablet,
|
landscapeTablet: controller.searchController.isSearchEmailRunning
|
||||||
mobile: _buildScaffoldHaveDrawer(body: ThreadView()));
|
? EmailView()
|
||||||
case DashboardRoutes.emailDetailed:
|
: bodyLandscapeTablet,
|
||||||
return ResponsiveWidget(
|
mobile: _buildScaffoldHaveDrawer(body: ThreadView()));
|
||||||
responsiveUtils: responsiveUtils,
|
case DashboardRoutes.emailDetailed:
|
||||||
desktop: controller.searchController.isSearchEmailRunning
|
return ResponsiveWidget(
|
||||||
? EmailView()
|
responsiveUtils: responsiveUtils,
|
||||||
: bodyLandscapeTablet,
|
desktop: controller.searchController.isSearchEmailRunning
|
||||||
tabletLarge: controller.searchController.isSearchEmailRunning
|
? EmailView()
|
||||||
? EmailView()
|
: bodyLandscapeTablet,
|
||||||
: bodyLandscapeTablet,
|
tabletLarge: controller.searchController.isSearchEmailRunning
|
||||||
landscapeTablet: controller.searchController.isSearchEmailRunning
|
? EmailView()
|
||||||
? EmailView()
|
: bodyLandscapeTablet,
|
||||||
: bodyLandscapeTablet,
|
landscapeTablet: controller.searchController.isSearchEmailRunning
|
||||||
mobile: EmailView());
|
? EmailView()
|
||||||
case DashboardRoutes.searchEmail:
|
: bodyLandscapeTablet,
|
||||||
return SafeArea(child: SearchEmailView());
|
mobile: EmailView());
|
||||||
default:
|
case DashboardRoutes.searchEmail:
|
||||||
return ResponsiveWidget(
|
return SafeArea(child: SearchEmailView());
|
||||||
responsiveUtils: responsiveUtils,
|
default:
|
||||||
desktop: controller.searchController.isSearchEmailRunning
|
return ResponsiveWidget(
|
||||||
? EmailView()
|
responsiveUtils: responsiveUtils,
|
||||||
: bodyLandscapeTablet,
|
desktop: controller.searchController.isSearchEmailRunning
|
||||||
tabletLarge: controller.searchController.isSearchEmailRunning
|
? EmailView()
|
||||||
? EmailView()
|
: bodyLandscapeTablet,
|
||||||
: bodyLandscapeTablet,
|
tabletLarge: controller.searchController.isSearchEmailRunning
|
||||||
landscapeTablet: controller.searchController.isSearchEmailRunning
|
? EmailView()
|
||||||
? EmailView()
|
: bodyLandscapeTablet,
|
||||||
: bodyLandscapeTablet,
|
landscapeTablet: controller.searchController.isSearchEmailRunning
|
||||||
mobile: _buildScaffoldHaveDrawer(body: ThreadView()));
|
? EmailView()
|
||||||
}
|
: bodyLandscapeTablet,
|
||||||
}),
|
mobile: _buildScaffoldHaveDrawer(body: ThreadView()));
|
||||||
]),
|
}
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import 'package:core/presentation/state/success.dart';
|
||||||
|
|
||||||
|
class RefreshActionViewEvent extends ViewEvent {
|
||||||
|
|
||||||
|
RefreshActionViewEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user