@ -87,15 +87,23 @@ class SortFilterMenu<T> extends StatelessWidget {
}
}
}
}
const int _actionSortRecentMessages = 1 ;
sealed class _ContactsFilterAction {
const int _actionSortName = 2 ;
const _ContactsFilterAction ( ) ;
const int _actionSortLastSeen = 3 ;
}
const int _actionFilterAll = 4 ;
const int _actionFilterFavorites = 5 ;
class _SortAction extends _ContactsFilterAction {
const int _actionFilterUsers = 6 ;
final ContactSortOption option ;
const int _actionFilterRepeaters = 7 ;
const _SortAction ( this . option ) ;
const int _actionFilterRooms = 8 ;
}
const int _actionToggleUnreadOnly = 9 ;
class _TypeFilterAction extends _ContactsFilterAction {
final ContactTypeFilter filter ;
const _TypeFilterAction ( this . filter ) ;
}
class _ToggleUnreadAction extends _ContactsFilterAction {
const _ToggleUnreadAction ( ) ;
}
class ContactsFilterMenu extends StatelessWidget {
class ContactsFilterMenu extends StatelessWidget {
final ContactSortOption sortOption ;
final ContactSortOption sortOption ;
@ -118,24 +126,24 @@ class ContactsFilterMenu extends StatelessWidget {
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
final l10n = context . l10n ;
final l10n = context . l10n ;
return SortFilterMenu (
return SortFilterMenu < _ContactsFilterAction > (
tooltip: l10n . listFilter_tooltip ,
tooltip: l10n . listFilter_tooltip ,
sections: [
sections: [
SortFilterMenuSection (
SortFilterMenuSection (
title: l10n . listFilter_sortBy ,
title: l10n . listFilter_sortBy ,
options: [
options: [
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionSortRecentMessages ,
value: _ SortAction( ContactSortOption . recentMessages ) ,
label: l10n . listFilter_latestMessages ,
label: l10n . listFilter_latestMessages ,
checked: sortOption = = ContactSortOption . recentMessages ,
checked: sortOption = = ContactSortOption . recentMessages ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionSortLastSeen ,
value: _ SortAction( ContactSortOption . lastSeen ) ,
label: l10n . listFilter_heardRecently ,
label: l10n . listFilter_heardRecently ,
checked: sortOption = = ContactSortOption . lastSeen ,
checked: sortOption = = ContactSortOption . lastSeen ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionSortName ,
value: _ SortAction( ContactSortOption . name ) ,
label: l10n . listFilter_az ,
label: l10n . listFilter_az ,
checked: sortOption = = ContactSortOption . name ,
checked: sortOption = = ContactSortOption . name ,
) ,
) ,
@ -145,32 +153,32 @@ class ContactsFilterMenu extends StatelessWidget {
title: l10n . listFilter_filters ,
title: l10n . listFilter_filters ,
options: [
options: [
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterAll ,
value: _ TypeFilterAction( ContactTypeFilter . all ) ,
label: l10n . listFilter_all ,
label: l10n . listFilter_all ,
checked: typeFilter = = ContactTypeFilter . all ,
checked: typeFilter = = ContactTypeFilter . all ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterFavorites ,
value: _ TypeFilterAction( ContactTypeFilter . favorites ) ,
label: l10n . listFilter_favorites ,
label: l10n . listFilter_favorites ,
checked: typeFilter = = ContactTypeFilter . favorites ,
checked: typeFilter = = ContactTypeFilter . favorites ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterUsers ,
value: _ TypeFilterAction( ContactTypeFilter . users ) ,
label: l10n . listFilter_users ,
label: l10n . listFilter_users ,
checked: typeFilter = = ContactTypeFilter . users ,
checked: typeFilter = = ContactTypeFilter . users ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterRepeaters ,
value: _ TypeFilterAction( ContactTypeFilter . repeaters ) ,
label: l10n . listFilter_repeaters ,
label: l10n . listFilter_repeaters ,
checked: typeFilter = = ContactTypeFilter . repeaters ,
checked: typeFilter = = ContactTypeFilter . repeaters ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterRooms ,
value: _ TypeFilterAction( ContactTypeFilter . rooms ) ,
label: l10n . listFilter_roomServers ,
label: l10n . listFilter_roomServers ,
checked: typeFilter = = ContactTypeFilter . rooms ,
checked: typeFilter = = ContactTypeFilter . rooms ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _actionToggleUnreadOnly ,
value: const _ToggleUnreadAction ( ) ,
label: l10n . listFilter_unreadOnly ,
label: l10n . listFilter_unreadOnly ,
checked: showUnreadOnly ,
checked: showUnreadOnly ,
) ,
) ,
@ -179,39 +187,32 @@ class ContactsFilterMenu extends StatelessWidget {
] ,
] ,
onSelected: ( action ) {
onSelected: ( action ) {
switch ( action ) {
switch ( action ) {
case _actionSortRecentMessages:
case _SortAction ( : final option ) :
onSortChanged ( ContactSortOption . recentMessages ) ;
onSortChanged ( option ) ;
break ;
case _TypeFilterAction ( : final filter ) :
case _actionSortName:
onTypeFilterChanged ( filter ) ;
onSortChanged ( ContactSortOption . name ) ;
case _ToggleUnreadAction ( ) :
break ;
case _actionSortLastSeen:
onSortChanged ( ContactSortOption . lastSeen ) ;
break ;
case _actionFilterAll:
onTypeFilterChanged ( ContactTypeFilter . all ) ;
break ;
case _actionFilterUsers:
onTypeFilterChanged ( ContactTypeFilter . users ) ;
break ;
case _actionFilterFavorites:
onTypeFilterChanged ( ContactTypeFilter . favorites ) ;
break ;
case _actionFilterRepeaters:
onTypeFilterChanged ( ContactTypeFilter . repeaters ) ;
break ;
case _actionFilterRooms:
onTypeFilterChanged ( ContactTypeFilter . rooms ) ;
break ;
case _actionToggleUnreadOnly:
onUnreadOnlyChanged ( ! showUnreadOnly ) ;
onUnreadOnlyChanged ( ! showUnreadOnly ) ;
break ;
}
}
} ,
} ,
) ;
) ;
}
}
}
}
sealed class _DiscoveryFilterAction {
const _DiscoveryFilterAction ( ) ;
}
class _DiscoverySortAction extends _DiscoveryFilterAction {
final ContactSortOption option ;
const _DiscoverySortAction ( this . option ) ;
}
class _DiscoveryTypeFilterAction extends _DiscoveryFilterAction {
final ContactTypeFilter filter ;
const _DiscoveryTypeFilterAction ( this . filter ) ;
}
class DiscoveryContactsFilterMenu extends StatelessWidget {
class DiscoveryContactsFilterMenu extends StatelessWidget {
final ContactSortOption sortOption ;
final ContactSortOption sortOption ;
final ContactTypeFilter typeFilter ;
final ContactTypeFilter typeFilter ;
@ -229,19 +230,19 @@ class DiscoveryContactsFilterMenu extends StatelessWidget {
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
final l10n = context . l10n ;
final l10n = context . l10n ;
return SortFilterMenu (
return SortFilterMenu < _DiscoveryFilterAction > (
tooltip: l10n . listFilter_tooltip ,
tooltip: l10n . listFilter_tooltip ,
sections: [
sections: [
SortFilterMenuSection (
SortFilterMenuSection (
title: l10n . listFilter_sortBy ,
title: l10n . listFilter_sortBy ,
options: [
options: [
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionSortLastSeen ,
value: _ DiscoverySortAction( ContactSortOption . lastSeen ) ,
label: l10n . listFilter_heardRecently ,
label: l10n . listFilter_heardRecently ,
checked: sortOption = = ContactSortOption . lastSeen ,
checked: sortOption = = ContactSortOption . lastSeen ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionSortName ,
value: _ DiscoverySortAction( ContactSortOption . name ) ,
label: l10n . listFilter_az ,
label: l10n . listFilter_az ,
checked: sortOption = = ContactSortOption . name ,
checked: sortOption = = ContactSortOption . name ,
) ,
) ,
@ -251,22 +252,22 @@ class DiscoveryContactsFilterMenu extends StatelessWidget {
title: l10n . listFilter_filters ,
title: l10n . listFilter_filters ,
options: [
options: [
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterAll ,
value: _ DiscoveryTypeFilterAction( ContactTypeFilter . all ) ,
label: l10n . listFilter_all ,
label: l10n . listFilter_all ,
checked: typeFilter = = ContactTypeFilter . all ,
checked: typeFilter = = ContactTypeFilter . all ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterUsers ,
value: _ DiscoveryTypeFilterAction( ContactTypeFilter . users ) ,
label: l10n . listFilter_users ,
label: l10n . listFilter_users ,
checked: typeFilter = = ContactTypeFilter . users ,
checked: typeFilter = = ContactTypeFilter . users ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterRepeaters ,
value: _ DiscoveryTypeFilterAction( ContactTypeFilter . repeaters ) ,
label: l10n . listFilter_repeaters ,
label: l10n . listFilter_repeaters ,
checked: typeFilter = = ContactTypeFilter . repeaters ,
checked: typeFilter = = ContactTypeFilter . repeaters ,
) ,
) ,
SortFilterMenuOption (
SortFilterMenuOption (
value: _ actionFilterRooms ,
value: _ DiscoveryTypeFilterAction( ContactTypeFilter . rooms ) ,
label: l10n . listFilter_roomServers ,
label: l10n . listFilter_roomServers ,
checked: typeFilter = = ContactTypeFilter . rooms ,
checked: typeFilter = = ContactTypeFilter . rooms ,
) ,
) ,
@ -275,27 +276,10 @@ class DiscoveryContactsFilterMenu extends StatelessWidget {
] ,
] ,
onSelected: ( action ) {
onSelected: ( action ) {
switch ( action ) {
switch ( action ) {
case _actionSortName:
case _DiscoverySortAction ( : final option ) :
onSortChanged ( ContactSortOption . name ) ;
onSortChanged ( option ) ;
break ;
case _DiscoveryTypeFilterAction ( : final filter ) :
case _actionSortLastSeen:
onTypeFilterChanged ( filter ) ;
onSortChanged ( ContactSortOption . lastSeen ) ;
break ;
case _actionFilterAll:
onTypeFilterChanged ( ContactTypeFilter . all ) ;
break ;
case _actionFilterUsers:
onTypeFilterChanged ( ContactTypeFilter . users ) ;
break ;
case _actionFilterFavorites:
onTypeFilterChanged ( ContactTypeFilter . favorites ) ;
break ;
case _actionFilterRepeaters:
onTypeFilterChanged ( ContactTypeFilter . repeaters ) ;
break ;
case _actionFilterRooms:
onTypeFilterChanged ( ContactTypeFilter . rooms ) ;
break ;
}
}
} ,
} ,
) ;
) ;