diff --git a/lib/widgets/collection/app_bar.dart b/lib/widgets/collection/app_bar.dart index fe3e18bb0..f9d3e38cd 100644 --- a/lib/widgets/collection/app_bar.dart +++ b/lib/widgets/collection/app_bar.dart @@ -46,7 +46,7 @@ class CollectionAppBar extends StatefulWidget { class _CollectionAppBarState extends State with SingleTickerProviderStateMixin { final TextEditingController _searchFieldController = TextEditingController(); - late EntrySetActionDelegate _actionDelegate; + final EntrySetActionDelegate _actionDelegate = EntrySetActionDelegate(); late AnimationController _browseToSelectAnimation; late Future _canAddShortcutsLoader; @@ -59,9 +59,6 @@ class _CollectionAppBarState extends State with SingleTickerPr @override void initState() { super.initState(); - _actionDelegate = EntrySetActionDelegate( - collection: collection, - ); _browseToSelectAnimation = AnimationController( duration: Durations.iconAnimation, vsync: this, diff --git a/lib/widgets/collection/entry_set_action_delegate.dart b/lib/widgets/collection/entry_set_action_delegate.dart index 4973cac16..557c2be48 100644 --- a/lib/widgets/collection/entry_set_action_delegate.dart +++ b/lib/widgets/collection/entry_set_action_delegate.dart @@ -3,11 +3,9 @@ import 'dart:async'; import 'package:aves/model/actions/collection_actions.dart'; import 'package:aves/model/actions/entry_actions.dart'; import 'package:aves/model/actions/move_type.dart'; -import 'package:aves/model/entry.dart'; import 'package:aves/model/filters/album.dart'; import 'package:aves/model/highlight.dart'; import 'package:aves/model/source/collection_lens.dart'; -import 'package:aves/model/source/collection_source.dart'; import 'package:aves/services/android_app_service.dart'; import 'package:aves/services/image_op_events.dart'; import 'package:aves/services/services.dart'; @@ -27,23 +25,14 @@ import 'package:pedantic/pedantic.dart'; import 'package:provider/provider.dart'; class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMixin { - final CollectionLens collection; - - CollectionSource get source => collection.source; - - Set get selection => collection.selection; - - EntrySetActionDelegate({ - required this.collection, - }); - void onEntryActionSelected(BuildContext context, EntryAction action) { switch (action) { case EntryAction.delete: _showDeleteDialog(context); break; case EntryAction.share: - AndroidAppService.shareEntries(selection).then((success) { + final collection = context.read(); + AndroidAppService.shareEntries(collection.selection).then((success) { if (!success) showNoMatchingAppDialog(context); }); break; @@ -61,15 +50,24 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware _moveSelection(context, moveType: MoveType.move); break; case CollectionAction.refreshMetadata: - source.refreshMetadata(selection); - collection.browse(); + _refreshMetadata(context); break; default: break; } } + void _refreshMetadata(BuildContext context) { + final collection = context.read(); + collection.source.refreshMetadata(collection.selection); + collection.browse(); + } + Future _moveSelection(BuildContext context, {required MoveType moveType}) async { + final collection = context.read(); + final source = collection.source; + final selection = collection.selection; + final selectionDirs = selection.where((e) => e.path != null).map((e) => e.directory).cast().toSet(); if (moveType == MoveType.move) { // check whether moving is possible given OS restrictions, @@ -105,6 +103,8 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware final copy = moveType == MoveType.copy; final todoCount = todoEntries.length; + assert(todoCount > 0); + source.pauseMonitoring(); showOpReport( context: context, @@ -179,6 +179,9 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware } Future _showDeleteDialog(BuildContext context) async { + final collection = context.read(); + final source = collection.source; + final selection = collection.selection; final selectionDirs = selection.where((e) => e.path != null).map((e) => e.directory).cast().toSet(); final todoCount = selection.length;