view mode: fixed renaming/rotating items without db
This commit is contained in:
parent
2ab0eaeae1
commit
0b2be7e3d4
4 changed files with 22 additions and 17 deletions
|
@ -568,26 +568,26 @@ class AvesEntry {
|
||||||
metadataChangeNotifier.notifyListeners();
|
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);
|
final newFields = await imageFileService.rotate(this, clockwise: clockwise);
|
||||||
if (newFields.isEmpty) return false;
|
if (newFields.isEmpty) return false;
|
||||||
|
|
||||||
final oldDateModifiedSecs = dateModifiedSecs;
|
final oldDateModifiedSecs = dateModifiedSecs;
|
||||||
final oldRotationDegrees = rotationDegrees;
|
final oldRotationDegrees = rotationDegrees;
|
||||||
final oldIsFlipped = isFlipped;
|
final oldIsFlipped = isFlipped;
|
||||||
await _applyNewFields(newFields, persist: true);
|
await _applyNewFields(newFields, persist: persist);
|
||||||
await _onImageChanged(oldDateModifiedSecs, oldRotationDegrees, oldIsFlipped);
|
await _onImageChanged(oldDateModifiedSecs, oldRotationDegrees, oldIsFlipped);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> flip() async {
|
Future<bool> flip({required bool persist}) async {
|
||||||
final newFields = await imageFileService.flip(this);
|
final newFields = await imageFileService.flip(this);
|
||||||
if (newFields.isEmpty) return false;
|
if (newFields.isEmpty) return false;
|
||||||
|
|
||||||
final oldDateModifiedSecs = dateModifiedSecs;
|
final oldDateModifiedSecs = dateModifiedSecs;
|
||||||
final oldRotationDegrees = rotationDegrees;
|
final oldRotationDegrees = rotationDegrees;
|
||||||
final oldIsFlipped = isFlipped;
|
final oldIsFlipped = isFlipped;
|
||||||
await _applyNewFields(newFields, persist: true);
|
await _applyNewFields(newFields, persist: persist);
|
||||||
await _onImageChanged(oldDateModifiedSecs, oldRotationDegrees, oldIsFlipped);
|
await _onImageChanged(oldDateModifiedSecs, oldRotationDegrees, oldIsFlipped);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM
|
||||||
updateTags();
|
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 oldContentId = entry.contentId!;
|
||||||
final newContentId = newFields['contentId'] as int?;
|
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.catalogMetadata = entry.catalogMetadata?.copyWith(contentId: newContentId);
|
||||||
entry.addressDetails = entry.addressDetails?.copyWith(contentId: newContentId);
|
entry.addressDetails = entry.addressDetails?.copyWith(contentId: newContentId);
|
||||||
|
|
||||||
await metadataDb.updateEntryId(oldContentId, entry);
|
if (persist) {
|
||||||
await metadataDb.updateMetadataId(oldContentId, entry.catalogMetadata);
|
await metadataDb.updateEntryId(oldContentId, entry);
|
||||||
await metadataDb.updateAddressId(oldContentId, entry.addressDetails);
|
await metadataDb.updateMetadataId(oldContentId, entry.catalogMetadata);
|
||||||
await favourites.moveEntry(oldContentId, entry);
|
await metadataDb.updateAddressId(oldContentId, entry.addressDetails);
|
||||||
await covers.moveEntry(oldContentId, entry);
|
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;
|
if (newName == entry.filenameWithoutExtension) return true;
|
||||||
final newFields = await imageFileService.rename(entry, '$newName${entry.extension}');
|
final newFields = await imageFileService.rename(entry, '$newName${entry.extension}');
|
||||||
if (newFields.isEmpty) return false;
|
if (newFields.isEmpty) return false;
|
||||||
|
|
||||||
await _moveEntry(entry, newFields);
|
await _moveEntry(entry, newFields, persist: persist);
|
||||||
entry.metadataChangeNotifier.notifyListeners();
|
entry.metadataChangeNotifier.notifyListeners();
|
||||||
eventBus.fire(EntryMovedEvent({entry}));
|
eventBus.fire(EntryMovedEvent({entry}));
|
||||||
return true;
|
return true;
|
||||||
|
@ -215,7 +217,7 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
fromAlbums.add(entry.directory);
|
fromAlbums.add(entry.directory);
|
||||||
movedEntries.add(entry);
|
movedEntries.add(entry);
|
||||||
await _moveEntry(entry, newFields);
|
await _moveEntry(entry, newFields, persist: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:aves/app_mode.dart';
|
||||||
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';
|
||||||
|
@ -105,14 +106,14 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
Future<void> _flip(BuildContext context, AvesEntry entry) async {
|
Future<void> _flip(BuildContext context, AvesEntry entry) async {
|
||||||
if (!await checkStoragePermission(context, {entry})) return;
|
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);
|
if (!success) showFeedback(context, context.l10n.genericFailureFeedback);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _rotate(BuildContext context, AvesEntry entry, {required bool clockwise}) async {
|
Future<void> _rotate(BuildContext context, AvesEntry entry, {required bool clockwise}) async {
|
||||||
if (!await checkStoragePermission(context, {entry})) return;
|
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);
|
if (!success) showFeedback(context, context.l10n.genericFailureFeedback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +258,7 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
|
|
||||||
if (!await checkStoragePermission(context, {entry})) return;
|
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) {
|
if (success) {
|
||||||
showFeedback(context, context.l10n.genericSuccessFeedback);
|
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) {
|
void _goToSourceViewer(BuildContext context, AvesEntry entry) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
|
|
|
@ -118,7 +118,7 @@ void main() {
|
||||||
await image1.toggleFavourite();
|
await image1.toggleFavourite();
|
||||||
const albumFilter = AlbumFilter(testAlbum, 'whatever');
|
const albumFilter = AlbumFilter(testAlbum, 'whatever');
|
||||||
await covers.set(albumFilter, image1.contentId);
|
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(favourites.count, 1);
|
||||||
expect(image1.isFavourite, true);
|
expect(image1.isFavourite, true);
|
||||||
|
|
Loading…
Reference in a new issue