TF-1176 Fix delete button is enable even when no mailbox is selected
This commit is contained in:
@@ -25,6 +25,7 @@ class ButtonBuilder {
|
|||||||
double? _radiusSplash;
|
double? _radiusSplash;
|
||||||
double? _maxWidth;
|
double? _maxWidth;
|
||||||
EdgeInsets? _padding;
|
EdgeInsets? _padding;
|
||||||
|
String? _tooltip;
|
||||||
|
|
||||||
void key(Key key) {
|
void key(Key key) {
|
||||||
_key = key;
|
_key = key;
|
||||||
@@ -79,6 +80,10 @@ class ButtonBuilder {
|
|||||||
_isVertical = isVertical;
|
_isVertical = isVertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tooltip(String? message) {
|
||||||
|
_tooltip = message;
|
||||||
|
}
|
||||||
|
|
||||||
ButtonBuilder(this._icon);
|
ButtonBuilder(this._icon);
|
||||||
|
|
||||||
void onPressActionClick(OnPressActionClick onPressActionClick) {
|
void onPressActionClick(OnPressActionClick onPressActionClick) {
|
||||||
@@ -109,14 +114,17 @@ class ButtonBuilder {
|
|||||||
},
|
},
|
||||||
customBorder: RoundedRectangleBorder(
|
customBorder: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(_radiusSplash ?? 20)),
|
borderRadius: BorderRadius.circular(_radiusSplash ?? 20)),
|
||||||
child: Container(
|
child: Tooltip(
|
||||||
key: _key,
|
message: _tooltip ?? '',
|
||||||
alignment: Alignment.center,
|
child: Container(
|
||||||
color: _decoration == null ? _colorButton : null,
|
key: _key,
|
||||||
decoration: _decoration,
|
alignment: Alignment.center,
|
||||||
width: _maxWidth,
|
color: _decoration == null ? _colorButton : null,
|
||||||
padding: _padding ?? EdgeInsets.zero,
|
decoration: _decoration,
|
||||||
child: _buildBody()
|
width: _maxWidth,
|
||||||
|
padding: _padding ?? EdgeInsets.zero,
|
||||||
|
child: _buildBody()
|
||||||
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -573,6 +573,31 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
|
|||||||
|
|
||||||
bool isSelectionEnabled() => currentSelectMode.value == SelectMode.ACTIVE;
|
bool isSelectionEnabled() => currentSelectMode.value == SelectMode.ACTIVE;
|
||||||
|
|
||||||
|
List<MailboxActions> get listActionOfMailboxSelected {
|
||||||
|
final currentMailboxesSelected = listMailboxSelected;
|
||||||
|
|
||||||
|
if (currentMailboxesSelected.length == 1) {
|
||||||
|
if (currentMailboxesSelected.isAllDefaultMailboxes && currentMailboxesSelected.isAllUnreadMailboxes) {
|
||||||
|
return [MailboxActions.markAsRead];
|
||||||
|
} else if (currentMailboxesSelected.isAllPersonalMailboxes) {
|
||||||
|
return [
|
||||||
|
MailboxActions.move,
|
||||||
|
MailboxActions.rename,
|
||||||
|
if (currentMailboxesSelected.isAllUnreadMailboxes)
|
||||||
|
MailboxActions.markAsRead,
|
||||||
|
MailboxActions.delete
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
} else if (currentMailboxesSelected.length > 1
|
||||||
|
&& currentMailboxesSelected.isAllPersonalMailboxes) {
|
||||||
|
return [MailboxActions.delete];
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _cancelSelectMailbox() {
|
void _cancelSelectMailbox() {
|
||||||
unAllSelectedMailboxNode();
|
unAllSelectedMailboxNode();
|
||||||
currentSelectMode.value = SelectMode.INACTIVE;
|
currentSelectMode.value = SelectMode.INACTIVE;
|
||||||
|
|||||||
@@ -58,9 +58,14 @@ class MailboxView extends GetWidget<MailboxController>
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
Obx(() => controller.isSelectionEnabled()
|
Obx(() {
|
||||||
? _buildOptionSelectionMailbox(context)
|
if (controller.isSelectionEnabled()
|
||||||
: const SizedBox.shrink()),
|
&& controller.listActionOfMailboxSelected.isNotEmpty) {
|
||||||
|
return _buildOptionSelectionMailbox(context);
|
||||||
|
} else {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
}),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
Obx(() => controller.isMailboxListScrollable.isTrue
|
Obx(() => controller.isMailboxListScrollable.isTrue
|
||||||
@@ -377,21 +382,32 @@ class MailboxView extends GetWidget<MailboxController>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildOptionSelectionMailbox(BuildContext context) {
|
Widget _buildOptionSelectionMailbox(BuildContext context) {
|
||||||
return Column(children: [
|
return Column(
|
||||||
const Divider(color: AppColor.lineItemListColor, height: 1, thickness: 0.2),
|
mainAxisSize: MainAxisSize.min,
|
||||||
SafeArea(
|
children: [
|
||||||
child: Padding(
|
const Divider(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
color: AppColor.lineItemListColor,
|
||||||
child: (BottomBarSelectionMailboxWidget(context,
|
height: 1,
|
||||||
_imagePaths,
|
thickness: 0.2
|
||||||
controller.listMailboxSelected)
|
),
|
||||||
..addOnMailboxActionsClick((actions, listMailboxSelected) =>
|
SafeArea(
|
||||||
controller.pressMailboxSelectionAction(
|
right: false,
|
||||||
context,
|
top: false,
|
||||||
actions,
|
child: BottomBarSelectionMailboxWidget(
|
||||||
listMailboxSelected)))
|
_responsiveUtils,
|
||||||
.build()))
|
_imagePaths,
|
||||||
]);
|
controller.listMailboxSelected,
|
||||||
|
controller.listActionOfMailboxSelected,
|
||||||
|
onMailboxActionsClick: (actions, listMailboxSelected) =>
|
||||||
|
controller.pressMailboxSelectionAction(
|
||||||
|
context,
|
||||||
|
actions,
|
||||||
|
listMailboxSelected
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildVersionInformation(BuildContext context, PackageInfo packageInfo) {
|
Widget _buildVersionInformation(BuildContext context, PackageInfo packageInfo) {
|
||||||
|
|||||||
+36
-116
@@ -1,133 +1,53 @@
|
|||||||
import 'package:core/core.dart';
|
import 'package:core/presentation/extensions/color_extension.dart';
|
||||||
|
import 'package:core/presentation/resources/image_paths.dart';
|
||||||
|
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||||
|
import 'package:core/presentation/views/button/button_builder.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:model/model.dart';
|
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
|
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
|
||||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
|
||||||
|
|
||||||
typedef OnMailboxActionsClick = void Function(MailboxActions, List<PresentationMailbox>);
|
typedef OnMailboxActionsClick = void Function(MailboxActions, List<PresentationMailbox>);
|
||||||
|
|
||||||
class BottomBarSelectionMailboxWidget {
|
class BottomBarSelectionMailboxWidget extends StatelessWidget {
|
||||||
|
|
||||||
final BuildContext _context;
|
final ResponsiveUtils _responsiveUtils;
|
||||||
final ImagePaths _imagePaths;
|
final ImagePaths _imagePaths;
|
||||||
final List<PresentationMailbox> _listSelectionMailbox;
|
final List<PresentationMailbox> _listSelectionMailbox;
|
||||||
|
final List<MailboxActions> _listMailboxActions;
|
||||||
|
final OnMailboxActionsClick onMailboxActionsClick;
|
||||||
|
|
||||||
OnMailboxActionsClick? _onMailboxActionsClick;
|
const BottomBarSelectionMailboxWidget(
|
||||||
|
this._responsiveUtils,
|
||||||
BottomBarSelectionMailboxWidget(
|
|
||||||
this._context,
|
|
||||||
this._imagePaths,
|
this._imagePaths,
|
||||||
this._listSelectionMailbox,
|
this._listSelectionMailbox,
|
||||||
);
|
this._listMailboxActions,
|
||||||
|
{
|
||||||
|
Key? key,
|
||||||
|
required this.onMailboxActionsClick
|
||||||
|
}
|
||||||
|
) : super(key: key);
|
||||||
|
|
||||||
void addOnMailboxActionsClick(OnMailboxActionsClick onMailboxActionsClick) {
|
|
||||||
_onMailboxActionsClick = onMailboxActionsClick;
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(children: _listMailboxActions
|
||||||
|
.map((action) => _buildMailboxActionButton(context, action))
|
||||||
|
.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget build() {
|
Widget _buildMailboxActionButton(BuildContext context, MailboxActions actions) {
|
||||||
return Container(
|
return Expanded(child: (ButtonBuilder(actions.getContextMenuIcon(_imagePaths))
|
||||||
key: const Key('bottom_bar_selection_mailbox_widget'),
|
..key(const Key('button_move_all_mailbox'))
|
||||||
alignment: Alignment.center,
|
..radiusSplash(8)
|
||||||
color: Colors.white,
|
..padding(const EdgeInsets.all(8))
|
||||||
child: MediaQuery(
|
..tooltip(actions.getTitleContextMenu(context))
|
||||||
data: const MediaQueryData(padding: EdgeInsets.zero),
|
..textStyle(const TextStyle(fontSize: 12, color: AppColor.colorTextButton))
|
||||||
child: SafeArea(child: _buildListOptionButton())
|
..iconColor(AppColor.colorTextButton)
|
||||||
|
..onPressActionClick(() => onMailboxActionsClick.call(actions, _listSelectionMailbox))
|
||||||
|
..text(
|
||||||
|
_responsiveUtils.isLandscapeMobile(context) ? null : actions.getTitleContextMenu(context),
|
||||||
|
isVertical: true
|
||||||
)
|
)
|
||||||
);
|
).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildListOptionButton() {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Expanded(child: (ButtonBuilder(_imagePaths.icMoveMailbox)
|
|
||||||
..key(const Key('button_move_all_mailbox'))
|
|
||||||
..paddingIcon(const EdgeInsets.all(8))
|
|
||||||
..textStyle(TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: _isMoveMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3)))
|
|
||||||
..iconColor(_isMoveMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3))
|
|
||||||
..onPressActionClick(() {
|
|
||||||
if (_isMoveMailboxValid) {
|
|
||||||
_onMailboxActionsClick?.call(MailboxActions.move, _listSelectionMailbox);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
..text(AppLocalizations.of(_context).move, isVertical: true))
|
|
||||||
.build()),
|
|
||||||
Expanded(child: (ButtonBuilder(_imagePaths.icRenameMailbox)
|
|
||||||
..key(const Key('button_rename_mailbox'))
|
|
||||||
..paddingIcon(const EdgeInsets.all(8))
|
|
||||||
..textStyle(TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: _isRenameMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3)))
|
|
||||||
..iconColor(_isRenameMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3))
|
|
||||||
..onPressActionClick(() {
|
|
||||||
if (_isRenameMailboxValid) {
|
|
||||||
_onMailboxActionsClick?.call(MailboxActions.rename, _listSelectionMailbox);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
..text(AppLocalizations.of(_context).rename, isVertical: true))
|
|
||||||
.build()),
|
|
||||||
Expanded(child: (ButtonBuilder(_imagePaths.icMarkAsRead)
|
|
||||||
..key(const Key('button_mark_read_all_mailbox'))
|
|
||||||
..paddingIcon(const EdgeInsets.all(8))
|
|
||||||
..textStyle(TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: _isMarkAsReadMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3)))
|
|
||||||
..iconColor(_isMarkAsReadMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3))
|
|
||||||
..onPressActionClick(() {
|
|
||||||
if (_isMarkAsReadMailboxValid) {
|
|
||||||
_onMailboxActionsClick?.call(MailboxActions.markAsRead, _listSelectionMailbox);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
..text(AppLocalizations.of(_context).mark_as_read, isVertical: true))
|
|
||||||
.build()),
|
|
||||||
Expanded(child: (ButtonBuilder(_imagePaths.icDeleteMailbox)
|
|
||||||
..key(const Key('button_delete_all_mailbox'))
|
|
||||||
..paddingIcon(const EdgeInsets.all(8))
|
|
||||||
..textStyle(TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: _isDeleteMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3)))
|
|
||||||
..iconColor(_isDeleteMailboxValid
|
|
||||||
? AppColor.colorTextButton
|
|
||||||
: AppColor.colorTextButton.withOpacity(0.3))
|
|
||||||
..onPressActionClick(() {
|
|
||||||
if (_isDeleteMailboxValid) {
|
|
||||||
_onMailboxActionsClick?.call(MailboxActions.delete, _listSelectionMailbox);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
..text(AppLocalizations.of(_context).delete, isVertical: true))
|
|
||||||
.build())
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get _isDeleteMailboxValid => _isAllFolderMailbox;
|
|
||||||
|
|
||||||
bool get _isRenameMailboxValid => _listSelectionMailbox.length == 1
|
|
||||||
&& _isAllFolderMailbox;
|
|
||||||
|
|
||||||
bool get _isMarkAsReadMailboxValid => _listSelectionMailbox.length == 1
|
|
||||||
&& _listSelectionMailbox.first.getCountUnReadEmails().isNotEmpty;
|
|
||||||
|
|
||||||
bool get _isMoveMailboxValid => _listSelectionMailbox.length == 1
|
|
||||||
&& _isAllFolderMailbox;
|
|
||||||
|
|
||||||
bool get _isAllFolderMailbox =>
|
|
||||||
_listSelectionMailbox.every((mailbox) => !mailbox.hasRole());
|
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,10 @@ extension ListPresentationMailboxExtension on List<PresentationMailbox> {
|
|||||||
|
|
||||||
List<PresentationMailbox> get listPersonalMailboxes =>
|
List<PresentationMailbox> get listPersonalMailboxes =>
|
||||||
where((mailbox) => mailbox.isPersonal).toList();
|
where((mailbox) => mailbox.isPersonal).toList();
|
||||||
|
|
||||||
|
bool get isAllPersonalMailboxes => every((mailbox) => mailbox.isPersonal && !mailbox.isDefault);
|
||||||
|
|
||||||
|
bool get isAllDefaultMailboxes => every((mailbox) => mailbox.isDefault);
|
||||||
|
|
||||||
|
bool get isAllUnreadMailboxes => every((mailbox) => mailbox.getCountUnReadEmails().isNotEmpty);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user