From e12debeff97d84338439dfba6f7184c6bbc74ca8 Mon Sep 17 00:00:00 2001 From: ericz Date: Sat, 28 Mar 2026 13:32:18 +0100 Subject: [PATCH] add chat filter list, more space for search bar. --- lib/screens/contacts_screen.dart | 29 +++++++++++++++++++++++------ lib/screens/discovery_screen.dart | 8 ++++++++ lib/utils/contact_filter_types.dart | 2 +- lib/widgets/list_filter_widget.dart | 5 +++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/screens/contacts_screen.dart b/lib/screens/contacts_screen.dart index 54d3299..24dffad 100644 --- a/lib/screens/contacts_screen.dart +++ b/lib/screens/contacts_screen.dart @@ -672,6 +672,14 @@ class _ContactsScreenState extends State : "", ); break; + case ContactTypeFilter.chat: + hintText = context.l10n.contacts_searchContacts( + filteredAndSorted.length, + viewState.contactsShowUnreadOnly + ? " ${context.l10n.contacts_unread}" + : "", + ); + break; } final groupsByName = {}; @@ -682,13 +690,13 @@ class _ContactsScreenState extends State ..sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase())); final screenWidth = MediaQuery.sizeOf(context).width; - final searchExpandedWidth = (screenWidth * 0.52).clamp( + final searchExpandedWidth = (screenWidth * 0.72).clamp( 97.0, double.infinity, - ); // allow expansion up to 52% of screen width, but not less than the collapsed width + ); // allow expansion up to 72% of screen width, but not less than the collapsed width final searchCollapsedWidth = (screenWidth * 0.22).clamp( 97.0, - 120.0, + 97.0, ); //two 48px icon buttons + 1px divider return Column( @@ -860,8 +868,11 @@ class _ContactsScreenState extends State if (viewState.contactsTypeFilter != ContactTypeFilter.all) { filtered = filtered .where( - (contact) => - _matchesTypeFilter(contact, viewState.contactsTypeFilter), + (contact) => _matchesTypeFilter( + contact, + viewState.contactsTypeFilter, + connector, + ), ) .toList(); } @@ -901,7 +912,11 @@ class _ContactsScreenState extends State return filtered; } - bool _matchesTypeFilter(Contact contact, ContactTypeFilter typeFilter) { + bool _matchesTypeFilter( + Contact contact, + ContactTypeFilter typeFilter, + MeshCoreConnector connector, + ) { switch (typeFilter) { case ContactTypeFilter.all: return true; @@ -913,6 +928,8 @@ class _ContactsScreenState extends State return contact.type == advTypeRepeater; case ContactTypeFilter.rooms: return contact.type == advTypeRoom; + case ContactTypeFilter.chat: + return connector.getMessages(contact).isNotEmpty; } } diff --git a/lib/screens/discovery_screen.dart b/lib/screens/discovery_screen.dart index f9f0e07..c4f41cb 100644 --- a/lib/screens/discovery_screen.dart +++ b/lib/screens/discovery_screen.dart @@ -306,6 +306,12 @@ class _DiscoveryScreenState extends State { showUnreadOnly ? " ${context.l10n.contacts_unread}" : "", ); break; + case ContactTypeFilter.chat: + hintText = context.l10n.contacts_searchContacts( + filteredAndSorted.length, + showUnreadOnly ? " ${context.l10n.contacts_unread}" : "", + ); + break; } return Column( @@ -424,6 +430,8 @@ class _DiscoveryScreenState extends State { return contact.type == advTypeRepeater; case ContactTypeFilter.rooms: return contact.type == advTypeRoom; + case ContactTypeFilter.chat: + return false; default: return false; } diff --git a/lib/utils/contact_filter_types.dart b/lib/utils/contact_filter_types.dart index 08e07c2..cdab35f 100644 --- a/lib/utils/contact_filter_types.dart +++ b/lib/utils/contact_filter_types.dart @@ -1,3 +1,3 @@ enum ContactSortOption { lastSeen, recentMessages, name } -enum ContactTypeFilter { all, favorites, users, repeaters, rooms } +enum ContactTypeFilter { all, favorites, users, repeaters, rooms, chat } diff --git a/lib/widgets/list_filter_widget.dart b/lib/widgets/list_filter_widget.dart index c4fd5aa..0076fc6 100644 --- a/lib/widgets/list_filter_widget.dart +++ b/lib/widgets/list_filter_widget.dart @@ -177,6 +177,11 @@ class ContactsFilterMenu extends StatelessWidget { label: l10n.listFilter_roomServers, checked: typeFilter == ContactTypeFilter.rooms, ), + SortFilterMenuOption( + value: _TypeFilterAction(ContactTypeFilter.chat), + label: l10n.map_chat, + checked: typeFilter == ContactTypeFilter.chat, + ), SortFilterMenuOption( value: const _ToggleUnreadAction(), label: l10n.listFilter_unreadOnly,