diff --git a/lib/model/collection_source.dart b/lib/model/collection_source.dart index 783683fdc..06a012e77 100644 --- a/lib/model/collection_source.dart +++ b/lib/model/collection_source.dart @@ -114,11 +114,13 @@ class CollectionSource { return compareAsciiUpperCase(ua, ub); }); sortedAlbums = List.unmodifiable(sorted); + eventBus.fire(AlbumsChangedEvent()); } void updateTags() { final tags = _rawEntries.expand((entry) => entry.xmpSubjects).toSet().toList()..sort(compareAsciiUpperCase); sortedTags = List.unmodifiable(tags); + eventBus.fire(TagsChangedEvent()); } void updateLocations() { @@ -126,6 +128,7 @@ class CollectionSource { final lister = (String Function(AddressDetails a) f) => List.unmodifiable(locations.map(f).where((s) => s != null && s.isNotEmpty).toSet().toList()..sort(compareAsciiUpperCase)); sortedCountries = lister((address) => '${address.countryName};${address.countryCode}'); sortedPlaces = lister((address) => address.place); + eventBus.fire(LocationsChangedEvent()); } void addAll(Iterable entries) { @@ -159,6 +162,12 @@ class AddressMetadataChangedEvent {} class CatalogMetadataChangedEvent {} +class AlbumsChangedEvent {} + +class LocationsChangedEvent {} + +class TagsChangedEvent {} + class EntryAddedEvent { final ImageEntry entry; diff --git a/lib/widgets/album/search/search_delegate.dart b/lib/widgets/album/search/search_delegate.dart index c5fbcca6c..288d56908 100644 --- a/lib/widgets/album/search/search_delegate.dart +++ b/lib/widgets/album/search/search_delegate.dart @@ -1,4 +1,5 @@ import 'package:aves/model/collection_lens.dart'; +import 'package:aves/model/collection_source.dart'; import 'package:aves/model/filters/album.dart'; import 'package:aves/model/filters/favourite.dart'; import 'package:aves/model/filters/filters.dart'; @@ -70,26 +71,42 @@ class ImageSearchDelegate extends SearchDelegate { MimeFilter(MimeTypes.SVG), ].where((f) => containQuery(f.label)), ), - _buildFilterRow( - context: context, - title: 'Albums', - filters: source.sortedAlbums.where(containQuery).map((s) => AlbumFilter(s, source.getUniqueAlbumName(s))).where((f) => containQuery(f.uniqueName)), - ), - _buildFilterRow( - context: context, - title: 'Countries', - filters: source.sortedCountries.where(containQuery).map((s) => LocationFilter(LocationLevel.country, s)), - ), - _buildFilterRow( - context: context, - title: 'Places', - filters: source.sortedPlaces.where(containQuery).map((s) => LocationFilter(LocationLevel.place, s)), - ), - _buildFilterRow( - context: context, - title: 'Tags', - filters: source.sortedTags.where(containQuery).map((s) => TagFilter(s)), - ), + StreamBuilder( + stream: source.eventBus.on(), + builder: (context, snapshot) { + return _buildFilterRow( + context: context, + title: 'Albums', + filters: source.sortedAlbums.where(containQuery).map((s) => AlbumFilter(s, source.getUniqueAlbumName(s))).where((f) => containQuery(f.uniqueName)), + ); + }), + StreamBuilder( + stream: source.eventBus.on(), + builder: (context, snapshot) { + return _buildFilterRow( + context: context, + title: 'Countries', + filters: source.sortedCountries.where(containQuery).map((s) => LocationFilter(LocationLevel.country, s)), + ); + }), + StreamBuilder( + stream: source.eventBus.on(), + builder: (context, snapshot) { + return _buildFilterRow( + context: context, + title: 'Places', + filters: source.sortedPlaces.where(containQuery).map((s) => LocationFilter(LocationLevel.place, s)), + ); + }), + StreamBuilder( + stream: source.eventBus.on(), + builder: (context, snapshot) { + return _buildFilterRow( + context: context, + title: 'Tags', + filters: source.sortedTags.where(containQuery).map((s) => TagFilter(s)), + ); + }), ], ); }),