From e2e1d7ef135b050a276e829f97c9fee05fd7f737 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 23 May 2023 10:26:48 +0530 Subject: [PATCH] Replace collection.name usage with collection.displayName --- lib/models/collection.dart | 5 +++-- lib/models/duplicate_files.dart | 11 ++++++----- lib/models/search/album_search_result.dart | 2 +- lib/services/search_service.dart | 2 +- .../collection/collection_sharing_actions.dart | 2 +- lib/ui/collection_action_sheet.dart | 6 +++--- lib/ui/collections/collection_item_widget.dart | 2 +- lib/ui/collections_gallery_widget.dart | 4 ++-- lib/ui/collections_list_widget.dart | 10 ++++++---- lib/ui/components/album_list_item_widget.dart | 2 +- lib/ui/shared_collections_gallery.dart | 4 ++-- lib/ui/sharing/album_participants_page.dart | 2 +- lib/ui/sharing/share_collection_page.dart | 2 +- lib/ui/tools/deduplicate_page.dart | 2 +- lib/ui/viewer/file_details/albums_item_widget.dart | 2 +- lib/ui/viewer/gallery/collection_page.dart | 4 ++-- 16 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/models/collection.dart b/lib/models/collection.dart index 4dae67dc1..d11851f41 100644 --- a/lib/models/collection.dart +++ b/lib/models/collection.dart @@ -9,6 +9,7 @@ class Collection { final User? owner; final String encryptedKey; final String? keyDecryptionNonce; + @Deprecated("Use collectionName instead") final String? name; // encryptedName & nameDecryptionNonce will be null for collections // created before we started encrypting collection name @@ -38,6 +39,8 @@ class Collection { set magicMetadata(val) => _mmd = val; + String get displayName => decryptedName ?? name ?? "Unnamed collection"; + Collection( this.id, this.owner, @@ -97,8 +100,6 @@ class Collection { return (owner?.id ?? 0) == userID; } - String get collectionName => name ?? "Unnamed collection"; - void updateSharees(List newSharees) { sharees?.clear(); sharees?.addAll(newSharees); diff --git a/lib/models/duplicate_files.dart b/lib/models/duplicate_files.dart index ae824108f..8ba971501 100644 --- a/lib/models/duplicate_files.dart +++ b/lib/models/duplicate_files.dart @@ -55,11 +55,12 @@ class DuplicateFiles { sortByCollectionName() { files.sort((first, second) { - final firstName = - collectionsService.getCollectionByID(first.collectionID!)!.name ?? ''; - final secondName = - collectionsService.getCollectionByID(second.collectionID!)!.name ?? - ''; + final firstName = collectionsService + .getCollectionByID(first.collectionID!)! + .displayName; + final secondName = collectionsService + .getCollectionByID(second.collectionID!)! + .displayName; return firstName.compareTo(secondName); }); } diff --git a/lib/models/search/album_search_result.dart b/lib/models/search/album_search_result.dart index 01eb5906f..fcdc8b47a 100644 --- a/lib/models/search/album_search_result.dart +++ b/lib/models/search/album_search_result.dart @@ -14,7 +14,7 @@ class AlbumSearchResult extends SearchResult { @override String name() { - return collectionWithThumbnail.collection.name!; + return collectionWithThumbnail.collection.displayName; } @override diff --git a/lib/services/search_service.dart b/lib/services/search_service.dart index 6fc0e68b5..6ee7269dc 100644 --- a/lib/services/search_service.dart +++ b/lib/services/search_service.dart @@ -76,7 +76,7 @@ class SearchService { if (!c.collection.isHidden() && c.collection.type != CollectionType.uncategorized && - c.collection.name!.toLowerCase().contains( + c.collection.displayName.toLowerCase().contains( query.toLowerCase(), )) { collectionSearchResults.add(AlbumSearchResult(c)); diff --git a/lib/ui/actions/collection/collection_sharing_actions.dart b/lib/ui/actions/collection/collection_sharing_actions.dart index 462b9f79b..3f3b048d9 100644 --- a/lib/ui/actions/collection/collection_sharing_actions.dart +++ b/lib/ui/actions/collection/collection_sharing_actions.dart @@ -81,7 +81,7 @@ class CollectionActions { title: S.of(context).removePublicLink, body: //'This will remove the public link for accessing "${collection.name}".', - S.of(context).disableLinkMessage(collection.collectionName), + S.of(context).disableLinkMessage(collection.displayName), ); if (actionResult?.action != null) { if (actionResult!.action == ButtonAction.error) { diff --git a/lib/ui/collection_action_sheet.dart b/lib/ui/collection_action_sheet.dart index 6841b412f..bbff7cfdb 100644 --- a/lib/ui/collection_action_sheet.dart +++ b/lib/ui/collection_action_sheet.dart @@ -218,7 +218,7 @@ class _CollectionActionSheetState extends State { final searchResults = _searchQuery.isNotEmpty ? collectionsWithThumbnail .where( - (element) => element.collection.name! + (element) => element.collection.displayName .toLowerCase() .contains(_searchQuery), ) @@ -263,8 +263,8 @@ class _CollectionActionSheetState extends State { ); collectionsWithThumbnail.sort((first, second) { return compareAsciiLowerCaseNatural( - first.collection.name ?? "", - second.collection.name ?? "", + first.collection.displayName, + second.collection.displayName, ); }); return collectionsWithThumbnail; diff --git a/lib/ui/collections/collection_item_widget.dart b/lib/ui/collections/collection_item_widget.dart index 9c275dd61..4ba0e946c 100644 --- a/lib/ui/collections/collection_item_widget.dart +++ b/lib/ui/collections/collection_item_widget.dart @@ -62,7 +62,7 @@ class CollectionItem extends StatelessWidget { children: [ const SizedBox(height: 2), Text( - (c.collection.collectionName).trim(), + (c.collection.displayName).trim(), style: enteTextTheme.small, overflow: TextOverflow.ellipsis, ), diff --git a/lib/ui/collections_gallery_widget.dart b/lib/ui/collections_gallery_widget.dart index 6fe3ef975..29789061f 100644 --- a/lib/ui/collections_gallery_widget.dart +++ b/lib/ui/collections_gallery_widget.dart @@ -107,8 +107,8 @@ class _CollectionsGalleryWidgetState extends State (first, second) { if (sortKey == AlbumSortKey.albumName) { return compareAsciiLowerCaseNatural( - first.collection.name!, - second.collection.name!, + first.collection.displayName, + second.collection.displayName, ); } else if (sortKey == AlbumSortKey.newestPhoto) { return (second.thumbnail?.creationTime ?? -1 * intMaxValue) diff --git a/lib/ui/collections_list_widget.dart b/lib/ui/collections_list_widget.dart index 10112ff85..75157020c 100644 --- a/lib/ui/collections_list_widget.dart +++ b/lib/ui/collections_list_widget.dart @@ -181,12 +181,14 @@ class CollectionsListWidget extends StatelessWidget { late final String toastMessage; bool shouldNavigateToCollection = false; if (actionType == CollectionActionType.addFiles) { - toastMessage = S.of(context).addedSuccessfullyTo(item.collection.name!); + toastMessage = + S.of(context).addedSuccessfullyTo(item.collection.displayName); shouldNavigateToCollection = true; } else if (actionType == CollectionActionType.moveFiles || actionType == CollectionActionType.restoreFiles || actionType == CollectionActionType.unHide) { - toastMessage = S.of(context).movedSuccessfullyTo(item.collection.name!); + toastMessage = + S.of(context).movedSuccessfullyTo(item.collection.displayName); shouldNavigateToCollection = true; } else { toastMessage = ""; @@ -275,7 +277,7 @@ class CollectionsListWidget extends StatelessWidget { .updateShareUrl(collection, {'enableCollect': true}).then( (value) => showShortToast( context, - S.of(context).collaborativeLinkCreatedFor(collection.name!), + S.of(context).collaborativeLinkCreatedFor(collection.displayName), ), ); return true; @@ -293,7 +295,7 @@ class CollectionsListWidget extends StatelessWidget { if (result) { showShortToast( context, - S.of(context).collaborativeLinkCreatedFor(collection.name!), + S.of(context).collaborativeLinkCreatedFor(collection.displayName), ); if (Configuration.instance.getUserID() == collection.owner!.id) { unawaited( diff --git a/lib/ui/components/album_list_item_widget.dart b/lib/ui/components/album_list_item_widget.dart index dc6e804d3..021669148 100644 --- a/lib/ui/components/album_list_item_widget.dart +++ b/lib/ui/components/album_list_item_widget.dart @@ -52,7 +52,7 @@ class AlbumListItemWidget extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(item.collection.collectionName), + Text(item.collection.displayName), FutureBuilder( future: FilesDB.instance.collectionFileCount( item.collection.id, diff --git a/lib/ui/shared_collections_gallery.dart b/lib/ui/shared_collections_gallery.dart index af0ddfa79..416b9caee 100644 --- a/lib/ui/shared_collections_gallery.dart +++ b/lib/ui/shared_collections_gallery.dart @@ -343,7 +343,7 @@ class OutgoingCollectionItem extends StatelessWidget { Row( children: [ Text( - c.collection.name!, + c.collection.displayName, style: const TextStyle( fontSize: 16, ), @@ -449,7 +449,7 @@ class IncomingCollectionItem extends StatelessWidget { Container( constraints: BoxConstraints(maxWidth: sideOfThumbnail - 40), child: Text( - c.collection.name!, + c.collection.displayName, style: albumTitleTextStyle, overflow: TextOverflow.ellipsis, ), diff --git a/lib/ui/sharing/album_participants_page.dart b/lib/ui/sharing/album_participants_page.dart index b3ac48d3d..f626a8a53 100644 --- a/lib/ui/sharing/album_participants_page.dart +++ b/lib/ui/sharing/album_participants_page.dart @@ -83,7 +83,7 @@ class _AlbumParticipantsPageState extends State { slivers: [ TitleBarWidget( flexibleSpaceTitle: TitleBarTitleWidget( - title: "${widget.collection.name}", + title: widget.collection.displayName, ), flexibleSpaceCaption: S.of(context).albumParticipantsCount(participants), diff --git a/lib/ui/sharing/share_collection_page.dart b/lib/ui/sharing/share_collection_page.dart index da3e0c749..2f5626817 100644 --- a/lib/ui/sharing/share_collection_page.dart +++ b/lib/ui/sharing/share_collection_page.dart @@ -288,7 +288,7 @@ class _ShareCollectionPageState extends State { return Scaffold( appBar: AppBar( title: Text( - widget.collection.name ?? "Unnamed", + widget.collection.displayName, style: Theme.of(context).textTheme.headline5?.copyWith(fontSize: 16), ), elevation: 0, diff --git a/lib/ui/tools/deduplicate_page.dart b/lib/ui/tools/deduplicate_page.dart index ad29e33f8..b2163706b 100644 --- a/lib/ui/tools/deduplicate_page.dart +++ b/lib/ui/tools/deduplicate_page.dart @@ -480,7 +480,7 @@ class _DeduplicatePageState extends State { child: Text( CollectionsService.instance .getCollectionByID(file.collectionID!)! - .name!, + .displayName, style: Theme.of(context).textTheme.caption!.copyWith(fontSize: 12), overflow: TextOverflow.ellipsis, diff --git a/lib/ui/viewer/file_details/albums_item_widget.dart b/lib/ui/viewer/file_details/albums_item_widget.dart index 6d54f0f6b..142af8cd9 100644 --- a/lib/ui/viewer/file_details/albums_item_widget.dart +++ b/lib/ui/viewer/file_details/albums_item_widget.dart @@ -83,7 +83,7 @@ class AlbumsItemWidget extends StatelessWidget { collections.add(c!); chipButtons.add( ChipButtonWidget( - c.isHidden() ? S.of(context).hidden : c.name, + c.isHidden() ? S.of(context).hidden : c.displayName, onTap: () { if (c.isHidden()) { return; diff --git a/lib/ui/viewer/gallery/collection_page.dart b/lib/ui/viewer/gallery/collection_page.dart index 3903fb043..3ac15c260 100644 --- a/lib/ui/viewer/gallery/collection_page.dart +++ b/lib/ui/viewer/gallery/collection_page.dart @@ -73,14 +73,14 @@ class CollectionPage extends StatelessWidget { tagPrefix: tagPrefix, selectedFiles: _selectedFiles, initialFiles: initialFiles, - albumName: c.collection.name, + albumName: c.collection.displayName, ); return Scaffold( appBar: PreferredSize( preferredSize: const Size.fromHeight(50.0), child: GalleryAppBarWidget( appBarTypeValue, - c.collection.name, + c.collection.displayName, _selectedFiles, collection: c.collection, ),