collection: fixed action delegate when app bar state was changed

This commit is contained in:
Thibault Deckers 2021-06-09 13:59:10 +09:00
parent 9c8d0215c6
commit e3054d24e8
2 changed files with 19 additions and 19 deletions

View file

@ -46,7 +46,7 @@ class CollectionAppBar extends StatefulWidget {
class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerProviderStateMixin { class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerProviderStateMixin {
final TextEditingController _searchFieldController = TextEditingController(); final TextEditingController _searchFieldController = TextEditingController();
late EntrySetActionDelegate _actionDelegate; final EntrySetActionDelegate _actionDelegate = EntrySetActionDelegate();
late AnimationController _browseToSelectAnimation; late AnimationController _browseToSelectAnimation;
late Future<bool> _canAddShortcutsLoader; late Future<bool> _canAddShortcutsLoader;
@ -59,9 +59,6 @@ class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerPr
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_actionDelegate = EntrySetActionDelegate(
collection: collection,
);
_browseToSelectAnimation = AnimationController( _browseToSelectAnimation = AnimationController(
duration: Durations.iconAnimation, duration: Durations.iconAnimation,
vsync: this, vsync: this,

View file

@ -3,11 +3,9 @@ import 'dart:async';
import 'package:aves/model/actions/collection_actions.dart'; import 'package:aves/model/actions/collection_actions.dart';
import 'package:aves/model/actions/entry_actions.dart'; import 'package:aves/model/actions/entry_actions.dart';
import 'package:aves/model/actions/move_type.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/filters/album.dart';
import 'package:aves/model/highlight.dart'; import 'package:aves/model/highlight.dart';
import 'package:aves/model/source/collection_lens.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/android_app_service.dart';
import 'package:aves/services/image_op_events.dart'; import 'package:aves/services/image_op_events.dart';
import 'package:aves/services/services.dart'; import 'package:aves/services/services.dart';
@ -27,23 +25,14 @@ import 'package:pedantic/pedantic.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMixin { class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMixin {
final CollectionLens collection;
CollectionSource get source => collection.source;
Set<AvesEntry> get selection => collection.selection;
EntrySetActionDelegate({
required this.collection,
});
void onEntryActionSelected(BuildContext context, EntryAction action) { void onEntryActionSelected(BuildContext context, EntryAction action) {
switch (action) { switch (action) {
case EntryAction.delete: case EntryAction.delete:
_showDeleteDialog(context); _showDeleteDialog(context);
break; break;
case EntryAction.share: case EntryAction.share:
AndroidAppService.shareEntries(selection).then((success) { final collection = context.read<CollectionLens>();
AndroidAppService.shareEntries(collection.selection).then((success) {
if (!success) showNoMatchingAppDialog(context); if (!success) showNoMatchingAppDialog(context);
}); });
break; break;
@ -61,15 +50,24 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware
_moveSelection(context, moveType: MoveType.move); _moveSelection(context, moveType: MoveType.move);
break; break;
case CollectionAction.refreshMetadata: case CollectionAction.refreshMetadata:
source.refreshMetadata(selection); _refreshMetadata(context);
collection.browse();
break; break;
default: default:
break; break;
} }
} }
void _refreshMetadata(BuildContext context) {
final collection = context.read<CollectionLens>();
collection.source.refreshMetadata(collection.selection);
collection.browse();
}
Future<void> _moveSelection(BuildContext context, {required MoveType moveType}) async { Future<void> _moveSelection(BuildContext context, {required MoveType moveType}) async {
final collection = context.read<CollectionLens>();
final source = collection.source;
final selection = collection.selection;
final selectionDirs = selection.where((e) => e.path != null).map((e) => e.directory).cast<String>().toSet(); final selectionDirs = selection.where((e) => e.path != null).map((e) => e.directory).cast<String>().toSet();
if (moveType == MoveType.move) { if (moveType == MoveType.move) {
// check whether moving is possible given OS restrictions, // check whether moving is possible given OS restrictions,
@ -105,6 +103,8 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware
final copy = moveType == MoveType.copy; final copy = moveType == MoveType.copy;
final todoCount = todoEntries.length; final todoCount = todoEntries.length;
assert(todoCount > 0);
source.pauseMonitoring(); source.pauseMonitoring();
showOpReport<MoveOpEvent>( showOpReport<MoveOpEvent>(
context: context, context: context,
@ -179,6 +179,9 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware
} }
Future<void> _showDeleteDialog(BuildContext context) async { Future<void> _showDeleteDialog(BuildContext context) async {
final collection = context.read<CollectionLens>();
final source = collection.source;
final selection = collection.selection;
final selectionDirs = selection.where((e) => e.path != null).map((e) => e.directory).cast<String>().toSet(); final selectionDirs = selection.where((e) => e.path != null).map((e) => e.directory).cast<String>().toSet();
final todoCount = selection.length; final todoCount = selection.length;