mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-22 00:31:04 +10:00
Correct unread badges for tabs; people first contacts sort option
This commit is contained in:
@@ -343,6 +343,8 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
selectedIndex: 1,
|
||||
onDestinationSelected: (index) =>
|
||||
_handleQuickSwitch(index, context),
|
||||
contactsUnreadCount: connector.getTotalContactsUnreadCount(),
|
||||
channelsUnreadCount: connector.getTotalChannelsUnreadCount(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -48,6 +48,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
String _searchQuery = '';
|
||||
ContactSortOption _sortOption = ContactSortOption.lastSeen;
|
||||
bool _showUnreadOnly = false;
|
||||
bool _prioritizePeople = true;
|
||||
ContactTypeFilter _typeFilter = ContactTypeFilter.all;
|
||||
final ContactGroupStore _groupStore = ContactGroupStore();
|
||||
List<ContactGroup> _groups = [];
|
||||
@@ -332,6 +333,8 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
selectedIndex: 0,
|
||||
onDestinationSelected: (index) =>
|
||||
_handleQuickSwitch(index, context),
|
||||
contactsUnreadCount: connector.getTotalContactsUnreadCount(),
|
||||
channelsUnreadCount: connector.getTotalChannelsUnreadCount(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -350,6 +353,7 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
sortOption: _sortOption,
|
||||
typeFilter: _typeFilter,
|
||||
showUnreadOnly: _showUnreadOnly,
|
||||
prioritizePeople: _prioritizePeople,
|
||||
onSortChanged: (value) {
|
||||
setState(() {
|
||||
_sortOption = value;
|
||||
@@ -365,6 +369,11 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
_showUnreadOnly = value;
|
||||
});
|
||||
},
|
||||
onPrioritizePeopleChanged: (value) {
|
||||
setState(() {
|
||||
_prioritizePeople = value;
|
||||
});
|
||||
},
|
||||
onNewGroup: () => _showGroupEditor(context, connector.contacts),
|
||||
);
|
||||
}
|
||||
@@ -545,14 +554,34 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// Apply sorting within groups if prioritizing people
|
||||
if (_prioritizePeople) {
|
||||
// Separate people (advTypeChat) from others
|
||||
final people = filtered.where((c) => c.type == advTypeChat).toList();
|
||||
final others = filtered.where((c) => c.type != advTypeChat).toList();
|
||||
|
||||
// Sort each group separately
|
||||
_applySorting(people, connector);
|
||||
_applySorting(others, connector);
|
||||
|
||||
// Combine: people first, then others
|
||||
filtered = [...people, ...others];
|
||||
} else {
|
||||
_applySorting(filtered, connector);
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
void _applySorting(List<Contact> contacts, MeshCoreConnector connector) {
|
||||
switch (_sortOption) {
|
||||
case ContactSortOption.lastSeen:
|
||||
filtered.sort(
|
||||
contacts.sort(
|
||||
(a, b) => _resolveLastSeen(b).compareTo(_resolveLastSeen(a)),
|
||||
);
|
||||
break;
|
||||
case ContactSortOption.recentMessages:
|
||||
filtered.sort((a, b) {
|
||||
contacts.sort((a, b) {
|
||||
final aMessages = connector.getMessages(a);
|
||||
final bMessages = connector.getMessages(b);
|
||||
final aLastMsg = aMessages.isEmpty
|
||||
@@ -565,13 +594,11 @@ class _ContactsScreenState extends State<ContactsScreen>
|
||||
});
|
||||
break;
|
||||
case ContactSortOption.name:
|
||||
filtered.sort(
|
||||
contacts.sort(
|
||||
(a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()),
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
bool _matchesTypeFilter(Contact contact) {
|
||||
|
||||
@@ -71,7 +71,7 @@ class _DeviceScreenState extends State<DeviceScreen>
|
||||
const SizedBox(height: 16),
|
||||
_buildSectionLabel(theme, context.l10n.device_quickSwitch),
|
||||
const SizedBox(height: 12),
|
||||
_buildQuickSwitchBar(context),
|
||||
_buildQuickSwitchBar(context, connector),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -196,12 +196,14 @@ class _DeviceScreenState extends State<DeviceScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuickSwitchBar(BuildContext context) {
|
||||
Widget _buildQuickSwitchBar(BuildContext context, MeshCoreConnector connector) {
|
||||
return QuickSwitchBar(
|
||||
selectedIndex: _quickIndex,
|
||||
onDestinationSelected: (index) {
|
||||
_openQuickDestination(index, context);
|
||||
},
|
||||
contactsUnreadCount: connector.getTotalContactsUnreadCount(),
|
||||
channelsUnreadCount: connector.getTotalChannelsUnreadCount(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -362,6 +362,8 @@ class _MapScreenState extends State<MapScreen> {
|
||||
selectedIndex: 2,
|
||||
onDestinationSelected: (index) =>
|
||||
_handleQuickSwitch(index, context),
|
||||
contactsUnreadCount: connector.getTotalContactsUnreadCount(),
|
||||
channelsUnreadCount: connector.getTotalChannelsUnreadCount(),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
|
||||
Reference in New Issue
Block a user