Skip to content

Commit

Permalink
TF-2431 Show confirm dialog when logout
Browse files Browse the repository at this point in the history
Signed-off-by: dab246 <[email protected]>
  • Loading branch information
dab246 committed Jan 16, 2024
1 parent 176ba6d commit a422ef4
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 104 deletions.
1 change: 0 additions & 1 deletion core/lib/presentation/utils/theme_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class ThemeUtils {
fontSize: 28
),
bodyLarge: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 17
),
bodyMedium: TextStyle(
Expand Down
20 changes: 10 additions & 10 deletions core/lib/presentation/views/dialog/confirmation_dialog_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class ConfirmDialogBuilder {
TextStyle? _styleContent;
double? _radiusButton;
double? heightButton;
EdgeInsets? _paddingTitle;
EdgeInsets? _paddingContent;
EdgeInsets? _paddingButton;
EdgeInsetsGeometry? _paddingTitle;
EdgeInsetsGeometry? _paddingContent;
EdgeInsetsGeometry? _paddingButton;
EdgeInsets? _outsideDialogPadding;
EdgeInsets? _marginIcon;
EdgeInsets? _margin;
EdgeInsetsGeometry? _marginIcon;
EdgeInsetsGeometry? _margin;
double? _widthDialog;
double? _heightDialog;
double maxWith;
Expand Down Expand Up @@ -95,23 +95,23 @@ class ConfirmDialogBuilder {
_radiusButton = radius;
}

void paddingTitle(EdgeInsets? value) {
void paddingTitle(EdgeInsetsGeometry? value) {
_paddingTitle = value;
}

void paddingContent(EdgeInsets? value) {
void paddingContent(EdgeInsetsGeometry? value) {
_paddingContent = value;
}

void paddingButton(EdgeInsets? value) {
void paddingButton(EdgeInsetsGeometry? value) {
_paddingButton = value;
}

void marginIcon(EdgeInsets? value) {
void marginIcon(EdgeInsetsGeometry? value) {
_marginIcon = value;
}

void margin(EdgeInsets? value) {
void margin(EdgeInsetsGeometry? value) {
_margin = value;
}

Expand Down
58 changes: 57 additions & 1 deletion lib/features/base/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/account/authentication_type.dart';
import 'package:model/account/personal_account.dart';
import 'package:rule_filter/rule_filter/capability_rule_filter.dart';
Expand Down Expand Up @@ -296,11 +297,66 @@ abstract class BaseController extends GetxController
}

void logout({
required BuildContext context,
required Session session,
required AccountId accountId
}) async {
_isFcmEnabled = _isFcmActivated(session, accountId);
consumeState(_logoutCurrentAccountInteractor.execute());

if (PlatformInfo.isMobile) {
_showConfirmDialogLogout(
context: context,
userName: session.username
);
} else {
consumeState(_logoutCurrentAccountInteractor.execute());
}
}

void _showConfirmDialogLogout({
required BuildContext context,
required UserName userName
}) {
showConfirmDialogAction(
context: context,
actionName: AppLocalizations.of(currentContext!).yesLogout,
title: AppLocalizations.of(currentContext!).logoutConfirmation,
alignCenter: true,
titlePadding: const EdgeInsetsDirectional.only(top: 24),
messageStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
color: AppColor.colorTextBody,
fontSize: 15
),
titleStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20
),
actionButtonColor: AppColor.primaryColor,
actionStyle: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.white,
fontSize: 16
),
cancelStyle: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: AppColor.primaryColor,
fontSize: 16
),
listTextSpan: [
TextSpan(text: AppLocalizations.of(context).messageConfirmationLogout),
TextSpan(
text: ' ${userName.value}',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: AppColor.colorTextBody,
fontWeight: FontWeight.bold,
fontSize: 15
),
),
const TextSpan(text: '?'),
],
onConfirmAction: () {
consumeState(_logoutCurrentAccountInteractor.execute());
},
);
}

void _removeFirebaseRegistration(PersonalAccount deletedAccount) async {
Expand Down
75 changes: 37 additions & 38 deletions lib/features/base/mixin/message_dialog_action_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';

mixin MessageDialogActionMixin {

Future<dynamic> showConfirmDialogAction(
BuildContext context,
String message,
String actionName,
{
Function? onConfirmAction,
Function? onCancelAction,
String? title,
String? cancelTitle,
bool hasCancelButton = true,
bool showAsBottomSheet = false,
bool alignCenter = false,
List<TextSpan>? listTextSpan,
Widget? icon,
TextStyle? titleStyle,
TextStyle? messageStyle,
TextStyle? actionStyle,
TextStyle? cancelStyle,
Color? actionButtonColor,
Color? cancelButtonColor,
}
) async {
Future<dynamic> showConfirmDialogAction({
required BuildContext context,
String? message,
String? actionName,
Function? onConfirmAction,
Function? onCancelAction,
String? title,
String? cancelTitle,
bool hasCancelButton = true,
bool showAsBottomSheet = false,
bool alignCenter = false,
List<TextSpan>? listTextSpan,
Widget? icon,
TextStyle? titleStyle,
TextStyle? messageStyle,
TextStyle? actionStyle,
TextStyle? cancelStyle,
Color? actionButtonColor,
Color? cancelButtonColor,
EdgeInsetsGeometry? titlePadding,
}) async {
final responsiveUtils = Get.find<ResponsiveUtils>();
final imagePaths = Get.find<ImagePaths>();

Expand All @@ -39,20 +38,20 @@ mixin MessageDialogActionMixin {
child: (ConfirmDialogBuilder(imagePaths, listTextSpan: listTextSpan, heightButton: 44)
..key(const Key('confirm_dialog_action'))
..title(title ?? '')
..content(message)
..content(message ?? '')
..addIcon(icon)
..colorConfirmButton(actionButtonColor ?? AppColor.colorTextButton)
..colorCancelButton(cancelButtonColor ?? AppColor.colorCancelButton)
..marginIcon(icon != null ? const EdgeInsets.only(top: 24) : null)
..paddingTitle(icon != null ? const EdgeInsets.only(top: 24) : EdgeInsets.zero)
..paddingTitle(icon != null ? const EdgeInsets.only(top: 24) : titlePadding ?? EdgeInsets.zero)
..radiusButton(12)
..paddingContent(const EdgeInsets.only(left: 24, right: 24, bottom: 24, top: 12))
..paddingButton(hasCancelButton ? null : const EdgeInsets.only(bottom: 24, left: 24, right: 24))
..paddingContent(const EdgeInsetsDirectional.only(start: 24, end: 24, bottom: 24, top: 12))
..paddingButton(hasCancelButton ? null : const EdgeInsetsDirectional.only(bottom: 24, start: 24, end: 24))
..styleTitle(titleStyle ?? const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black))
..styleContent(messageStyle ?? const TextStyle(fontSize: 14, fontWeight: FontWeight.normal, color: AppColor.colorContentEmail))
..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton))
..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white))
..onConfirmButtonAction(actionName, () {
..onConfirmButtonAction(actionName ?? AppLocalizations.of(context).yes, () {
popBack();
onConfirmAction?.call();
})
Expand Down Expand Up @@ -80,21 +79,21 @@ mixin MessageDialogActionMixin {
)
..key(const Key('confirm_dialog_action'))
..title(title ?? '')
..content(message)
..content(message ?? '')
..addIcon(icon)
..margin(const EdgeInsets.only(bottom: 42))
..widthDialog(responsiveUtils.getSizeScreenWidth(context))
..colorConfirmButton(actionButtonColor ?? AppColor.colorTextButton)
..colorCancelButton(cancelButtonColor ?? AppColor.colorCancelButton)
..paddingTitle(icon != null ? const EdgeInsets.only(top: 24) : EdgeInsets.zero)
..paddingTitle(icon != null ? const EdgeInsets.only(top: 24) : titlePadding ?? EdgeInsets.zero)
..marginIcon(EdgeInsets.zero)
..paddingContent(const EdgeInsets.only(left: 44, right: 44, bottom: 24, top: 12))
..paddingButton(hasCancelButton ? null : const EdgeInsets.only(bottom: 16, left: 44, right: 44))
..paddingContent(const EdgeInsetsDirectional.only(start: 44, end: 44, bottom: 24, top: 12))
..paddingButton(hasCancelButton ? null : const EdgeInsetsDirectional.only(bottom: 16, start: 44, end: 44))
..styleTitle(titleStyle ?? const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black))
..styleContent(messageStyle ?? const TextStyle(fontSize: 14, fontWeight: FontWeight.normal, color: AppColor.colorContentEmail))
..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton))
..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white))
..onConfirmButtonAction(actionName, () {
..onConfirmButtonAction(actionName ?? AppLocalizations.of(context).yes, () {
popBack();
onConfirmAction?.call();
})
Expand All @@ -117,7 +116,7 @@ mixin MessageDialogActionMixin {
);
} else {
return (ConfirmationDialogActionSheetBuilder(context, listTextSpan: listTextSpan)
..messageText(message)
..messageText(message ?? '')
..styleConfirmButton(const TextStyle(fontSize: 20, fontWeight: FontWeight.normal, color: Colors.black))
..styleMessage(messageStyle)
..styleCancelButton(cancelStyle)
Expand All @@ -128,7 +127,7 @@ mixin MessageDialogActionMixin {
onCancelAction?.call();
}
)
..onConfirmAction(actionName, () {
..onConfirmAction(actionName ?? AppLocalizations.of(context).yes, () {
popBack();
onConfirmAction?.call();
})).show();
Expand All @@ -139,20 +138,20 @@ mixin MessageDialogActionMixin {
child: (ConfirmDialogBuilder(imagePaths, listTextSpan: listTextSpan)
..key(const Key('confirm_dialog_action'))
..title(title ?? '')
..content(message)
..content(message ?? '')
..addIcon(icon)
..colorConfirmButton(actionButtonColor ?? AppColor.colorTextButton)
..colorCancelButton(cancelButtonColor ?? AppColor.colorCancelButton)
..marginIcon(icon != null ? const EdgeInsets.only(top: 24) : null)
..paddingTitle(icon != null ? const EdgeInsets.only(top: 24) : EdgeInsets.zero)
..paddingTitle(icon != null ? const EdgeInsets.only(top: 24) : titlePadding ?? EdgeInsets.zero)
..marginIcon(EdgeInsets.zero)
..paddingContent(const EdgeInsets.only(left: 44, right: 44, bottom: 24, top: 12))
..paddingContent(const EdgeInsetsDirectional.only(start: 44, end: 44, bottom: 24, top: 12))
..paddingButton(hasCancelButton ? null : const EdgeInsets.only(bottom: 16, left: 44, right: 44))
..styleTitle(titleStyle ?? const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black))
..styleContent(messageStyle ?? const TextStyle(fontSize: 14, fontWeight: FontWeight.normal, color: AppColor.colorContentEmail))
..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton))
..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white))
..onConfirmButtonAction(actionName, () {
..onConfirmButtonAction(actionName ?? AppLocalizations.of(context).yes, () {
popBack();
onConfirmAction?.call();
})
Expand Down
Loading

0 comments on commit a422ef4

Please sign in to comment.