export: action to show exported items, removed superfluous permission check
This commit is contained in:
parent
e3054d24e8
commit
503981deac
1 changed files with 48 additions and 7 deletions
|
@ -3,12 +3,16 @@ import 'dart:convert';
|
||||||
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/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_lens.dart';
|
||||||
import 'package:aves/model/source/collection_source.dart';
|
import 'package:aves/model/source/collection_source.dart';
|
||||||
import 'package:aves/ref/mime_types.dart';
|
import 'package:aves/ref/mime_types.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';
|
||||||
|
import 'package:aves/theme/durations.dart';
|
||||||
|
import 'package:aves/widgets/collection/collection_page.dart';
|
||||||
import 'package:aves/widgets/common/action_mixins/feedback.dart';
|
import 'package:aves/widgets/common/action_mixins/feedback.dart';
|
||||||
import 'package:aves/widgets/common/action_mixins/permission_aware.dart';
|
import 'package:aves/widgets/common/action_mixins/permission_aware.dart';
|
||||||
import 'package:aves/widgets/common/action_mixins/size_aware.dart';
|
import 'package:aves/widgets/common/action_mixins/size_aware.dart';
|
||||||
|
@ -20,6 +24,7 @@ import 'package:aves/widgets/viewer/debug/debug_page.dart';
|
||||||
import 'package:aves/widgets/viewer/info/notifications.dart';
|
import 'package:aves/widgets/viewer/info/notifications.dart';
|
||||||
import 'package:aves/widgets/viewer/printer.dart';
|
import 'package:aves/widgets/viewer/printer.dart';
|
||||||
import 'package:aves/widgets/viewer/source_viewer_page.dart';
|
import 'package:aves/widgets/viewer/source_viewer_page.dart';
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:pedantic/pedantic.dart';
|
import 'package:pedantic/pedantic.dart';
|
||||||
|
@ -34,8 +39,6 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
required this.showInfo,
|
required this.showInfo,
|
||||||
});
|
});
|
||||||
|
|
||||||
bool get hasCollection => collection != null;
|
|
||||||
|
|
||||||
void onActionSelected(BuildContext context, AvesEntry entry, EntryAction action) {
|
void onActionSelected(BuildContext context, AvesEntry entry, EntryAction action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case EntryAction.toggleFavourite:
|
case EntryAction.toggleFavourite:
|
||||||
|
@ -140,7 +143,7 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
if (!await entry.delete()) {
|
if (!await entry.delete()) {
|
||||||
showFeedback(context, context.l10n.genericFailureFeedback);
|
showFeedback(context, context.l10n.genericFailureFeedback);
|
||||||
} else {
|
} else {
|
||||||
if (hasCollection) {
|
if (collection != null) {
|
||||||
await collection!.source.removeEntries({entry.uri});
|
await collection!.source.removeEntries({entry.uri});
|
||||||
}
|
}
|
||||||
EntryDeletedNotification(entry).dispatch(context);
|
EntryDeletedNotification(entry).dispatch(context);
|
||||||
|
@ -164,8 +167,6 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
if (destinationAlbum == null || destinationAlbum.isEmpty) return;
|
if (destinationAlbum == null || destinationAlbum.isEmpty) return;
|
||||||
if (!await checkStoragePermissionForAlbums(context, {destinationAlbum})) return;
|
if (!await checkStoragePermissionForAlbums(context, {destinationAlbum})) return;
|
||||||
|
|
||||||
if (!await checkStoragePermission(context, {entry})) return;
|
|
||||||
|
|
||||||
if (!await checkFreeSpaceForMove(context, {entry}, destinationAlbum, MoveType.export)) return;
|
if (!await checkFreeSpaceForMove(context, {entry}, destinationAlbum, MoveType.export)) return;
|
||||||
|
|
||||||
final selection = <AvesEntry>{};
|
final selection = <AvesEntry>{};
|
||||||
|
@ -195,11 +196,51 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
onDone: (processed) {
|
onDone: (processed) {
|
||||||
final movedOps = processed.where((e) => e.success);
|
final movedOps = processed.where((e) => e.success);
|
||||||
final movedCount = movedOps.length;
|
final movedCount = movedOps.length;
|
||||||
|
final showAction = collection != null && movedCount > 0
|
||||||
|
? SnackBarAction(
|
||||||
|
label: context.l10n.showButtonLabel,
|
||||||
|
onPressed: () async {
|
||||||
|
final highlightInfo = context.read<HighlightInfo>();
|
||||||
|
final targetCollection = CollectionLens(
|
||||||
|
source: collection!.source,
|
||||||
|
filters: {AlbumFilter(destinationAlbum, source.getAlbumDisplayName(context, destinationAlbum))},
|
||||||
|
groupFactor: collection!.groupFactor,
|
||||||
|
sortFactor: collection!.sortFactor,
|
||||||
|
);
|
||||||
|
unawaited(Navigator.pushAndRemoveUntil(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
settings: const RouteSettings(name: CollectionPage.routeName),
|
||||||
|
builder: (context) {
|
||||||
|
return CollectionPage(
|
||||||
|
targetCollection,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(route) => false,
|
||||||
|
));
|
||||||
|
await Future.delayed(Durations.staggeredAnimationPageTarget + Durations.highlightScrollInitDelay);
|
||||||
|
final newUris = movedOps.map((v) => v.newFields['uri'] as String?).toSet();
|
||||||
|
final targetEntry = targetCollection.sortedEntries.firstWhereOrNull((entry) => newUris.contains(entry.uri));
|
||||||
|
if (targetEntry != null) {
|
||||||
|
highlightInfo.trackItem(targetEntry, animate: true, highlight: targetEntry);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: null;
|
||||||
if (movedCount < selectionCount) {
|
if (movedCount < selectionCount) {
|
||||||
final count = selectionCount - movedCount;
|
final count = selectionCount - movedCount;
|
||||||
showFeedback(context, context.l10n.collectionExportFailureFeedback(count));
|
showFeedback(
|
||||||
|
context,
|
||||||
|
context.l10n.collectionExportFailureFeedback(count),
|
||||||
|
showAction,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
showFeedback(context, context.l10n.genericSuccessFeedback);
|
showFeedback(
|
||||||
|
context,
|
||||||
|
context.l10n.genericSuccessFeedback,
|
||||||
|
showAction,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue