From 23a20a9343053a56ee17dc498dfbf2b0a2dea013 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 16 Mar 2020 17:14:04 +0900 Subject: [PATCH] viewer: fixed delete action --- lib/model/collection_source.dart | 3 +-- lib/model/image_entry.dart | 10 ++++++---- .../fullscreen/fullscreen_action_delegate.dart | 14 ++++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/model/collection_source.dart b/lib/model/collection_source.dart index 9ff1c6ae4..fb8cc113d 100644 --- a/lib/model/collection_source.dart +++ b/lib/model/collection_source.dart @@ -1,5 +1,4 @@ import 'package:aves/model/image_entry.dart'; -import 'package:aves/model/image_file_service.dart'; import 'package:aves/model/image_metadata.dart'; import 'package:aves/model/metadata_db.dart'; import 'package:collection/collection.dart'; @@ -121,7 +120,7 @@ class CollectionSource { } Future delete(ImageEntry entry) async { - final success = await ImageFileService.delete(entry); + final success = await entry.delete(); if (success) { _rawEntries.remove(entry); eventBus.fire(EntryRemovedEvent(entry)); diff --git a/lib/model/image_entry.dart b/lib/model/image_entry.dart index ac8fc47ff..e45ccecb1 100644 --- a/lib/model/image_entry.dart +++ b/lib/model/image_entry.dart @@ -103,6 +103,10 @@ class ImageEntry { bool get isCatalogued => catalogMetadata != null; + bool get canPrint => !isVideo; + + bool get canRotate => mimeType == MimeTypes.MIME_JPEG || mimeType == MimeTypes.MIME_PNG; + double get aspectRatio { if (width == 0 || height == 0) return 1; if (isVideo && isCatalogued) { @@ -214,10 +218,6 @@ class ImageEntry { return true; } - bool get canPrint => !isVideo; - - bool get canRotate => mimeType == MimeTypes.MIME_JPEG || mimeType == MimeTypes.MIME_PNG; - Future rotate({@required bool clockwise}) async { final newFields = await ImageFileService.rotate(this, clockwise: clockwise); if (newFields.isEmpty) return false; @@ -232,4 +232,6 @@ class ImageEntry { imageChangeNotifier.notifyListeners(); return true; } + + Future delete() => ImageFileService.delete(this); } diff --git a/lib/widgets/fullscreen/fullscreen_action_delegate.dart b/lib/widgets/fullscreen/fullscreen_action_delegate.dart index d319ed46c..0e3f642ee 100644 --- a/lib/widgets/fullscreen/fullscreen_action_delegate.dart +++ b/lib/widgets/fullscreen/fullscreen_action_delegate.dart @@ -20,6 +20,8 @@ class FullscreenActionDelegate { @required this.showInfo, }); + bool get hasCollection => collection != null; + void onActionSelected(BuildContext context, ImageEntry entry, FullscreenAction action) { switch (action) { case FullscreenAction.delete: @@ -109,10 +111,14 @@ class FullscreenActionDelegate { }, ); if (confirmed == null || !confirmed) return; - if (!await collection.source.delete(entry)) { - _showFeedback(context, 'Failed'); - } else if (collection.sortedEntries.isEmpty) { - Navigator.pop(context); + if (hasCollection) { + if (!await collection.source.delete(entry)) { + _showFeedback(context, 'Failed'); + } else if (collection.sortedEntries.isEmpty) { + Navigator.pop(context); + } + } else if (await entry.delete()) { + exit(0); } }