view mode: fixed renaming/rotating items without db

This commit is contained in:
Thibault Deckers 2021-06-17 16:43:32 +09:00
parent 2ab0eaeae1
commit 0b2be7e3d4
4 changed files with 22 additions and 17 deletions

View file

@ -568,26 +568,26 @@ class AvesEntry {
metadataChangeNotifier.notifyListeners();
}
Future<bool> rotate({required bool clockwise}) async {
Future<bool> 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<bool> flip() async {
Future<bool> 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;
}

View file

@ -124,7 +124,7 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM
updateTags();
}
Future<void> _moveEntry(AvesEntry entry, Map newFields) async {
Future<void> _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<bool> renameEntry(AvesEntry entry, String newName) async {
Future<bool> 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);
}
}
});

View file

@ -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<void> _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<void> _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<CollectionSource>().renameEntry(entry, newName);
final success = await context.read<CollectionSource>().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<ValueNotifier<AppMode>>().value == AppMode.main;
void _goToSourceViewer(BuildContext context, AvesEntry entry) {
Navigator.push(
context,

View file

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