π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] made shared_public_collection to handle public link seprately
Aman Raj Singh Mouryad6bed953a190
diff --git a/mobile/lib/models/gallery_type.dart b/mobile/lib/models/gallery_type.dartindex d0ad67774f..54028ee8a2 100644--- a/mobile/lib/models/gallery_type.dart+++ b/mobile/lib/models/gallery_type.dart@@ -20,7 +20,7 @@ enum GalleryType {quickLink,peopleTag,cluster,- sharedPublicLink,+ sharedPublicCollection,magic,}@@ -45,7 +45,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.hiddenOwnedCollection:case GalleryType.trash:case GalleryType.cluster:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:return false;}}@@ -69,7 +69,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.sharedCollection:case GalleryType.locationTag:case GalleryType.cluster:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:case GalleryType.magic:return false;}@@ -96,7 +96,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.hiddenSection:case GalleryType.hiddenOwnedCollection:case GalleryType.sharedCollection:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:return false;}}@@ -120,7 +120,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.trash:case GalleryType.cluster:case GalleryType.sharedCollection:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:return false;}}@@ -144,7 +144,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.trash:case GalleryType.sharedCollection:case GalleryType.quickLink:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:return false;}}@@ -167,7 +167,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.cluster:case GalleryType.trash:case GalleryType.locationTag:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:case GalleryType.magic:return false;}@@ -193,7 +193,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.trash:case GalleryType.sharedCollection:case GalleryType.cluster:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:return false;}}@@ -222,7 +222,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.favorite:case GalleryType.cluster:case GalleryType.sharedCollection:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:return false;}}@@ -252,7 +252,7 @@ extension GalleyTypeExtension on GalleryType {case GalleryType.localFolder:case GalleryType.trash:case GalleryType.sharedCollection:- case GalleryType.sharedPublicLink:+ case GalleryType.sharedPublicCollection:return false;}}@@ -295,7 +295,7 @@ extension GalleryAppBarExtn on GalleryType {this == GalleryType.hiddenOwnedCollection) {return true;}- if (this == GalleryType.sharedPublicLink && c!.isEnableCollect()) {+ if (this == GalleryType.sharedPublicCollection && c!.isEnableCollect()) {return true;}if (this == GalleryType.sharedCollection) {@@ -377,7 +377,8 @@ extension GalleryAppBarExtn on GalleryType {case GalleryType.locationTag:case GalleryType.searchResults:case GalleryType.magic:- return true;+ case GalleryType.sharedPublicCollection:+ return false;case GalleryType.uncategorized:case GalleryType.cluster:case GalleryType.peopleTag:@@ -386,7 +387,6 @@ extension GalleryAppBarExtn on GalleryType {case GalleryType.quickLink:case GalleryType.favorite:case GalleryType.hiddenOwnedCollection:- case GalleryType.sharedPublicLink:return true;}}@@ -394,7 +394,7 @@ extension GalleryAppBarExtn on GalleryType {GalleryType getGalleryType(Collection c, int userID) {if (c.type == CollectionType.album) {- return GalleryType.sharedPublicLink;+ return GalleryType.sharedPublicCollection;}if (!c.isOwner(userID)) {return GalleryType.sharedCollection;diff --git a/mobile/lib/ui/tabs/home_widget.dart b/mobile/lib/ui/tabs/home_widget.dartindex 8d3f43f6ed..e4a607cacf 100644--- a/mobile/lib/ui/tabs/home_widget.dart+++ b/mobile/lib/ui/tabs/home_widget.dart@@ -55,6 +55,7 @@ import "package:photos/ui/settings_page.dart";import "package:photos/ui/tabs/shared_collections_tab.dart";import "package:photos/ui/tabs/user_collections_tab.dart";import "package:photos/ui/viewer/gallery/collection_page.dart";+import "package:photos/ui/viewer/gallery/shared_public_collection_page.dart";import "package:photos/ui/viewer/search/search_widget.dart";import 'package:photos/ui/viewer/search_tab/search_tab.dart';import "package:photos/utils/crypto_util.dart";@@ -301,9 +302,8 @@ class _HomeWidgetState extends State<HomeWidget> {await routeToPage(context,- CollectionPage(- isFromPublicShareLink: true,- sharedLinkFiles: sharedFiles,+ SharedPublicCollectionPage(+ files: sharedFiles,CollectionWithThumbnail(collection,null,diff --git a/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dartindex d6ec440bb6..181334cdf8 100644--- a/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart+++ b/mobile/lib/ui/viewer/actions/file_selection_actions_widget.dart@@ -284,14 +284,16 @@ class _FileSelectionActionsWidgetStateonTap: _onGuestViewClick,),);- items.add(- SelectionActionButton(- icon: Icons.grid_view_outlined,- labelText: S.of(context).createCollage,- onTap: _onCreateCollageClicked,- shouldShow: showCollageOption,- ),- );+ if (widget.type != GalleryType.sharedPublicCollection) {+ items.add(+ SelectionActionButton(+ icon: Icons.grid_view_outlined,+ labelText: S.of(context).createCollage,+ onTap: _onCreateCollageClicked,+ shouldShow: showCollageOption,+ ),+ );+ }if (widget.type.showDeleteOption()) {items.add(@@ -422,19 +424,20 @@ class _FileSelectionActionsWidgetState),);}-- items.add(- SelectionActionButton(- labelText: S.of(context).share,- icon: Icons.adaptive.share_outlined,- key: shareButtonKey,- onTap: () => shareSelected(- context,- shareButtonKey,- widget.selectedFiles.files.toList(),+ if (widget.type != GalleryType.sharedPublicCollection) {+ items.add(+ SelectionActionButton(+ labelText: S.of(context).share,+ icon: Icons.adaptive.share_outlined,+ key: shareButtonKey,+ onTap: () => shareSelected(+ context,+ shareButtonKey,+ widget.selectedFiles.files.toList(),+ ),),- ),- );+ );+ }// if (widget.type == GalleryType.cluster && widget.clusterID != null) {if (widget.type == GalleryType.cluster && widget.clusterID != null) {diff --git a/mobile/lib/ui/viewer/gallery/collection_page.dart b/mobile/lib/ui/viewer/gallery/collection_page.dartindex 0cfecb4410..67a53961e6 100644--- a/mobile/lib/ui/viewer/gallery/collection_page.dart+++ b/mobile/lib/ui/viewer/gallery/collection_page.dart@@ -24,8 +24,6 @@ class CollectionPage extends StatelessWidget {final String tagPrefix;final bool? hasVerifiedLock;final bool isFromCollectPhotos;- final bool isFromPublicShareLink;- final List<EnteFile>? sharedLinkFiles;CollectionPage(this.c, {@@ -33,12 +31,7 @@ class CollectionPage extends StatelessWidget {this.hasVerifiedLock = false,this.isFromCollectPhotos = false,super.key,- this.isFromPublicShareLink = false,- this.sharedLinkFiles,- }) : assert(- !(isFromPublicShareLink && sharedLinkFiles == null),- 'sharedLinkFiles cannot be empty if isFromPublicShareLink is true',- );+ });final _selectedFiles = SelectedFiles();@@ -56,9 +49,6 @@ class CollectionPage extends StatelessWidget {c.thumbnail != null ? [c.thumbnail!] : null;final gallery = Gallery(asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {- if (isFromPublicShareLink) {- return FileLoadResult(sharedLinkFiles!, false);- }final FileLoadResult result =await FilesDB.instance.getFilesInCollection(c.collection.id,@@ -117,7 +107,6 @@ class CollectionPage extends StatelessWidget {_selectedFiles,collection: c.collection,isFromCollectPhotos: isFromCollectPhotos,- sharedLinkFiles: sharedLinkFiles,),),bottomNavigationBar: isFromCollectPhotosdiff --git a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dartindex 110dd65e37..4594d957fb 100644--- a/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart+++ b/mobile/lib/ui/viewer/gallery/gallery_app_bar_widget.dart@@ -56,8 +56,7 @@ class GalleryAppBarWidget extends StatefulWidget {final DeviceCollection? deviceCollection;final Collection? collection;final bool isFromCollectPhotos;- final bool isFromPublicShareLink;- final List<EnteFile> files;+ final List<EnteFile>? files;const GalleryAppBarWidget(this.type,@@ -67,8 +66,7 @@ class GalleryAppBarWidget extends StatefulWidget {this.deviceCollection,this.collection,this.isFromCollectPhotos = false,- this.isFromPublicShareLink = false,- this.files = const [],+ this.files,});@override@@ -498,19 +496,18 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {value: AlbumPopupAction.freeUpSpace,icon: Icons.delete_sweep_outlined,),+ if (galleryType == GalleryType.sharedPublicCollection &&+ widget.collection!.isPublicDownload())+ EntePopupMenuItem(+ "Download album",+ value: AlbumPopupAction.downloadAlbum,+ icon: Platform.isAndroid+ ? Icons.download+ : Icons.cloud_download_outlined,+ ),],);- if (widget.isFromPublicShareLink) {- actions.clear();- items.clear();- items.add(- EntePopupMenuItem(- "Download album",- value: AlbumPopupAction.downloadAlbum,- icon: Icons.download_outlined,- ),- );- }+if (items.isNotEmpty) {actions.add(PopupMenuButton(@@ -567,7 +564,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {} else if (value == AlbumPopupAction.cleanUncategorized) {await onCleanUncategorizedClick(context);} else if (value == AlbumPopupAction.downloadAlbum) {- await _downloadPublicAlbumToGallery(widget.files);+ await _downloadPublicAlbumToGallery(widget.files!);} else {showToast(context, S.of(context).somethingWentWrong);}@@ -579,11 +576,23 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {return actions;}- Future<void> _downloadPublicAlbumToGallery(List<EnteFile> files) async {- final dialog = createProgressDialog(context, "Downloading album");+ Future<void> _downloadPublicAlbumToGallery(List<EnteFile>? files) async {+ if (files == null || files.isEmpty) {+ return;+ }+ final totalFiles = files.length;+ final dialog = createProgressDialog(+ context,+ "Downloading... 0/$totalFiles",+ isDismissible: true,+ );await dialog.show();+try {- await downloadPublicAlbumToGallery(files);+ for (var i = 0; i < files.length; i++) {+ await downloadToGallery(files[i]);+ dialog.update(message: "Downloading... ${i + 1}/$totalFiles");+ }} catch (e, s) {_logger.severe("Failed to download album", e, s);await showGenericErrorDialog(context: context, error: e);diff --git a/mobile/lib/ui/viewer/gallery/shared_public_collection_page.dart b/mobile/lib/ui/viewer/gallery/shared_public_collection_page.dartnew file mode 100644index 0000000000..542a95dadb--- /dev/null+++ b/mobile/lib/ui/viewer/gallery/shared_public_collection_page.dart@@ -0,0 +1,100 @@+import "package:flutter/material.dart";+import "package:photos/core/configuration.dart";+import "package:photos/core/event_bus.dart";+import "package:photos/events/collection_meta_event.dart";+import "package:photos/events/collection_updated_event.dart";+import "package:photos/events/files_updated_event.dart";+import "package:photos/models/collection/collection_items.dart";+import "package:photos/models/file/file.dart";+import "package:photos/models/file_load_result.dart";+import "package:photos/models/gallery_type.dart";+import "package:photos/models/selected_files.dart";+import "package:photos/ui/viewer/actions/file_selection_overlay_bar.dart";+import "package:photos/ui/viewer/gallery/gallery.dart";+import "package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart";+import "package:photos/ui/viewer/gallery/state/selection_state.dart";++class SharedPublicCollectionPage extends StatelessWidget {+ final CollectionWithThumbnail c;+ final String tagPrefix;+ final List<EnteFile>? files;++ SharedPublicCollectionPage(+ this.c, {+ this.tagPrefix = "shared_public_collection",+ super.key,+ this.files,+ }) : assert(+ !(files == null),+ 'sharedLinkFiles cannot be empty',+ );++ final _selectedFiles = SelectedFiles();++ @override+ Widget build(BuildContext context) {+ final bool isPublicDownload = c.collection.isPublicDownload();+ final bool isisEnableCollect = c.collection.isEnableCollect();+ final galleryType = getGalleryType(+ c.collection,+ Configuration.instance.getUserID()!,+ );+ final List<EnteFile>? initialFiles =+ c.thumbnail != null ? [c.thumbnail!] : null;+ final gallery = Gallery(+ asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {+ return FileLoadResult(files!, false);+ },+ reloadEvent: Bus.instance+ .on<CollectionUpdatedEvent>()+ .where((event) => event.collectionID == c.collection.id),+ forceReloadEvents: [+ Bus.instance.on<CollectionMetaEvent>().where(+ (event) =>+ event.id == c.collection.id &&+ event.type == CollectionMetaEventType.sortChanged,+ ),+ ],+ removalEventTypes: const {+ EventType.deletedFromRemote,+ EventType.deletedFromEverywhere,+ EventType.hide,+ },+ tagPrefix: tagPrefix,+ selectedFiles: _selectedFiles,+ initialFiles: initialFiles,+ albumName: c.collection.displayName,+ sortAsyncFn: () => c.collection.pubMagicMetadata.asc ?? false,+ showSelectAllByDefault: galleryType != GalleryType.sharedPublicCollection,+ );++ return Scaffold(+ appBar: PreferredSize(+ preferredSize: const Size.fromHeight(50.0),+ child: GalleryAppBarWidget(+ galleryType,+ c.collection.displayName,+ _selectedFiles,+ collection: c.collection,+ files: files,+ ),+ ),+ body: SelectionState(+ selectedFiles: _selectedFiles,+ child: Stack(+ alignment: Alignment.bottomCenter,+ children: [+ gallery,+ !isPublicDownload && !isisEnableCollect+ ? const SizedBox.shrink()+ : FileSelectionOverlayBar(+ galleryType,+ _selectedFiles,+ collection: c.collection,+ ),+ ],+ ),+ ),+ );+ }+}diff --git a/mobile/lib/utils/file_download_util.dart b/mobile/lib/utils/file_download_util.dartindex a1b080c613..17d58a2ea4 100644--- a/mobile/lib/utils/file_download_util.dart+++ b/mobile/lib/utils/file_download_util.dart@@ -206,12 +206,6 @@ Future<Uint8List> getFileKeyUsingBgWorker(EnteFile file) async {);}-Future<void> downloadPublicAlbumToGallery(List<EnteFile> files) async {- for (final file in files) {- await downloadToGallery(file);- }-}-Future<void> downloadToGallery(EnteFile file) async {try {final FileType type = file.fileType;