From 1451370974aeb7d1daf08bb063fffee71c6d147c Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Thu, 21 Sep 2023 14:52:21 +0700 Subject: [PATCH] TW-613: Update icon and title when select multi --- assets/l10n/intl_en.arb | 4 +- lib/pages/chat_list/chat_list.dart | 181 +++++++++--------- lib/pages/chat_list/chat_list_body.dart | 1 - .../chat_list/chat_list_bottom_navigator.dart | 44 +---- lib/pages/chat_list/chat_list_header.dart | 2 +- .../chat_list/chat_list_header_style.dart | 2 + lib/pages/chat_list/chat_list_item.dart | 17 +- lib/pages/chat_list/chat_list_item_style.dart | 12 ++ lib/pages/chat_list/chat_list_view.dart | 17 +- lib/pages/chat_list/space_view.dart | 2 +- lib/pages/settings/settings.dart | 4 +- .../enum/chat_list/chat_list_enum.dart | 58 ++++-- .../adaptive_layout/adaptive_scaffold.dart | 27 +-- .../adaptive_scaffold_view.dart | 46 +---- .../enum/adaptive_destinations_enum.dart | 39 ++++ pubspec.lock | 56 ++++++ 16 files changed, 293 insertions(+), 219 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 0eec09d067..d210557729 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2732,5 +2732,7 @@ "markThisMessageAsUnRead": "Mark this message as unread", "muteThisMessage": "Mute this message", "unmuteThisMessage": "Unmute this message", - "read": "Read" + "read": "Read", + "unread": "Unread", + "unmute": "Unmute" } \ No newline at end of file diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index b4486eba65..522e4c7e97 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:adaptive_dialog/adaptive_dialog.dart'; +import 'package:collection/collection.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/di/global/get_it_initializer.dart'; import 'package:fluffychat/domain/model/recovery_words/recovery_words.dart'; @@ -71,23 +72,8 @@ class ChatListController extends State String? activeSpaceId; - late final profileMemoizers = >{}; - Client get client => Matrix.of(context).client; - Future fetchOwnProfile({required Client client}) { - if (!profileMemoizers.containsKey(client)) { - profileMemoizers[client] = AsyncMemoizer(); - } - return profileMemoizers[client]!.runOnce(() async { - return await client.fetchOwnProfile(); - }); - } - - void updateProfile(Client? client) { - profileMemoizers[client] = AsyncMemoizer(); - } - void resetActiveSpaceId() { setState(() { activeSpaceId = null; @@ -278,13 +264,14 @@ class ChatListController extends State (conversation) => conversation.roomId == roomId, ); - final Set temp = + final Set + tempConversationSelectionPresentation = conversationSelectionNotifier.value.toSet(); if (conversation != null) { - temp.remove(conversation); + conversationSelectionNotifier.value.toSet().remove(conversation); } else { - temp.add( + tempConversationSelectionPresentation.add( ConversationSelectionPresentation( roomId: roomId, selectionType: SelectionType.selected, @@ -292,25 +279,33 @@ class ChatListController extends State ); } - conversationSelectionNotifier.value = temp.toList(); + conversationSelectionNotifier.value = + tempConversationSelectionPresentation.toList(); } void toggleSelectMode() { selectModeNotifier.value = isSelectMode ? SelectMode.normal : SelectMode.select; - clearSelection(); + _clearSelectionItem(); } - void clearSelection() { + void _clearSelectionItem() { conversationSelectionNotifier.value = []; } - void toggleUnread() async { + void onClickClearSelection() { + if (conversationSelectionNotifier.value.isNotEmpty) { + _clearSelectionItem(); + } else { + toggleSelectMode(); + } + } + + Future toggleUnread() async { await showFutureLoadingDialog( context: context, future: () async { final markUnread = anySelectedRoomNotMarkedUnread; - final client = Matrix.of(context).client; for (final conversation in conversationSelectionNotifier.value) { final room = client.getRoomById(conversation.roomId)!; if (room.markedUnread == markUnread) continue; @@ -321,12 +316,11 @@ class ChatListController extends State toggleSelectMode(); } - void toggleFavouriteRoom() async { + Future toggleFavouriteRoom() async { await showFutureLoadingDialog( context: context, future: () async { final makeFavorite = anySelectedRoomNotFavorite; - final client = Matrix.of(context).client; for (final conversation in conversationSelectionNotifier.value) { final room = client.getRoomById(conversation.roomId)!; if (room.isFavourite == makeFavorite) continue; @@ -339,14 +333,13 @@ class ChatListController extends State toggleSelectMode(); } - void toggleMuted() async { + Future toggleMuted() async { await showFutureLoadingDialog( context: context, future: () async { final newState = anySelectedRoomNotMuted ? PushRuleState.mentionsOnly : PushRuleState.notify; - final client = Matrix.of(context).client; for (final conversation in conversationSelectionNotifier.value) { final room = client.getRoomById(conversation.roomId)!; if (room.pushRuleState == newState) continue; @@ -401,7 +394,6 @@ class ChatListController extends State } Future _archiveSelectedRooms() async { - final client = Matrix.of(context).client; while (conversationSelectionNotifier.value.isNotEmpty) { final conversation = conversationSelectionNotifier.value.first; try { @@ -483,7 +475,6 @@ class ChatListController extends State bool waitForFirstSync = false; Future _waitForFirstSync() async { - final client = Matrix.of(context).client; await client.roomsLoading; await client.accountDataLoading; if (client.prevBatch == null) { @@ -617,15 +608,15 @@ class ChatListController extends State ) async { switch (chatListBottomNavigatorBar) { case ChatListSelectionActions.read: - toggleUnread(); + await toggleUnread(); toggleSelectMode(); return; case ChatListSelectionActions.mute: - toggleMuted(); + await toggleMuted(); toggleSelectMode(); return; case ChatListSelectionActions.pin: - toggleFavouriteRoom(); + await toggleFavouriteRoom(); toggleSelectMode(); return; case ChatListSelectionActions.more: @@ -634,59 +625,6 @@ class ChatListController extends State } } - String _getTitleContextMenuSelection( - ChatListSelectionActions chatListBottomNavigatorBar, - Room room, - ) { - switch (chatListBottomNavigatorBar) { - case ChatListSelectionActions.read: - if (room.markedUnread) { - return L10n.of(context)!.markThisMessageAsRead; - } else { - return L10n.of(context)!.markThisMessageAsUnRead; - } - case ChatListSelectionActions.mute: - if (room.pushRuleState == PushRuleState.notify) { - return L10n.of(context)!.muteThisMessage; - } else { - return L10n.of(context)!.unmuteThisMessage; - } - case ChatListSelectionActions.pin: - return L10n.of(context)!.pinThisMessage; - case ChatListSelectionActions.more: - return L10n.of(context)!.more; - } - } - - IconData _getIconContextMenuSelection( - ChatListSelectionActions chatListBottomNavigatorBar, - Room room, - ) { - switch (chatListBottomNavigatorBar) { - case ChatListSelectionActions.read: - if (room.markedUnread) { - return Icons.mark_chat_read; - } else { - return Icons.mark_chat_unread; - } - case ChatListSelectionActions.mute: - if (room.pushRuleState == PushRuleState.notify) { - return Icons.volume_off; - } else { - return Icons.volume_up; - } - - case ChatListSelectionActions.pin: - if (room.isFavourite) { - return Icons.push_pin_outlined; - } else { - return Icons.push_pin; - } - case ChatListSelectionActions.more: - return Icons.more_vert; - } - } - void handleContextMenuAction( BuildContext context, Room room, @@ -712,8 +650,8 @@ class ChatListController extends State padding: EdgeInsets.zero, child: popupItem( context, - _getTitleContextMenuSelection(action, room), - iconAction: _getIconContextMenuSelection(action, room), + action.getTitleContextMenuSelection(context, room), + iconAction: action.getIconContextMenuSelection(room), onCallbackAction: () => _handleClickOnContextMenuItem( action, room, @@ -761,6 +699,75 @@ class ChatListController extends State } } + List _getNavigationDestinations() { + return [ + ChatListSelectionActions.read, + ChatListSelectionActions.mute, + ChatListSelectionActions.pin, + ChatListSelectionActions.more, + ]; + } + + List bottomNavigationActionsWidget({ + required EdgeInsetsDirectional paddingIcon, + double? width, + double? iconSize, + }) { + return _getNavigationDestinations().map((item) { + return InkWell( + onTap: () => _onTapBottomNavigation(item), + child: SizedBox( + width: width, + child: Column( + children: [ + Padding( + padding: paddingIcon, + child: Icon( + item.getIconBottomNavigation(), + size: iconSize, + color: Theme.of(context).colorScheme.primary, + ), + ), + Text( + _getTitleBottomNavigation(item), + style: Theme.of(context).textTheme.labelMedium?.copyWith( + color: Theme.of(context).colorScheme.primary, + ), + ), + ], + ), + ), + ); + }).toList(); + } + + String _getTitleBottomNavigation( + ChatListSelectionActions actionBottomNavigation, + ) { + switch (actionBottomNavigation) { + case ChatListSelectionActions.read: + if (anySelectedRoomNotMarkedUnread) { + return L10n.of(context)!.unread; + } else { + return L10n.of(context)!.read; + } + case ChatListSelectionActions.mute: + if (anySelectedRoomNotMuted) { + return L10n.of(context)!.mute; + } else { + return L10n.of(context)!.unmute; + } + case ChatListSelectionActions.pin: + if (anySelectedRoomNotFavorite) { + return L10n.of(context)!.pin; + } else { + return L10n.of(context)!.unpin; + } + case ChatListSelectionActions.more: + return L10n.of(context)!.more; + } + } + @override Widget build(BuildContext context) { return ChatListView( diff --git a/lib/pages/chat_list/chat_list_body.dart b/lib/pages/chat_list/chat_list_body.dart index cf9f7facc1..491ef5458e 100644 --- a/lib/pages/chat_list/chat_list_body.dart +++ b/lib/pages/chat_list/chat_list_body.dart @@ -181,7 +181,6 @@ class ChatListViewBody extends StatelessWidget { onTap: controller.isSelectMode ? () => controller.toggleSelection(rooms[index].id) : null, - // onLongPress: () => controller.toggleSelection(rooms[i].id), onSecondaryTap: () => controller.handleContextMenuAction( context, rooms[index], diff --git a/lib/pages/chat_list/chat_list_bottom_navigator.dart b/lib/pages/chat_list/chat_list_bottom_navigator.dart index e6716f29f4..95ad73bd91 100644 --- a/lib/pages/chat_list/chat_list_bottom_navigator.dart +++ b/lib/pages/chat_list/chat_list_bottom_navigator.dart @@ -6,13 +6,13 @@ import 'package:flutter/material.dart'; typedef ChatListBottomNavigatorBarIcon = Function(ChatListSelectionActions); class ChatListBottomNavigator extends StatelessWidget { + final List bottomNavigationActionsWidget; + const ChatListBottomNavigator({ super.key, - required this.onTapBottomNavigation, + required this.bottomNavigationActionsWidget, }); - final ChatListBottomNavigatorBarIcon onTapBottomNavigation; - @override Widget build(BuildContext context) { return Container( @@ -21,44 +21,8 @@ class ChatListBottomNavigator extends StatelessWidget { color: Theme.of(context).colorScheme.surface, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: _getNavigationDestinations.map( - (item) { - return InkWell( - onTap: () => onTapBottomNavigation(item), - child: SizedBox( - width: ChatListBottomNavigatorStyle.width, - child: Column( - children: [ - Padding( - padding: ChatListBottomNavigatorStyle.paddingIcon, - child: Icon( - item.getIcon(context), - size: ChatListBottomNavigatorStyle.iconSize, - color: Theme.of(context).colorScheme.primary, - ), - ), - Text( - item.getTitleForMobile(context), - style: Theme.of(context).textTheme.labelMedium?.copyWith( - color: Theme.of(context).colorScheme.primary, - ), - ), - ], - ), - ), - ); - }, - ).toList(), + children: bottomNavigationActionsWidget, ), ); } - - List get _getNavigationDestinations { - return [ - ChatListSelectionActions.read, - ChatListSelectionActions.mute, - ChatListSelectionActions.pin, - ChatListSelectionActions.more, - ]; - } } diff --git a/lib/pages/chat_list/chat_list_header.dart b/lib/pages/chat_list/chat_list_header.dart index cb0db4ac7d..75f5e27aae 100644 --- a/lib/pages/chat_list/chat_list_header.dart +++ b/lib/pages/chat_list/chat_list_header.dart @@ -55,7 +55,7 @@ class ChatListHeader extends StatelessWidget { enabled: false, decoration: InputDecoration( filled: true, - contentPadding: EdgeInsetsDirectional.zero, + contentPadding: ChatListHeaderStyle.paddingZero, fillColor: Theme.of(context).colorScheme.surface, border: OutlineInputBorder( borderSide: BorderSide.none, diff --git a/lib/pages/chat_list/chat_list_header_style.dart b/lib/pages/chat_list/chat_list_header_style.dart index 21872a61b5..5593d86878 100644 --- a/lib/pages/chat_list/chat_list_header_style.dart +++ b/lib/pages/chat_list/chat_list_header_style.dart @@ -14,4 +14,6 @@ class ChatListHeaderStyle { start: 16, end: 16, ); + + static const EdgeInsetsDirectional paddingZero = EdgeInsetsDirectional.zero; } diff --git a/lib/pages/chat_list/chat_list_item.dart b/lib/pages/chat_list/chat_list_item.dart index b224902f65..f2e013b195 100644 --- a/lib/pages/chat_list/chat_list_item.dart +++ b/lib/pages/chat_list/chat_list_item.dart @@ -1,6 +1,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item_mixin.dart'; +import 'package:fluffychat/pages/chat_list/chat_list_item_style.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item_subtitle.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item_title.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; @@ -20,7 +21,7 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { final bool isEnableSelectMode; final Widget? checkBoxWidget; final void Function()? onTap; - final void Function()? onLongPress; + final void Function()? onTapAvatar; final void Function()? onSecondaryTap; const ChatListItem( @@ -30,7 +31,7 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { this.isSelectedItem = false, this.isEnableSelectMode = false, this.onTap, - this.onLongPress, + this.onTapAvatar, this.onSecondaryTap, Key? key, }) : super(key: key); @@ -87,10 +88,7 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { MatrixLocals(L10n.of(context)!), ); return Padding( - padding: const EdgeInsets.symmetric( - horizontal: 8, - vertical: 1, - ), + padding: ChatListItemStyle.paddingConversation, child: Material( borderRadius: BorderRadius.circular(AppConfig.borderRadius), clipBehavior: Clip.hardEdge, @@ -101,19 +99,18 @@ class ChatListItem extends StatelessWidget with ChatListItemMixin { : Colors.transparent, child: InkWell( onTap: () => clickAction(context), - // onLongPress: onLongPress, onSecondaryTap: onSecondaryTap, child: Container( - padding: const EdgeInsets.symmetric(horizontal: 8), + padding: ChatListItemStyle.paddingBody, child: Row( children: [ if (isEnableSelectMode) checkBoxWidget ?? const SizedBox(), Padding( - padding: const EdgeInsetsDirectional.only(end: 8), + padding: ChatListItemStyle.paddingAvatar, child: Avatar( mxContent: room.avatar, name: displayname, - onTap: onLongPress, + onTap: onTapAvatar, ), ), Expanded( diff --git a/lib/pages/chat_list/chat_list_item_style.dart b/lib/pages/chat_list/chat_list_item_style.dart index bc9f0de551..f90a1fb248 100644 --- a/lib/pages/chat_list/chat_list_item_style.dart +++ b/lib/pages/chat_list/chat_list_item_style.dart @@ -18,6 +18,18 @@ class ChatListItemStyle { : 0.0; } + static const EdgeInsetsDirectional paddingConversation = + EdgeInsetsDirectional.symmetric( + horizontal: 8, + vertical: 1, + ); + + static const EdgeInsetsDirectional paddingAvatar = + EdgeInsetsDirectional.only(end: 8); + + static const EdgeInsetsDirectional paddingBody = + EdgeInsetsDirectional.symmetric(horizontal: 8); + static const double unreadBadgePaddingWhenMoreThanOne = 9.0; static double notificationBadgeSize( bool unread, diff --git a/lib/pages/chat_list/chat_list_view.dart b/lib/pages/chat_list/chat_list_view.dart index 21d7921211..ab76993eb2 100644 --- a/lib/pages/chat_list/chat_list_view.dart +++ b/lib/pages/chat_list/chat_list_view.dart @@ -1,6 +1,7 @@ import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:fluffychat/pages/chat_list/chat_list_body_stream.dart'; import 'package:fluffychat/pages/chat_list/chat_list_bottom_navigator.dart'; +import 'package:fluffychat/pages/chat_list/chat_list_bottom_navigator_style.dart'; import 'package:fluffychat/pages/chat_list/chat_list_header.dart'; import 'package:fluffychat/pages/chat_list/chat_list_view_style.dart'; import 'package:fluffychat/widgets/twake_components/twake_fab.dart'; @@ -15,7 +16,6 @@ class ChatListView extends StatelessWidget { final Widget? bottomNavigationBar; final VoidCallback? onOpenSearchPage; final ChatListBottomNavigatorBarIcon onTapBottomNavigation; - const ChatListView({ Key? key, required this.controller, @@ -42,15 +42,20 @@ class ChatListView extends StatelessWidget { onOpenSearchPage: onOpenSearchPage, conversationSelectionNotifier: controller.conversationSelectionNotifier, - onClearSelection: controller.clearSelection, + onClearSelection: controller.onClickClearSelection, ), ), bottomNavigationBar: ValueListenableBuilder( - valueListenable: controller.selectModeNotifier, - builder: (context, _, __) { - if (controller.isSelectMode) { + valueListenable: controller.conversationSelectionNotifier, + builder: (context, conversationSelection, __) { + if (conversationSelection.isNotEmpty) { return ChatListBottomNavigator( - onTapBottomNavigation: onTapBottomNavigation, + bottomNavigationActionsWidget: + controller.bottomNavigationActionsWidget( + paddingIcon: ChatListBottomNavigatorStyle.paddingIcon, + iconSize: ChatListBottomNavigatorStyle.iconSize, + width: ChatListBottomNavigatorStyle.width, + ), ); } else { return bottomNavigationBar ?? const SizedBox(); diff --git a/lib/pages/chat_list/space_view.dart b/lib/pages/chat_list/space_view.dart index 207f214b10..7c425cfcf1 100644 --- a/lib/pages/chat_list/space_view.dart +++ b/lib/pages/chat_list/space_view.dart @@ -258,7 +258,7 @@ class _SpaceViewState extends State { if (room != null && !room.isSpace) { return ChatListItem( room, - onLongPress: () => _onSpaceChildContextMenu(spaceChild, room), + onTapAvatar: () => _onSpaceChildContextMenu(spaceChild, room), activeChat: true, ); } diff --git a/lib/pages/settings/settings.dart b/lib/pages/settings/settings.dart index d3e5e61542..936ca2898f 100644 --- a/lib/pages/settings/settings.dart +++ b/lib/pages/settings/settings.dart @@ -166,10 +166,11 @@ class SettingsController extends State with ConnectPageMixin { } } + Client get client => Matrix.of(context).client; + @override void initState() { WidgetsBinding.instance.addPostFrameCallback((_) { - final client = Matrix.of(context).client; profileFuture ??= client.getProfileFromUserId( client.userID!, cache: !profileUpdated, @@ -181,7 +182,6 @@ class SettingsController extends State with ConnectPageMixin { } void checkBootstrap() async { - final client = Matrix.of(context).client; if (!client.encryptionEnabled) return; await client.accountDataLoading; await client.userDeviceKeysLoading; diff --git a/lib/presentation/enum/chat_list/chat_list_enum.dart b/lib/presentation/enum/chat_list/chat_list_enum.dart index 456ee27734..7d099dd86f 100644 --- a/lib/presentation/enum/chat_list/chat_list_enum.dart +++ b/lib/presentation/enum/chat_list/chat_list_enum.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:matrix/matrix.dart'; enum SelectMode { normal, @@ -27,41 +28,66 @@ enum ChatListSelectionActions { pin, more; - String getTitleForMobile(BuildContext context) { + IconData getIconBottomNavigation() { switch (this) { case ChatListSelectionActions.read: - return L10n.of(context)!.contacts; + return Icons.mark_email_read; case ChatListSelectionActions.mute: - return L10n.of(context)!.mute; + return Icons.notifications_off; case ChatListSelectionActions.pin: - return L10n.of(context)!.pin; + return Icons.push_pin; case ChatListSelectionActions.more: - return L10n.of(context)!.more; + return Icons.more_vert; } } - IconData getIcon( - BuildContext context, { - bool isMobile = true, - }) { + IconData getIconContextMenuSelection(Room room) { switch (this) { case ChatListSelectionActions.read: - if (isMobile) { - return Icons.mark_email_read; - } else { + if (room.markedUnread) { return Icons.mark_chat_read; + } else { + return Icons.mark_chat_unread; } case ChatListSelectionActions.mute: - if (isMobile) { - return Icons.notifications_off; - } else { + if (room.pushRuleState == PushRuleState.notify) { return Icons.volume_off; + } else { + return Icons.volume_up; } case ChatListSelectionActions.pin: - return Icons.push_pin; + if (room.isFavourite) { + return Icons.push_pin_outlined; + } else { + return Icons.push_pin; + } case ChatListSelectionActions.more: return Icons.more_vert; } } + + String getTitleContextMenuSelection( + BuildContext context, + Room room, + ) { + switch (this) { + case ChatListSelectionActions.read: + if (room.markedUnread) { + return L10n.of(context)!.markThisMessageAsRead; + } else { + return L10n.of(context)!.markThisMessageAsUnRead; + } + case ChatListSelectionActions.mute: + if (room.pushRuleState == PushRuleState.notify) { + return L10n.of(context)!.muteThisMessage; + } else { + return L10n.of(context)!.unmuteThisMessage; + } + case ChatListSelectionActions.pin: + return L10n.of(context)!.pinThisMessage; + case ChatListSelectionActions.more: + return L10n.of(context)!.more; + } + } } diff --git a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart index 93e5d91bf8..dc386ff090 100644 --- a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart +++ b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold.dart @@ -42,24 +42,16 @@ class AdaptiveScaffoldAppController extends State { }); } + List get destinations => [ + AdaptiveDestinationEnum.contacts, + AdaptiveDestinationEnum.rooms, + AdaptiveDestinationEnum.settings, + ]; + void onDestinationSelected(int index) { - switch (index) { - //FIXME: NOW WE SUPPORT FOR ONLY 2 TABS - case 0: - activeNavigationBar.value = AdaptiveDestinationEnum.contacts; - pageController.jumpToPage(index); - break; - case 1: - activeNavigationBar.value = AdaptiveDestinationEnum.rooms; - pageController.jumpToPage(index); - break; - case 2: - activeNavigationBar.value = AdaptiveDestinationEnum.settings; - pageController.jumpToPage(index); - break; - default: - break; - } + final destinationType = destinations[index]; + activeNavigationBar.value = destinationType; + pageController.jumpToPage(index); } void clientSelected( @@ -100,6 +92,7 @@ class AdaptiveScaffoldAppController extends State { @override Widget build(BuildContext context) => AppScaffoldView( + destinations: destinations, activeRoomId: widget.activeRoomId, activeNavigationBar: activeNavigationBar, pageController: pageController, diff --git a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart index 12b1c40fcb..2bd33a6004 100644 --- a/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart +++ b/lib/widgets/layouts/adaptive_layout/adaptive_scaffold_view.dart @@ -3,20 +3,17 @@ import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:fluffychat/pages/contacts_tab/contacts_tab.dart'; import 'package:fluffychat/pages/search/search.dart'; import 'package:fluffychat/pages/settings/settings.dart'; -import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; import 'package:fluffychat/utils/responsive/responsive_utils.dart'; import 'package:fluffychat/widgets/layouts/adaptive_layout/adaptive_scaffold_primary_navigation.dart'; import 'package:fluffychat/widgets/layouts/adaptive_layout/adaptive_scaffold.dart'; import 'package:fluffychat/widgets/layouts/enum/adaptive_destinations_enum.dart'; -import 'package:fluffychat/widgets/twake_components/twake_navigation_icon/twake_navigation_icon.dart'; -import 'package:fluffychat/widgets/unread_rooms_badge.dart'; import 'package:flutter/material.dart'; import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:linagora_design_flutter/linagora_design_flutter.dart'; import 'package:matrix/matrix.dart'; class AppScaffoldView extends StatelessWidget { + final List destinations; final ValueNotifier activeNavigationBar; final PageController pageController; final Future fetchOwnProfile; @@ -47,6 +44,7 @@ class AppScaffoldView extends StatelessWidget { required this.onCloseSearchPage, required this.onDestinationSelected, required this.onClientSelected, + required this.destinations, }) : super(key: key ?? scaffoldWithNestedNavigationKey); @override @@ -128,6 +126,10 @@ class AppScaffoldView extends StatelessWidget { ); } + int _getActiveBottomNavigationBarIndex() { + return destinations.indexOf(activeNavigationBar.value); + } + Widget _triggerPageViewBuilder({ required AdaptiveDestinationEnum navigatorBarType, required Widget navigatorBarWidget, @@ -172,19 +174,6 @@ class AppScaffoldView extends StatelessWidget { ); } - int _getActiveBottomNavigationBarIndex() { - switch (activeNavigationBar.value) { - case AdaptiveDestinationEnum.contacts: - return 0; - case AdaptiveDestinationEnum.rooms: - return 1; - case AdaptiveDestinationEnum.settings: - return 2; - default: - return 1; - } - } - Widget _primaryNavigationBarBuilder(BuildContext context) { final destinations = getNavigationDestinations(context); @@ -200,25 +189,8 @@ class AppScaffoldView extends StatelessWidget { } List getNavigationDestinations(BuildContext context) { - return [ - NavigationDestination( - icon: const TwakeNavigationIcon( - icon: Icons.contacts_outlined, - ), - label: L10n.of(context)!.contacts, - ), - NavigationDestination( - icon: UnreadRoomsBadge( - filter: (room) => !room.isSpace && !room.isStoryRoom, - ), - label: L10n.of(context)!.chat, - ), - NavigationDestination( - icon: const TwakeNavigationIcon( - icon: Icons.settings, - ), - label: L10n.of(context)!.settings, - ), - ]; + return destinations.map((destination) { + return destination.getNavigationDestination(context); + }).toList(); } } diff --git a/lib/widgets/layouts/enum/adaptive_destinations_enum.dart b/lib/widgets/layouts/enum/adaptive_destinations_enum.dart index 39bfdc5942..2cb62815f0 100644 --- a/lib/widgets/layouts/enum/adaptive_destinations_enum.dart +++ b/lib/widgets/layouts/enum/adaptive_destinations_enum.dart @@ -1,6 +1,45 @@ +import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; +import 'package:fluffychat/widgets/twake_components/twake_navigation_icon/twake_navigation_icon.dart'; +import 'package:fluffychat/widgets/unread_rooms_badge.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; + enum AdaptiveDestinationEnum { contacts, rooms, settings, search; + + NavigationDestination getNavigationDestination(BuildContext context) { + switch (this) { + case AdaptiveDestinationEnum.contacts: + return NavigationDestination( + icon: const TwakeNavigationIcon( + icon: Icons.contacts_outlined, + ), + label: L10n.of(context)!.contacts, + ); + case AdaptiveDestinationEnum.rooms: + return NavigationDestination( + icon: UnreadRoomsBadge( + filter: (room) => !room.isSpace && !room.isStoryRoom, + ), + label: L10n.of(context)!.chat, + ); + case AdaptiveDestinationEnum.settings: + return NavigationDestination( + icon: const TwakeNavigationIcon( + icon: Icons.settings, + ), + label: L10n.of(context)!.settings, + ); + default: + return NavigationDestination( + icon: UnreadRoomsBadge( + filter: (room) => !room.isSpace && !room.isStoryRoom, + ), + label: L10n.of(context)!.chat, + ); + } + } } diff --git a/pubspec.lock b/pubspec.lock index d5641896fe..78d739061a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -89,6 +89,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + base58check: + dependency: transitive + description: + name: base58check + sha256: "6c300dfc33e598d2fe26319e13f6243fea81eaf8204cb4c6b69ef20a625319a5" + url: "https://pub.dev" + source: hosted + version: "2.0.0" blurhash_dart: dependency: "direct main" description: @@ -241,6 +249,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.2+1" + canonical_json: + dependency: transitive + description: + name: canonical_json + sha256: d6be1dd66b420c6ac9f42e3693e09edf4ff6edfee26cb4c28c1c019fdb8c0c15 + url: "https://pub.dev" + source: hosted + version: "1.1.2" characters: dependency: transitive description: @@ -1202,6 +1218,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.15.4" + html_unescape: + dependency: transitive + description: + name: html_unescape + sha256: "15362d7a18f19d7b742ef8dcb811f5fd2a2df98db9f80ea393c075189e0b61e3" + url: "https://pub.dev" + source: hosted + version: "2.0.0" http: dependency: "direct main" description: @@ -1481,6 +1505,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.3" + markdown: + dependency: transitive + description: + name: markdown + sha256: "01512006c8429f604eb10f9848717baeaedf99e991d14a50d540d9beff08e5c6" + url: "https://pub.dev" + source: hosted + version: "4.0.1" matcher: dependency: transitive description: @@ -1675,6 +1707,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.2" + olm: + dependency: transitive + description: + name: olm + sha256: "37948a6576949256f3ee1d0063d5b408634ff7e452b9a5c2f6410f9d7ced1c20" + url: "https://pub.dev" + source: hosted + version: "2.0.3" open_file: dependency: "direct main" description: @@ -2003,6 +2043,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.1" + random_string: + dependency: transitive + description: + name: random_string + sha256: "03b52435aae8cbdd1056cf91bfc5bf845e9706724dd35ae2e99fa14a1ef79d02" + url: "https://pub.dev" + source: hosted + version: "2.3.1" receive_sharing_intent: dependency: "direct main" description: @@ -2140,6 +2188,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.1" + sdp_transform: + dependency: transitive + description: + name: sdp_transform + sha256: "73e412a5279a5c2de74001535208e20fff88f225c9a4571af0f7146202755e45" + url: "https://pub.dev" + source: hosted + version: "0.3.2" sentiment_dart: dependency: transitive description: