mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Simplify pages system
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import 'package:comunic/helpers/events_helper.dart';
|
||||
import 'package:comunic/helpers/notifications_helper.dart';
|
||||
import 'package:comunic/models/count_unread_notifications.dart';
|
||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
||||
import 'package:comunic/ui/routes/main_route/page_info.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -14,7 +16,6 @@ typedef OnSelectMenuAction = void Function(BarCallbackActions);
|
||||
|
||||
/// Callback actions
|
||||
enum BarCallbackActions {
|
||||
OPEN_CUSTOM_WIDGET,
|
||||
OPEN_NOTIFICATIONS,
|
||||
OPEN_CONVERSATIONS,
|
||||
OPEN_NEWEST_POSTS,
|
||||
@ -22,14 +23,8 @@ enum BarCallbackActions {
|
||||
OPEN_MY_PAGE,
|
||||
OPEN_SEARCH_PAGE,
|
||||
OPEN_GROUPS,
|
||||
OPEN_GROUP_PAGE,
|
||||
OPEN_USER_PAGE,
|
||||
OPEN_USER_ACCESS_DENIED_PAGE,
|
||||
OPEN_ACCOUNT_SETTINGS,
|
||||
OPEN_APP_SETTINGS,
|
||||
OPEN_USER_FRIENDS_LIST,
|
||||
OPEN_CONVERSATION,
|
||||
NONE,
|
||||
ACTION_LOGOUT
|
||||
}
|
||||
|
||||
@ -43,16 +38,19 @@ class _MenuItem {
|
||||
final Widget icon;
|
||||
final BarCallbackActions action;
|
||||
final bool isMenu;
|
||||
final PageType pageType;
|
||||
|
||||
const _MenuItem({
|
||||
@required this.label,
|
||||
@required this.icon,
|
||||
@required this.action,
|
||||
@required this.pageType,
|
||||
this.isMenu = false,
|
||||
}) : assert(label != null),
|
||||
assert(icon != null || isMenu),
|
||||
assert(action != null),
|
||||
assert(isMenu != null);
|
||||
assert(isMenu != null),
|
||||
assert(isMenu || icon != null),
|
||||
assert(isMenu || action != null),
|
||||
assert(isMenu || pageType != null);
|
||||
}
|
||||
|
||||
/// Item of action menu
|
||||
@ -70,24 +68,29 @@ final _menuItems = <_MenuItem>[
|
||||
_MenuItem(
|
||||
label: tr("Notifications"),
|
||||
icon: Icon(Icons.notifications),
|
||||
action: BarCallbackActions.OPEN_NOTIFICATIONS),
|
||||
action: BarCallbackActions.OPEN_NOTIFICATIONS,
|
||||
pageType: PageType.NOTIFICATIONS_PAGE),
|
||||
_MenuItem(
|
||||
label: tr("Conversations"),
|
||||
icon: Icon(Icons.comment),
|
||||
action: BarCallbackActions.OPEN_CONVERSATIONS),
|
||||
action: BarCallbackActions.OPEN_CONVERSATIONS,
|
||||
pageType: PageType.CONVERSATIONS_LIST_PAGE),
|
||||
_MenuItem(
|
||||
label: tr("Newest"),
|
||||
icon: Icon(Icons.refresh),
|
||||
action: BarCallbackActions.OPEN_NEWEST_POSTS),
|
||||
action: BarCallbackActions.OPEN_NEWEST_POSTS,
|
||||
pageType: PageType.LATEST_POSTS_PAGE),
|
||||
_MenuItem(
|
||||
label: tr("Friends"),
|
||||
icon: Icon(Icons.group),
|
||||
action: BarCallbackActions.OPEN_FRIENDS),
|
||||
action: BarCallbackActions.OPEN_FRIENDS,
|
||||
pageType: PageType.FRIENDS_LIST_PAGE),
|
||||
_MenuItem(
|
||||
label: tr("Menu"),
|
||||
icon: Icon(Icons.more_vert),
|
||||
isMenu: true,
|
||||
action: BarCallbackActions.NONE)
|
||||
action: null,
|
||||
pageType: null)
|
||||
];
|
||||
|
||||
/// List of menu actions items
|
||||
@ -107,13 +110,14 @@ final _menuActionsItem = <_ActionMenuItem>[
|
||||
];
|
||||
|
||||
/// Public widget
|
||||
class ComunicMobileAppBar extends StatefulWidget implements PreferredSizeWidget {
|
||||
final OnSelectMenuAction onTap;
|
||||
final BarCallbackActions selectedAction;
|
||||
class ComunicMobileAppBar extends StatefulWidget
|
||||
implements PreferredSizeWidget {
|
||||
final PageInfo currentPage;
|
||||
|
||||
const ComunicMobileAppBar(
|
||||
{Key key, @required this.onTap, @required this.selectedAction})
|
||||
: assert(onTap != null),
|
||||
const ComunicMobileAppBar({
|
||||
Key key,
|
||||
@required this.currentPage,
|
||||
}) : assert(currentPage != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
@ -178,14 +182,50 @@ class _ComunicMobileAppBarState extends SafeState<ComunicMobileAppBar> {
|
||||
_menuItems.length,
|
||||
(i) => _MenuItemWidget(
|
||||
item: _menuItems[i],
|
||||
onTap: widget.onTap,
|
||||
isSelected: _menuItems[i].action == widget.selectedAction,
|
||||
onTap: _handleAction,
|
||||
isSelected: _menuItems[i].pageType == widget.currentPage.type,
|
||||
newNotice: getNumberUnread(_menuItems[i].action),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleAction(BarCallbackActions action) {
|
||||
final controller = MainController.of(context);
|
||||
switch (action) {
|
||||
case BarCallbackActions.OPEN_NOTIFICATIONS:
|
||||
controller.openNotificationsPage();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_CONVERSATIONS:
|
||||
controller.openConversationsPage();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_NEWEST_POSTS:
|
||||
controller.openLatestPostsPage();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_FRIENDS:
|
||||
controller.openFriendsList();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_MY_PAGE:
|
||||
controller.openCurrentUserPage();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_SEARCH_PAGE:
|
||||
controller.openSearchPage();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_GROUPS:
|
||||
controller.openGroupsListPage();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_ACCOUNT_SETTINGS:
|
||||
controller.openAccountSettings();
|
||||
break;
|
||||
case BarCallbackActions.OPEN_APP_SETTINGS:
|
||||
controller.openAppSettings();
|
||||
break;
|
||||
case BarCallbackActions.ACTION_LOGOUT:
|
||||
controller.requestLogout();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The [Widget] part of a menu item
|
||||
|
Reference in New Issue
Block a user