collection: fixed sort/group on settings change
This commit is contained in:
parent
e2166bd15a
commit
b704d72c9d
7 changed files with 34 additions and 38 deletions
|
@ -35,27 +35,27 @@ class CollectionLens with ChangeNotifier, CollectionActivityMixin {
|
|||
CollectionLens({
|
||||
required this.source,
|
||||
Iterable<CollectionFilter?>? filters,
|
||||
EntryGroupFactor? groupFactor,
|
||||
EntrySortFactor? sortFactor,
|
||||
this.id,
|
||||
this.listenToSource = true,
|
||||
}) : filters = (filters ?? {}).where((f) => f != null).cast<CollectionFilter>().toSet(),
|
||||
groupFactor = groupFactor ?? settings.collectionGroupFactor,
|
||||
sortFactor = sortFactor ?? settings.collectionSortFactor {
|
||||
groupFactor = settings.collectionGroupFactor,
|
||||
sortFactor = settings.collectionSortFactor {
|
||||
id ??= hashCode;
|
||||
if (listenToSource) {
|
||||
_subscriptions.add(source.eventBus.on<EntryAddedEvent>().listen((e) => onEntryAdded(e.entries)));
|
||||
_subscriptions.add(source.eventBus.on<EntryRemovedEvent>().listen((e) => onEntryRemoved(e.entries)));
|
||||
_subscriptions.add(source.eventBus.on<EntryMovedEvent>().listen((e) => _refresh()));
|
||||
_subscriptions.add(source.eventBus.on<FilterVisibilityChangedEvent>().listen((e) => _refresh()));
|
||||
_subscriptions.add(source.eventBus.on<CatalogMetadataChangedEvent>().listen((e) => _refresh()));
|
||||
_subscriptions.add(source.eventBus.on<AddressMetadataChangedEvent>().listen((e) {
|
||||
final sourceEvents = source.eventBus;
|
||||
_subscriptions.add(sourceEvents.on<EntryAddedEvent>().listen((e) => onEntryAdded(e.entries)));
|
||||
_subscriptions.add(sourceEvents.on<EntryRemovedEvent>().listen((e) => onEntryRemoved(e.entries)));
|
||||
_subscriptions.add(sourceEvents.on<EntryMovedEvent>().listen((e) => _refresh()));
|
||||
_subscriptions.add(sourceEvents.on<FilterVisibilityChangedEvent>().listen((e) => _refresh()));
|
||||
_subscriptions.add(sourceEvents.on<CatalogMetadataChangedEvent>().listen((e) => _refresh()));
|
||||
_subscriptions.add(sourceEvents.on<AddressMetadataChangedEvent>().listen((e) {
|
||||
if (this.filters.any((filter) => filter is LocationFilter)) {
|
||||
_refresh();
|
||||
}
|
||||
}));
|
||||
favourites.addListener(onFavouritesChanged);
|
||||
favourites.addListener(_onFavouritesChanged);
|
||||
}
|
||||
settings.addListener(_onSettingsChanged);
|
||||
_refresh();
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,8 @@ class CollectionLens with ChangeNotifier, CollectionActivityMixin {
|
|||
_subscriptions
|
||||
..forEach((sub) => sub.cancel())
|
||||
..clear();
|
||||
favourites.removeListener(onFavouritesChanged);
|
||||
favourites.removeListener(_onFavouritesChanged);
|
||||
settings.addListener(_onSettingsChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -112,19 +113,6 @@ class CollectionLens with ChangeNotifier, CollectionActivityMixin {
|
|||
filterChangeNotifier.notifyListeners();
|
||||
}
|
||||
|
||||
void sort(EntrySortFactor sortFactor) {
|
||||
this.sortFactor = sortFactor;
|
||||
_applySort();
|
||||
_applyGroup();
|
||||
sortGroupChangeNotifier.notifyListeners();
|
||||
}
|
||||
|
||||
void group(EntryGroupFactor groupFactor) {
|
||||
this.groupFactor = groupFactor;
|
||||
_applyGroup();
|
||||
sortGroupChangeNotifier.notifyListeners();
|
||||
}
|
||||
|
||||
void _applyFilters() {
|
||||
final entries = source.visibleEntries;
|
||||
_filteredSortedEntries = List.of(filters.isEmpty ? entries : entries.where((entry) => filters.every((filter) => filter.test(entry))));
|
||||
|
@ -187,12 +175,32 @@ class CollectionLens with ChangeNotifier, CollectionActivityMixin {
|
|||
_applyGroup();
|
||||
}
|
||||
|
||||
void onFavouritesChanged() {
|
||||
void _onFavouritesChanged() {
|
||||
if (filters.any((filter) => filter is FavouriteFilter)) {
|
||||
_refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void _onSettingsChanged() {
|
||||
final newSortFactor = settings.collectionSortFactor;
|
||||
final newGroupFactor = settings.collectionGroupFactor;
|
||||
|
||||
final needSort = sortFactor != newSortFactor;
|
||||
final needGroup = needSort || groupFactor != newGroupFactor;
|
||||
|
||||
if (needSort) {
|
||||
sortFactor = newSortFactor;
|
||||
_applySort();
|
||||
}
|
||||
if (needGroup) {
|
||||
groupFactor = newGroupFactor;
|
||||
_applyGroup();
|
||||
}
|
||||
if (needSort || needGroup) {
|
||||
sortGroupChangeNotifier.notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void onEntryAdded(Set<AvesEntry>? entries) {
|
||||
_refresh();
|
||||
}
|
||||
|
|
|
@ -321,7 +321,6 @@ class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerPr
|
|||
await Future.delayed(Durations.dialogTransitionAnimation * timeDilation);
|
||||
if (value != null) {
|
||||
settings.collectionGroupFactor = value;
|
||||
collection.group(value);
|
||||
}
|
||||
break;
|
||||
case CollectionAction.sort:
|
||||
|
@ -341,7 +340,6 @@ class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerPr
|
|||
await Future.delayed(Durations.dialogTransitionAnimation * timeDilation);
|
||||
if (value != null) {
|
||||
settings.collectionSortFactor = value;
|
||||
collection.sort(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -148,8 +148,6 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware
|
|||
targetCollection = CollectionLens(
|
||||
source: collection.source,
|
||||
filters: collection.filters,
|
||||
groupFactor: collection.groupFactor,
|
||||
sortFactor: collection.sortFactor,
|
||||
)..addFilter(filter);
|
||||
unawaited(Navigator.pushReplacement(
|
||||
context,
|
||||
|
|
|
@ -71,8 +71,6 @@ class InteractiveThumbnail extends StatelessWidget {
|
|||
final viewerCollection = CollectionLens(
|
||||
source: collection.source,
|
||||
filters: collection.filters,
|
||||
groupFactor: collection.groupFactor,
|
||||
sortFactor: collection.sortFactor,
|
||||
id: collection.id,
|
||||
listenToSource: false,
|
||||
);
|
||||
|
|
|
@ -221,8 +221,6 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
|||
final targetCollection = CollectionLens(
|
||||
source: source,
|
||||
filters: {AlbumFilter(destinationAlbum, source.getAlbumDisplayName(context, destinationAlbum))},
|
||||
groupFactor: _collection.groupFactor,
|
||||
sortFactor: _collection.sortFactor,
|
||||
);
|
||||
unawaited(Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
|
|
|
@ -401,8 +401,6 @@ class _EntryViewerStackState extends State<EntryViewerStack> with SingleTickerPr
|
|||
collection: CollectionLens(
|
||||
source: baseCollection.source,
|
||||
filters: baseCollection.filters,
|
||||
groupFactor: baseCollection.groupFactor,
|
||||
sortFactor: baseCollection.sortFactor,
|
||||
)..addFilter(filter),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -96,8 +96,6 @@ class VideoActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
|||
final targetCollection = CollectionLens(
|
||||
source: source,
|
||||
filters: {AlbumFilter(destinationAlbum, source.getAlbumDisplayName(context, destinationAlbum))},
|
||||
groupFactor: _collection.groupFactor,
|
||||
sortFactor: _collection.sortFactor,
|
||||
);
|
||||
unawaited(Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
|
|
Loading…
Reference in a new issue