diff --git a/lib/model/entry.dart b/lib/model/entry.dart index e72fb22ad..297756c47 100644 --- a/lib/model/entry.dart +++ b/lib/model/entry.dart @@ -568,26 +568,26 @@ class AvesEntry { metadataChangeNotifier.notifyListeners(); } - Future rotate({required bool clockwise}) async { + Future rotate({required bool clockwise, required bool persist}) async { final newFields = await imageFileService.rotate(this, clockwise: clockwise); if (newFields.isEmpty) return false; final oldDateModifiedSecs = dateModifiedSecs; final oldRotationDegrees = rotationDegrees; final oldIsFlipped = isFlipped; - await _applyNewFields(newFields, persist: true); + await _applyNewFields(newFields, persist: persist); await _onImageChanged(oldDateModifiedSecs, oldRotationDegrees, oldIsFlipped); return true; } - Future flip() async { + Future flip({required bool persist}) async { final newFields = await imageFileService.flip(this); if (newFields.isEmpty) return false; final oldDateModifiedSecs = dateModifiedSecs; final oldRotationDegrees = rotationDegrees; final oldIsFlipped = isFlipped; - await _applyNewFields(newFields, persist: true); + await _applyNewFields(newFields, persist: persist); await _onImageChanged(oldDateModifiedSecs, oldRotationDegrees, oldIsFlipped); return true; } diff --git a/lib/model/source/collection_source.dart b/lib/model/source/collection_source.dart index c4702d5cb..ab4e099c7 100644 --- a/lib/model/source/collection_source.dart +++ b/lib/model/source/collection_source.dart @@ -124,7 +124,7 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM updateTags(); } - Future _moveEntry(AvesEntry entry, Map newFields) async { + Future _moveEntry(AvesEntry entry, Map newFields, {required bool persist}) async { final oldContentId = entry.contentId!; final newContentId = newFields['contentId'] as int?; @@ -139,19 +139,21 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM entry.catalogMetadata = entry.catalogMetadata?.copyWith(contentId: newContentId); entry.addressDetails = entry.addressDetails?.copyWith(contentId: newContentId); - await metadataDb.updateEntryId(oldContentId, entry); - await metadataDb.updateMetadataId(oldContentId, entry.catalogMetadata); - await metadataDb.updateAddressId(oldContentId, entry.addressDetails); - await favourites.moveEntry(oldContentId, entry); - await covers.moveEntry(oldContentId, entry); + if (persist) { + await metadataDb.updateEntryId(oldContentId, entry); + await metadataDb.updateMetadataId(oldContentId, entry.catalogMetadata); + await metadataDb.updateAddressId(oldContentId, entry.addressDetails); + await favourites.moveEntry(oldContentId, entry); + await covers.moveEntry(oldContentId, entry); + } } - Future renameEntry(AvesEntry entry, String newName) async { + Future renameEntry(AvesEntry entry, String newName, {required bool persist}) async { if (newName == entry.filenameWithoutExtension) return true; final newFields = await imageFileService.rename(entry, '$newName${entry.extension}'); if (newFields.isEmpty) return false; - await _moveEntry(entry, newFields); + await _moveEntry(entry, newFields, persist: persist); entry.metadataChangeNotifier.notifyListeners(); eventBus.fire(EntryMovedEvent({entry})); return true; @@ -215,7 +217,7 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM if (entry != null) { fromAlbums.add(entry.directory); movedEntries.add(entry); - await _moveEntry(entry, newFields); + await _moveEntry(entry, newFields, persist: true); } } }); diff --git a/lib/widgets/viewer/entry_action_delegate.dart b/lib/widgets/viewer/entry_action_delegate.dart index 3deb23604..87c6075d6 100644 --- a/lib/widgets/viewer/entry_action_delegate.dart +++ b/lib/widgets/viewer/entry_action_delegate.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:aves/app_mode.dart'; import 'package:aves/model/actions/entry_actions.dart'; import 'package:aves/model/actions/move_type.dart'; import 'package:aves/model/entry.dart'; @@ -105,14 +106,14 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix Future _flip(BuildContext context, AvesEntry entry) async { if (!await checkStoragePermission(context, {entry})) return; - final success = await entry.flip(); + final success = await entry.flip(persist: isMainMode(context)); if (!success) showFeedback(context, context.l10n.genericFailureFeedback); } Future _rotate(BuildContext context, AvesEntry entry, {required bool clockwise}) async { if (!await checkStoragePermission(context, {entry})) return; - final success = await entry.rotate(clockwise: clockwise); + final success = await entry.rotate(clockwise: clockwise, persist: isMainMode(context)); if (!success) showFeedback(context, context.l10n.genericFailureFeedback); } @@ -257,7 +258,7 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix if (!await checkStoragePermission(context, {entry})) return; - final success = await context.read().renameEntry(entry, newName); + final success = await context.read().renameEntry(entry, newName, persist: isMainMode(context)); if (success) { showFeedback(context, context.l10n.genericSuccessFeedback); @@ -266,6 +267,8 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix } } + bool isMainMode(BuildContext context) => context.read>().value == AppMode.main; + void _goToSourceViewer(BuildContext context, AvesEntry entry) { Navigator.push( context, diff --git a/test/model/collection_source_test.dart b/test/model/collection_source_test.dart index b2caa0fe7..59275f209 100644 --- a/test/model/collection_source_test.dart +++ b/test/model/collection_source_test.dart @@ -118,7 +118,7 @@ void main() { await image1.toggleFavourite(); const albumFilter = AlbumFilter(testAlbum, 'whatever'); await covers.set(albumFilter, image1.contentId); - await source.renameEntry(image1, 'image1b.jpg'); + await source.renameEntry(image1, 'image1b.jpg', persist: true); expect(favourites.count, 1); expect(image1.isFavourite, true);