search: update available filter on source change

This commit is contained in:
Thibault Deckers 2020-05-11 12:12:34 +09:00
parent 0ab594f6ab
commit 445938435c
2 changed files with 46 additions and 20 deletions

View file

@ -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<String>.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<ImageEntry> entries) {
@ -159,6 +162,12 @@ class AddressMetadataChangedEvent {}
class CatalogMetadataChangedEvent {}
class AlbumsChangedEvent {}
class LocationsChangedEvent {}
class TagsChangedEvent {}
class EntryAddedEvent {
final ImageEntry entry;

View file

@ -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<CollectionFilter> {
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<AlbumsChangedEvent>(),
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<LocationsChangedEvent>(),
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<LocationsChangedEvent>(),
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<TagsChangedEvent>(),
builder: (context, snapshot) {
return _buildFilterRow(
context: context,
title: 'Tags',
filters: source.sortedTags.where(containQuery).map((s) => TagFilter(s)),
);
}),
],
);
}),