From 2ef7c7ce01d1061a4ea4fb769300626770781f8f Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 15 Sep 2022 12:41:57 +0530 Subject: [PATCH 1/6] CollectionService: remove getCollectionNameByID method Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com> --- lib/models/duplicate_files.dart | 4 ++-- lib/services/collections_service.dart | 4 ---- lib/ui/tools/deduplicate_page.dart | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/models/duplicate_files.dart b/lib/models/duplicate_files.dart index 3d74dee85..2834ba9be 100644 --- a/lib/models/duplicate_files.dart +++ b/lib/models/duplicate_files.dart @@ -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); }); } diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index c6af288b9..f75375ba3 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -826,10 +826,6 @@ class CollectionsService { Bus.instance.fire(CollectionUpdatedEvent(toCollectionID, files)); } - String getCollectionNameByID(int collectionID) { - return getCollectionByID(collectionID).name; - } - void _validateMoveRequest( int toCollectionID, int fromCollectionID, diff --git a/lib/ui/tools/deduplicate_page.dart b/lib/ui/tools/deduplicate_page.dart index 30ce3c886..fda7ccc1f 100644 --- a/lib/ui/tools/deduplicate_page.dart +++ b/lib/ui/tools/deduplicate_page.dart @@ -472,7 +472,8 @@ class _DeduplicatePageState extends State { 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, ), From b52ea8f30270d9baf01fbaf92c91db729ff4ce30 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 15 Sep 2022 12:55:46 +0530 Subject: [PATCH 2/6] remove unused method: getCollectionForPath --- lib/services/collections_service.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index f75375ba3..5bb400c47 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -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 getActiveCollections() { return _collectionIDToCollections.values From c70f6babcc0b0514284a8464eb710a464d1bb52d Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:12:14 +0530 Subject: [PATCH 3/6] FixBug: ensure getOrCreateForPath does not return deleted collection --- lib/services/collections_service.dart | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index 5bb400c47..ffcbce128 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -47,7 +47,7 @@ class CollectionsService { SharedPreferences _prefs; Future> _cachedLatestFiles; final _dio = Network.instance.getDio(); - final _localCollections = {}; + final _localPathToCollectionID = {}; final _collectionIDToCollections = {}; final _cachedKeys = {}; @@ -120,7 +120,7 @@ class CollectionsService { } void clearCache() { - _localCollections.clear(); + _localPathToCollectionID.clear(); _collectionIDToCollections.clear(); _cachedKeys.clear(); } @@ -578,9 +578,14 @@ class CollectionsService { } Future 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()); @@ -882,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; From 2f3b75b29f2673ceb64397ebd54cda463ff370b9 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:21:50 +0530 Subject: [PATCH 4/6] Hide delete album option for favorites collection --- .../gallery/gallery_app_bar_widget.dart | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart index eea8b4e2e..1b5d2befc 100644 --- a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -194,20 +194,22 @@ class _GalleryAppBarWidgetState extends State { ), ), ); - 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_sweep_outlined), + Padding( + padding: EdgeInsets.all(8), + ), + Text("Delete Album"), + ], + ), ), - ), - ); + ); + } return items; }, onSelected: (value) async { From 571c258f78881ba39cb655abb3464f29c18f2a23 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:34:41 +0530 Subject: [PATCH 5/6] copy changes --- lib/ui/viewer/gallery/gallery_app_bar_widget.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart index 1b5d2befc..812f7d73c 100644 --- a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -163,7 +163,7 @@ class _GalleryAppBarWidgetState extends State { PopupMenuButton( itemBuilder: (context) { final List 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 { Padding( padding: EdgeInsets.all(8), ), - Text("Rename"), + Text("Rename album"), ], ), ), @@ -189,7 +189,7 @@ class _GalleryAppBarWidgetState extends State { const Padding( padding: EdgeInsets.all(8), ), - Text(isArchived ? "Unhide" : "Hide"), + Text(isArchived ? "Unhide album" : "Hide album"), ], ), ), @@ -200,11 +200,11 @@ class _GalleryAppBarWidgetState extends State { value: 3, child: Row( children: const [ - Icon(Icons.delete_sweep_outlined), + Icon(Icons.delete_outline), Padding( padding: EdgeInsets.all(8), ), - Text("Delete Album"), + Text("Delete album"), ], ), ), From 2fc24b90865882aab172431c1caeda494abfe3ba Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:44:08 +0530 Subject: [PATCH 6/6] Always show favorite album first --- lib/ui/collections_gallery_widget.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ui/collections_gallery_widget.dart b/lib/ui/collections_gallery_widget.dart index 8e29674a4..bbb7bdfb8 100644 --- a/lib/ui/collections_gallery_widget.dart +++ b/lib/ui/collections_gallery_widget.dart @@ -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 } 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);