viewer: fixed delete action

This commit is contained in:
Thibault Deckers 2020-03-16 17:14:04 +09:00
parent 730c8bd632
commit 23a20a9343
3 changed files with 17 additions and 10 deletions

View file

@ -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<bool> delete(ImageEntry entry) async {
final success = await ImageFileService.delete(entry);
final success = await entry.delete();
if (success) {
_rawEntries.remove(entry);
eventBus.fire(EntryRemovedEvent(entry));

View file

@ -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<bool> 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<bool> delete() => ImageFileService.delete(this);
}

View file

@ -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);
}
}