copy: update DB, favs
This commit is contained in:
parent
0a3b625f44
commit
cae7e6570d
5 changed files with 40 additions and 13 deletions
|
@ -144,6 +144,7 @@ class CollectionSource {
|
|||
}
|
||||
|
||||
void removeEntries(Iterable<ImageEntry> entries) async {
|
||||
entries.forEach((entry) => entry.removeFromFavourites());
|
||||
_rawEntries.removeWhere(entries.contains);
|
||||
eventBus.fire(EntryRemovedEvent(entries));
|
||||
}
|
||||
|
|
|
@ -17,14 +17,16 @@ class FavouriteRepo {
|
|||
|
||||
bool isFavourite(ImageEntry entry) => _rows.any((row) => row.contentId == entry.contentId);
|
||||
|
||||
Future<void> add(ImageEntry entry) async {
|
||||
final newRows = [FavouriteRow(contentId: entry.contentId, path: entry.path)];
|
||||
FavouriteRow _entryToRow(ImageEntry entry) => FavouriteRow(contentId: entry.contentId, path: entry.path);
|
||||
|
||||
Future<void> add(Iterable<ImageEntry> entries) async {
|
||||
final newRows = entries.map(_entryToRow);
|
||||
await metadataDb.addFavourites(newRows);
|
||||
_rows.addAll(newRows);
|
||||
}
|
||||
|
||||
Future<void> remove(ImageEntry entry) async {
|
||||
final removedRows = [FavouriteRow(contentId: entry.contentId, path: entry.path)];
|
||||
Future<void> remove(Iterable<ImageEntry> entries) async {
|
||||
final removedRows = entries.map(_entryToRow);
|
||||
await metadataDb.removeFavourites(removedRows);
|
||||
removedRows.forEach(_rows.remove);
|
||||
}
|
||||
|
|
|
@ -335,10 +335,23 @@ class ImageEntry {
|
|||
|
||||
void toggleFavourite() {
|
||||
if (isFavourite) {
|
||||
favourites.remove(this);
|
||||
removeFromFavourites();
|
||||
} else {
|
||||
favourites.add(this);
|
||||
addToFavourites();
|
||||
}
|
||||
}
|
||||
|
||||
void addToFavourites() {
|
||||
if (!isFavourite) {
|
||||
favourites.add([this]);
|
||||
isFavouriteNotifier.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
void removeFromFavourites() {
|
||||
if (isFavourite) {
|
||||
favourites.remove([this]);
|
||||
isFavouriteNotifier.value = false;
|
||||
}
|
||||
isFavouriteNotifier.value = !isFavouriteNotifier.value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:aves/model/collection_lens.dart';
|
||||
import 'package:aves/model/filters/album.dart';
|
||||
import 'package:aves/model/image_entry.dart';
|
||||
import 'package:aves/model/metadata_db.dart';
|
||||
import 'package:aves/services/android_app_service.dart';
|
||||
import 'package:aves/services/image_file_service.dart';
|
||||
import 'package:aves/widgets/album/app_bar.dart';
|
||||
|
@ -98,20 +99,30 @@ class SelectionActionDelegate with PermissionAwareMixin {
|
|||
}
|
||||
if (movedCount > 0) {
|
||||
if (copy) {
|
||||
collection.source.addAll(movedOps.map((movedOp) {
|
||||
final newEntries = <ImageEntry>[];
|
||||
final newFavs = <ImageEntry>[];
|
||||
movedOps.forEach((movedOp) {
|
||||
final sourceUri = movedOp.uri;
|
||||
final newFields = movedOp.newFields;
|
||||
final sourceEntry = selection.firstWhere((entry) => entry.uri == sourceUri, orElse: () => null);
|
||||
return sourceEntry?.copyWith(
|
||||
final copy = sourceEntry?.copyWith(
|
||||
uri: newFields['uri'] as String,
|
||||
path: newFields['path'] as String,
|
||||
contentId: newFields['contentId'] as int,
|
||||
);
|
||||
}));
|
||||
newEntries.add(copy);
|
||||
if (sourceEntry.isFavourite) {
|
||||
newFavs.add(copy);
|
||||
}
|
||||
});
|
||||
collection.source.addAll(newEntries);
|
||||
metadataDb.saveMetadata(newEntries.map((entry) => entry.catalogMetadata));
|
||||
metadataDb.saveAddresses(newEntries.map((entry) => entry.addressDetails));
|
||||
newFavs.forEach((entry) => entry.addToFavourites());
|
||||
} else {
|
||||
// TODO TLAD update old entries path/dir/ID
|
||||
// TODO TLAD update DB for catalog/address/fav
|
||||
}
|
||||
// TODO TLAD update DB for catalog/address/fav
|
||||
}
|
||||
collection.clearSelection();
|
||||
collection.browse();
|
||||
|
|
|
@ -413,12 +413,12 @@ class _FullscreenVerticalPageViewState extends State<FullscreenVerticalPageView>
|
|||
|
||||
void _registerWidget(FullscreenVerticalPageView widget) {
|
||||
widget.verticalPager.addListener(_onVerticalPageControllerChanged);
|
||||
widget.entry.imageChangeNotifier.addListener(_onImageChanged);
|
||||
widget.entry?.imageChangeNotifier?.addListener(_onImageChanged);
|
||||
}
|
||||
|
||||
void _unregisterWidget(FullscreenVerticalPageView widget) {
|
||||
widget.verticalPager.removeListener(_onVerticalPageControllerChanged);
|
||||
widget.entry.imageChangeNotifier.removeListener(_onImageChanged);
|
||||
widget.entry?.imageChangeNotifier?.removeListener(_onImageChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in a new issue