From 8052347895d809963a8d493a3f85e0051681d9a2 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 28 Sep 2020 12:10:37 +0900 Subject: [PATCH] fixed freeze after deleting multiple entries --- lib/model/source/album.dart | 6 ++++++ lib/model/source/collection_source.dart | 2 +- .../common/action_delegates/selection_action_delegate.dart | 4 ++-- lib/widgets/filter_grids/common/chip_action_delegate.dart | 6 ++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/model/source/album.dart b/lib/model/source/album.dart index 3369ed290..c9256ed4f 100644 --- a/lib/model/source/album.dart +++ b/lib/model/source/album.dart @@ -1,4 +1,6 @@ +import 'package:aves/model/filters/album.dart'; import 'package:aves/model/image_entry.dart'; +import 'package:aves/model/settings/settings.dart'; import 'package:aves/model/source/collection_source.dart'; import 'package:aves/utils/android_file_utils.dart'; import 'package:collection/collection.dart'; @@ -67,6 +69,10 @@ mixin AlbumMixin on SourceBase { if (emptyAlbums.isNotEmpty) { _folderPaths.removeAll(emptyAlbums); updateAlbums(); + + final pinnedFilters = settings.pinnedFilters; + emptyAlbums.forEach((album) => pinnedFilters.remove(AlbumFilter(album, getUniqueAlbumName(album)))); + settings.pinnedFilters = pinnedFilters; } } diff --git a/lib/model/source/collection_source.dart b/lib/model/source/collection_source.dart index 3ef329b02..d3c80fe7a 100644 --- a/lib/model/source/collection_source.dart +++ b/lib/model/source/collection_source.dart @@ -70,7 +70,7 @@ class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagMixin { eventBus.fire(EntryAddedEvent()); } - void removeEntries(Iterable entries) { + void removeEntries(List entries) { entries.forEach((entry) => entry.removeFromFavourites()); _rawEntries.removeWhere(entries.contains); cleanEmptyAlbums(entries.map((entry) => entry.directory).toSet()); diff --git a/lib/widgets/common/action_delegates/selection_action_delegate.dart b/lib/widgets/common/action_delegates/selection_action_delegate.dart index a02ee9890..0c5788712 100644 --- a/lib/widgets/common/action_delegates/selection_action_delegate.dart +++ b/lib/widgets/common/action_delegates/selection_action_delegate.dart @@ -169,7 +169,7 @@ class SelectionActionDelegate with FeedbackMixin, PermissionAwareMixin { selection: selection, opStream: ImageFileService.delete(selection), onDone: (processed) { - final deletedUris = processed.where((e) => e.success).map((e) => e.uri); + final deletedUris = processed.where((e) => e.success).map((e) => e.uri).toList(); final deletedCount = deletedUris.length; final selectionCount = selection.length; if (deletedCount < selectionCount) { @@ -177,7 +177,7 @@ class SelectionActionDelegate with FeedbackMixin, PermissionAwareMixin { showFeedback(context, 'Failed to delete ${Intl.plural(count, one: '$count item', other: '$count items')}'); } if (deletedCount > 0) { - collection.source.removeEntries(selection.where((e) => deletedUris.contains(e.uri))); + collection.source.removeEntries(selection.where((e) => deletedUris.contains(e.uri)).toList()); } collection.clearSelection(); collection.browse(); diff --git a/lib/widgets/filter_grids/common/chip_action_delegate.dart b/lib/widgets/filter_grids/common/chip_action_delegate.dart index d1f2ecfb0..56b518752 100644 --- a/lib/widgets/filter_grids/common/chip_action_delegate.dart +++ b/lib/widgets/filter_grids/common/chip_action_delegate.dart @@ -86,17 +86,15 @@ class AlbumChipActionDelegate extends ChipActionDelegate with FeedbackMixin, Per selection: selection, opStream: ImageFileService.delete(selection), onDone: (processed) { - final deletedUris = processed.where((e) => e.success).map((e) => e.uri); + final deletedUris = processed.where((e) => e.success).map((e) => e.uri).toList(); final deletedCount = deletedUris.length; final selectionCount = selection.length; if (deletedCount < selectionCount) { final count = selectionCount - deletedCount; showFeedback(context, 'Failed to delete ${Intl.plural(count, one: '$count item', other: '$count items')}'); - } else { - settings.pinnedFilters = settings.pinnedFilters..remove(filter); } if (deletedCount > 0) { - source.removeEntries(selection.where((e) => deletedUris.contains(e.uri))); + source.removeEntries(selection.where((e) => deletedUris.contains(e.uri)).toList()); } }, );