Merge pull request #487 from ente-io/fix_collection_deletion
BugFix: Fix bug in handling trashed/deleted albums
This commit is contained in:
commit
3f9abfbd33
|
@ -58,9 +58,9 @@ class DuplicateFiles {
|
|||
sortByCollectionName() {
|
||||
files.sort((first, second) {
|
||||
final firstName =
|
||||
collectionsService.getCollectionNameByID(first.collectionID);
|
||||
collectionsService.getCollectionByID(first.collectionID).name;
|
||||
final secondName =
|
||||
collectionsService.getCollectionNameByID(second.collectionID);
|
||||
collectionsService.getCollectionByID(second.collectionID).name;
|
||||
return firstName.compareTo(secondName);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class CollectionsService {
|
|||
SharedPreferences _prefs;
|
||||
Future<List<File>> _cachedLatestFiles;
|
||||
final _dio = Network.instance.getDio();
|
||||
final _localCollections = <String, Collection>{};
|
||||
final _localPathToCollectionID = <String, int>{};
|
||||
final _collectionIDToCollections = <int, Collection>{};
|
||||
final _cachedKeys = <int, Uint8List>{};
|
||||
|
||||
|
@ -120,7 +120,7 @@ class CollectionsService {
|
|||
}
|
||||
|
||||
void clearCache() {
|
||||
_localCollections.clear();
|
||||
_localPathToCollectionID.clear();
|
||||
_collectionIDToCollections.clear();
|
||||
_cachedKeys.clear();
|
||||
}
|
||||
|
@ -163,10 +163,6 @@ class CollectionsService {
|
|||
return _prefs.setInt(key, time);
|
||||
}
|
||||
|
||||
Collection getCollectionForPath(String path) {
|
||||
return _localCollections[path];
|
||||
}
|
||||
|
||||
// getActiveCollections returns list of collections which are not deleted yet
|
||||
List<Collection> getActiveCollections() {
|
||||
return _collectionIDToCollections.values
|
||||
|
@ -582,9 +578,14 @@ class CollectionsService {
|
|||
}
|
||||
|
||||
Future<Collection> getOrCreateForPath(String path) async {
|
||||
if (_localCollections.containsKey(path) &&
|
||||
_localCollections[path].owner.id == _config.getUserID()) {
|
||||
return _localCollections[path];
|
||||
if (_localPathToCollectionID.containsKey(path)) {
|
||||
final Collection cachedCollection =
|
||||
_collectionIDToCollections[_localPathToCollectionID[path]];
|
||||
if (cachedCollection != null &&
|
||||
!cachedCollection.isDeleted &&
|
||||
cachedCollection.owner.id == _config.getUserID()) {
|
||||
return cachedCollection;
|
||||
}
|
||||
}
|
||||
final key = CryptoUtil.generateKey();
|
||||
final encryptedKeyData = CryptoUtil.encryptSync(key, _config.getKey());
|
||||
|
@ -826,10 +827,6 @@ class CollectionsService {
|
|||
Bus.instance.fire(CollectionUpdatedEvent(toCollectionID, files));
|
||||
}
|
||||
|
||||
String getCollectionNameByID(int collectionID) {
|
||||
return getCollectionByID(collectionID).name;
|
||||
}
|
||||
|
||||
void _validateMoveRequest(
|
||||
int toCollectionID,
|
||||
int fromCollectionID,
|
||||
|
@ -890,9 +887,10 @@ class CollectionsService {
|
|||
final collectionWithDecryptedName =
|
||||
_getCollectionWithDecryptedName(collection);
|
||||
if (collection.attributes.encryptedPath != null &&
|
||||
!(collection.isDeleted)) {
|
||||
_localCollections[decryptCollectionPath(collection)] =
|
||||
collectionWithDecryptedName;
|
||||
!collection.isDeleted &&
|
||||
collection.owner.id == _config.getUserID()) {
|
||||
_localPathToCollectionID[decryptCollectionPath(collection)] =
|
||||
collection.id;
|
||||
}
|
||||
_collectionIDToCollections[collection.id] = collectionWithDecryptedName;
|
||||
return collectionWithDecryptedName;
|
||||
|
|
|
@ -9,6 +9,7 @@ import 'package:photos/core/event_bus.dart';
|
|||
import 'package:photos/events/collection_updated_event.dart';
|
||||
import 'package:photos/events/local_photos_updated_event.dart';
|
||||
import 'package:photos/events/user_logged_out_event.dart';
|
||||
import 'package:photos/models/collection.dart';
|
||||
import 'package:photos/models/collection_items.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/ui/collections/device_folders_grid_view_widget.dart';
|
||||
|
@ -90,6 +91,10 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
|
|||
}
|
||||
collectionsWithThumbnail.sort(
|
||||
(first, second) {
|
||||
if (second.collection.type == CollectionType.favorites &&
|
||||
first.collection.type != CollectionType.favorites) {
|
||||
return 1;
|
||||
}
|
||||
if (sortKey == AlbumSortKey.albumName) {
|
||||
// alphabetical ASC order
|
||||
return first.collection.name.compareTo(second.collection.name);
|
||||
|
|
|
@ -472,7 +472,8 @@ class _DeduplicatePageState extends State<DeduplicatePage> {
|
|||
padding: const EdgeInsets.only(right: 2),
|
||||
child: Text(
|
||||
CollectionsService.instance
|
||||
.getCollectionNameByID(file.collectionID),
|
||||
.getCollectionByID(file.collectionID)
|
||||
.name,
|
||||
style: Theme.of(context).textTheme.caption.copyWith(fontSize: 12),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
|
|
@ -163,7 +163,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
PopupMenuButton(
|
||||
itemBuilder: (context) {
|
||||
final List<PopupMenuItem> items = [];
|
||||
if (widget.collection.type == CollectionType.album) {
|
||||
if (widget.collection.type != CollectionType.favorites) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
value: 1,
|
||||
|
@ -173,7 +173,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
),
|
||||
Text("Rename"),
|
||||
Text("Rename album"),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -189,25 +189,27 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
const Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
),
|
||||
Text(isArchived ? "Unhide" : "Hide"),
|
||||
Text(isArchived ? "Unhide album" : "Hide album"),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
value: 3,
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.delete_sweep_outlined),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
),
|
||||
Text("Delete Album"),
|
||||
],
|
||||
if (widget.collection.type != CollectionType.favorites) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
value: 3,
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.delete_outline),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
),
|
||||
Text("Delete album"),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
return items;
|
||||
},
|
||||
onSelected: (value) async {
|
||||
|
|
Loading…
Reference in a new issue