π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Share photos from person pages (#12685)
aman-pilot958aedb638db
diff --git a/mobile/apps/photos/changes/share-person-photos.md b/mobile/apps/photos/changes/share-person-photos.mdnew file mode 100644index 0000000000..1bd046bf98--- /dev/null+++ b/mobile/apps/photos/changes/share-person-photos.md@@ -0,0 +1 @@+- Added support for sharing photos from person pages.diff --git a/mobile/apps/photos/lib/ui/sharing/share_person_sheet.dart b/mobile/apps/photos/lib/ui/sharing/share_person_sheet.dartnew file mode 100644index 0000000000..1b29c3b607--- /dev/null+++ b/mobile/apps/photos/lib/ui/sharing/share_person_sheet.dart@@ -0,0 +1,390 @@+import 'dart:async';++import 'package:ente_components/ente_components.dart';+import 'package:ente_pure_utils/ente_pure_utils.dart';+import 'package:ente_strings/ente_strings.dart';+import 'package:flutter/material.dart';+import 'package:hugeicons/hugeicons.dart';+import 'package:logging/logging.dart';+import 'package:photos/core/errors.dart';+import 'package:photos/models/collection/collection.dart';+import 'package:photos/models/file/file.dart';+import 'package:photos/models/file_load_result.dart';+import 'package:photos/models/ml/face/person.dart';+import 'package:photos/models/selected_files.dart';+import 'package:photos/service_locator.dart' as services;+import 'package:photos/services/collections_service.dart';+import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';+import 'package:photos/ui/payment/subscription.dart';+import 'package:photos/ui/viewer/gallery/gallery.dart';+import 'package:photos/ui/viewer/gallery/state/boundary_reporter_mixin.dart';+import 'package:photos/ui/viewer/gallery/state/gallery_boundaries_provider.dart';+import 'package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart';+import 'package:photos/utils/dialog_util.dart';+import 'package:photos/utils/share_util.dart';++const maxPersonRawShareFiles = 50;++Future<void> showSharePersonSheet(+ BuildContext context, {+ required List<EnteFile> files,+ required GlobalKey shareButtonKey,+ PersonEntity? person,+}) async {+ final album = await showBottomSheetComponent<Collection>(+ context: context,+ builder: (_) => _SharePersonSheet(person: person, files: files),+ );+ if (album == null || !context.mounted) return;+ await shareText(+ CollectionsService.instance.getPublicUrl(album),+ context: context,+ key: shareButtonKey,+ );+}++class _SharePersonSheet extends StatefulWidget {+ const _SharePersonSheet({required this.person, required this.files});++ final PersonEntity? person;+ final List<EnteFile> files;++ @override+ State<_SharePersonSheet> createState() => _SharePersonSheetState();+}++class _SharePersonSheetState extends State<_SharePersonSheet> {+ final _logger = Logger('_SharePersonSheetState');+ final _rawShareButtonKey = GlobalKey();+ final _selectedFiles = SelectedFiles();+ late Set<EnteFile> _selectionBeforeAutoAdd;+ bool _autoAdd = false;++ List<EnteFile> get _filesToShare =>+ widget.files.where(_selectedFiles.isFileSelected).toList();+ bool get _canShareFiles =>+ !_autoAdd &&+ _selectedFiles.files.isNotEmpty &&+ _selectedFiles.files.length <= maxPersonRawShareFiles;++ @override+ void initState() {+ super.initState();+ _selectedFiles.addListener(() => setState(() {}));+ }++ @override+ void dispose() {+ _selectedFiles.dispose();+ super.dispose();+ }++ void _setAutoAdd(bool value) {+ _autoAdd = value;+ if (value) {+ _selectionBeforeAutoAdd = Set.of(_selectedFiles.files);+ _selectedFiles.replaceSelection(widget.files.toSet());+ } else {+ _selectedFiles.replaceSelection(_selectionBeforeAutoAdd);+ }+ }++ @override+ Widget build(BuildContext context) {+ final strings = context.strings;+ final colors = context.componentColors;+ final person = widget.person;+ return FractionallySizedBox(+ heightFactor: 0.86,+ alignment: Alignment.bottomCenter,+ child: GalleryBoundariesProvider(+ child: BottomSheetComponent(+ padding: const EdgeInsets.symmetric(vertical: Spacing.xl),+ header: _SharePersonSheetBoundary(+ position: BoundaryPosition.top,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),+ child: Row(+ children: [+ Expanded(+ child: Text(+ person == null+ ? strings.sharePhotos+ : strings.sharePersonPhotos(name: person.data.name),+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: TextStyles.h2.copyWith(color: colors.textBase),+ ),+ ),+ const SizedBox(width: Spacing.md),+ IconButtonComponent(+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedCancel01),+ variant: IconButtonComponentVariant.circular,+ tooltip: strings.close,+ onTap: () => Navigator.of(context).pop(),+ ),+ ],+ ),+ ),+ ),+ showCloseButton: false,+ content: Expanded(child: _buildContent(context)),+ actions: [+ _SharePersonSheetBoundary(+ position: BoundaryPosition.bottom,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ ButtonComponent(+ label: strings.shareLink,+ density: ButtonComponentDensity.compact,+ isDisabled: _selectedFiles.files.isEmpty,+ shouldSurfaceExecutionStates: false,+ leading: const HugeIcon(+ icon: HugeIcons.strokeRoundedLink02,+ size: IconSizes.small,+ ),+ onTap: _shareLink,+ ),+ AnimatedCrossFade(+ duration: Motion.standard,+ firstCurve: Curves.easeInOut,+ secondCurve: Curves.easeInOut,+ sizeCurve: Curves.easeInOut,+ crossFadeState: _canShareFiles+ ? CrossFadeState.showFirst+ : CrossFadeState.showSecond,+ firstChild: Padding(+ padding: const EdgeInsets.only(top: Spacing.md),+ child: ButtonComponent(+ key: _rawShareButtonKey,+ label: strings.shareItemCount(+ count: _selectedFiles.files.length,+ ),+ density: ButtonComponentDensity.compact,+ variant: ButtonComponentVariant.secondary,+ shouldSurfaceExecutionStates: false,+ onTap: _shareFiles,+ ),+ ),+ secondChild: const SizedBox.shrink(),+ ),+ ],+ ),+ ),+ ),+ ],+ ),+ ),+ );+ }++ Widget _buildContent(BuildContext context) {+ final strings = context.strings;+ final person = widget.person;+ final selection = Padding(+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),+ child: Column(+ children: [+ _selectionRow(context),+ const SizedBox(height: Spacing.lg),+ ],+ ),+ );+ return Column(+ children: [+ if (person == null)+ selection+ else ...[+ AnimatedCrossFade(+ duration: Motion.standard,+ firstCurve: Curves.easeInOut,+ secondCurve: Curves.easeInOut,+ sizeCurve: Curves.easeInOut,+ crossFadeState: _autoAdd+ ? CrossFadeState.showSecond+ : CrossFadeState.showFirst,+ firstChild: selection,+ secondChild: const SizedBox.shrink(),+ ),+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: Spacing.xl),+ child: MenuComponent(+ title: strings.shareAllPersonPhotos,+ subtitle: strings.shareAllPersonPhotosDescription(+ name: person.data.name,+ ),+ trailing: ToggleSwitchComponent(+ selected: _autoAdd,+ onChanged: _setAutoAdd,+ ),+ ),+ ),+ const SizedBox(height: Spacing.lg),+ ],+ Expanded(child: _buildGallery()),+ ],+ );+ }++ Widget _selectionRow(BuildContext context) {+ final strings = context.strings;+ return Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ SelectionSummaryChipComponent(+ label: strings.selectAll,+ icon: const HugeIcon(+ icon: HugeIcons.strokeRoundedTick02,+ size: IconSizes.small,+ ),+ semanticLabel: strings.selectAll,+ isSelected: _selectedFiles.files.length == widget.files.length,+ onTap: _selectedFiles.files.length == widget.files.length+ ? null+ : () => _selectedFiles.replaceSelection(widget.files.toSet()),+ ),+ SelectionSummaryChipComponent(+ label: strings.selectedPhotos(count: _selectedFiles.files.length),+ icon: const HugeIcon(+ icon: HugeIcons.strokeRoundedCancel01,+ size: IconSizes.small,+ ),+ semanticLabel: strings.clearSelection,+ isSelected: _selectedFiles.files.isNotEmpty,+ onTap: _selectedFiles.files.isEmpty+ ? null+ : () => _selectedFiles.clearAll(fireEvent: false),+ ),+ ],+ );+ }++ Widget _buildGallery() {+ return GalleryFilesState(+ child: Gallery(+ initialFiles: widget.files,+ asyncLoader: (_, _, {limit, asc}) async =>+ FileLoadResult(widget.files, false),+ tagPrefix: 'person_share_gallery',+ selectedFiles: _selectedFiles,+ enableFileGrouping: false,+ inSelectionMode: true,+ disableSelection: _autoAdd,+ showSelectAll: false,+ disablePinnedGroupHeader: true,+ disableVerticalPaddingForScrollbar: true,+ footer: const SizedBox.shrink(),+ ),+ );+ }++ Future<void> _shareLink() async {+ final person = widget.person;+ final albumName = person == null+ ? context.strings.unnamedPersonAlbumName(+ date: getDateAndMonthAndYear(DateTime.now()),+ )+ : person.data.name.trim();+ final dialog = createProgressDialog(context, context.strings.creatingLink);+ await dialog.show();+ final collections = CollectionsService.instance;+ Collection? album;+ try {+ album = await collections.createAlbum(albumName);+ await collections.addOrCopyToCollection(+ album.id,+ _filesToShare.map((file) => file.copyWith()).toList(),+ toCopy: false,+ );+ await collections.createShareUrl(album);+ if (_autoAdd) {+ await services.smartAlbumsService.addPeopleToSmartAlbum(album.id, [+ person!.remoteID,+ ]);+ unawaited(services.smartAlbumsService.syncSmartAlbums());+ }+ await dialog.hide();+ if (mounted) Navigator.of(context).pop(album);+ } catch (error, stack) {+ if (album != null) {+ try {+ await CollectionActions(+ collections,+ ).trashCollectionKeepingPhotos(album);+ } catch (cleanupError, cleanupStack) {+ _logger.severe(+ 'Could not roll back person album ${album.id}',+ cleanupError,+ cleanupStack,+ );+ await dialog.hide();+ if (!mounted) return;+ await showErrorDialog(+ context,+ context.strings.personShareFailedTitle,+ context.strings.personShareRollbackFailed(name: album.displayName),+ );+ return;+ }+ }+ await dialog.hide();+ if (!mounted) return;+ if (error is SharingNotPermittedForFreeAccountsError) {+ final upgrade = await showBottomSheetComponent<bool>(+ context: context,+ builder: (context) => BottomSheetComponent(+ title: context.strings.subscribe,+ message: context.strings.subscribeToEnableSharing,+ closeTooltip: context.strings.close,+ actions: [+ ButtonComponent(+ label: context.strings.upgrade,+ onTap: () => Navigator.of(context).pop(true),+ ),+ ],+ ),+ );+ if (upgrade == true && mounted) {+ await routeToPage(context, getSubscriptionPage());+ }+ } else {+ _logger.severe('Could not share person', error, stack);+ await showErrorDialog(+ context,+ context.strings.personShareFailedTitle,+ context.strings.personShareFailedBody,+ );+ }+ }+ }++ Future<void> _shareFiles() async {+ if (!_canShareFiles) return;+ await share(context, _filesToShare, shareButtonKey: _rawShareButtonKey);+ }+}++class _SharePersonSheetBoundary extends StatefulWidget {+ const _SharePersonSheetBoundary({+ required this.position,+ required this.child,+ });++ final BoundaryPosition position;+ final Widget child;++ @override+ State<_SharePersonSheetBoundary> createState() =>+ _SharePersonSheetBoundaryState();+}++class _SharePersonSheetBoundaryState extends State<_SharePersonSheetBoundary>+ with BoundaryReporter {+ @override+ Widget build(BuildContext context) {+ return boundaryWidget(position: widget.position, child: widget.child);+ }+}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dartindex 13335ac82d..7fdf7daf79 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/component/gallery_file_widget.dart@@ -103,6 +103,8 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {}Widget _buildFileContent(BuildContext context) {+ final disableSelection =+ GalleryContextState.of(context)?.disableSelection ?? false;Color selectionColor = Colors.white;if (_isFileSelected &&widget.file.isUploaded &&@@ -137,11 +139,13 @@ class _GalleryFileWidgetState extends State<GalleryFileWidget> {shouldShowVideoDuration: true,);return GestureDetector(- onTap: () {- widget.limitSelectionToOne- ? _onTapWithSelectionLimit(widget.file)- : _onTapNoSelectionLimit(context, widget.file);- },+ onTap: disableSelection+ ? null+ : () {+ widget.limitSelectionToOne+ ? _onTapWithSelectionLimit(widget.file)+ : _onTapNoSelectionLimit(context, widget.file);+ },onLongPress: () {widget.limitSelectionToOne? _onLongPressWithSelectionLimit(context, widget.file)diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dartindex 24143c9f0d..d21a11a40f 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery.dart@@ -92,6 +92,7 @@ class Gallery extends StatefulWidget {// Enables tap-to-select; it does not indicate whether files are selected.final bool inSelectionMode;+ final bool disableSelection;final bool showSelectAll;final SortAscFn? sortAsyncFn;@@ -122,6 +123,7 @@ class Gallery extends StatefulWidget {this.disableScroll = false,this.limitSelectionToOne = false,this.inSelectionMode = false,+ this.disableSelection = false,this.sortAsyncFn,this.showSelectAll = true,this.reloadDebounceTime = const Duration(milliseconds: 500),@@ -917,7 +919,7 @@ class GalleryState extends State<Gallery> {}return SwipeSelectionWrapper(- isEnabled: shouldEnableSwipeSelection,+ isEnabled: shouldEnableSwipeSelection && !widget.disableSelection,swipeHelper: _swipeHelper,selectedFiles: widget.selectedFiles,swipeActiveNotifier: _swipeActiveNotifier,@@ -925,6 +927,7 @@ class GalleryState extends State<Gallery> {child: GalleryContextState(sortOrderAsc: _sortOrderAsc,inSelectionMode: widget.inSelectionMode,+ disableSelection: widget.disableSelection,type: _groupType,galleryType: widget.galleryType,child: _allGalleryFiles.isEmptydiff --git a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dart b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dartindex 2e7e7d447a..efd72c954b 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/state/gallery_context_state.dart@@ -5,11 +5,13 @@ import "package:photos/ui/viewer/gallery/component/group/type.dart";class GalleryContextState extends InheritedWidget {final bool sortOrderAsc;final bool inSelectionMode;+ final bool disableSelection;final GroupType type;final GalleryType? galleryType;const GalleryContextState({this.inSelectionMode = false,+ this.disableSelection = false,this.type = GroupType.day,this.galleryType,required this.sortOrderAsc,@@ -25,6 +27,7 @@ class GalleryContextState extends InheritedWidget {bool updateShouldNotify(GalleryContextState oldWidget) {return sortOrderAsc != oldWidget.sortOrderAsc ||inSelectionMode != oldWidget.inSelectionMode ||+ disableSelection != oldWidget.disableSelection ||type != oldWidget.type ||galleryType != oldWidget.galleryType;}diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dartindex 9a18808380..83a8ba0547 100644--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart@@ -23,8 +23,10 @@ import "package:photos/services/machine_learning/ml_result.dart";import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';import 'package:photos/ui/components/buttons/button_widget.dart';+import 'package:photos/ui/sharing/share_person_sheet.dart';import "package:photos/ui/viewer/gallery/gallery_app_bar_actions.dart";import "package:photos/ui/viewer/gallery/gallery_app_bar_config.dart";+import 'package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart';import "package:photos/ui/viewer/people/cluster_breakup_page.dart";import "package:photos/ui/viewer/people/cluster_page.dart";import "package:photos/utils/dialog_util.dart";@@ -147,6 +149,32 @@ class _AppBarWidgetState extends State<ClusterAppBar> {return actions;}+ if (!isLocalGalleryMode && hasAccount) {+ final currentUserID = Configuration.instance.getUserID();+ final files = GalleryFilesState.maybeOf(context)?.galleryFilesOrNull+ ?.where(+ (file) =>+ file.uploadedFileID != null && file.ownerID == currentUserID,+ )+ .toList();+ if (files != null && files.isNotEmpty) {+ actions.add(+ IconButtonComponent(+ key: shareButtonKey,+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedShare08),+ variant: IconButtonComponentVariant.primary,+ tooltip: context.strings.share,+ shouldSurfaceExecutionStates: false,+ onTap: () => showSharePersonSheet(+ context,+ files: files,+ shareButtonKey: shareButtonKey,+ ),+ ),+ );+ }+ }+final List<EntePopupMenuOption<ClusterPopupAction>> items = [if (widget.memoryLaneReady && widget.onMemoryLaneTap != null)EntePopupMenuOption(diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dartindex ce2a783bb3..212ebf3d8b 100644--- a/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart@@ -19,9 +19,11 @@ import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';import "package:photos/ui/components/buttons/button_widget.dart";import "package:photos/ui/notification/toast.dart";+import 'package:photos/ui/sharing/share_person_sheet.dart';import "package:photos/ui/viewer/gallery/gallery_app_bar_actions.dart";import "package:photos/ui/viewer/gallery/gallery_app_bar_config.dart";import "package:photos/ui/viewer/gallery/hooks/pick_person_avatar.dart";+import 'package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart';import "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dart";import "package:photos/ui/viewer/hierarchicial_search/app_bar_filter_chips.dart";import "package:photos/ui/viewer/people/person_cluster_suggestion.dart";@@ -280,6 +282,34 @@ class _AppBarWidgetState extends State<PeopleAppBar> {return actions;}+ final currentUserID = Configuration.instance.getUserID();+ final files = GalleryFilesState.maybeOf(context)?.galleryFilesOrNull+ ?.where(+ (file) =>+ file.uploadedFileID != null && file.ownerID == currentUserID,+ )+ .toList();+ if (!isIgnored &&+ person.data.name.trim().isNotEmpty &&+ files != null &&+ files.isNotEmpty) {+ actions.add(+ IconButtonComponent(+ key: shareButtonKey,+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedShare08),+ variant: IconButtonComponentVariant.primary,+ tooltip: context.strings.share,+ shouldSurfaceExecutionStates: false,+ onTap: () => showSharePersonSheet(+ context,+ person: person,+ files: files,+ shareButtonKey: shareButtonKey,+ ),+ ),+ );+ }+final List<EntePopupMenuOption<PeoplePopupAction>> items = [];final bool showTimelineAction =widget.memoryLaneReady && widget.onMemoryLaneTap != null;diff --git a/mobile/packages/ente_components/lib/components/selection_summary_chip_component.dart b/mobile/packages/ente_components/lib/components/selection_summary_chip_component.dartindex b032fdca3a..405c7bf6e0 100644--- a/mobile/packages/ente_components/lib/components/selection_summary_chip_component.dart+++ b/mobile/packages/ente_components/lib/components/selection_summary_chip_component.dart@@ -53,12 +53,13 @@ class SelectionSummaryChipComponent extends StatelessWidget {children: [SizedBox(width: 66,- child: Text(- label,- maxLines: 1,- overflow: TextOverflow.ellipsis,- textAlign: TextAlign.center,- style: TextStyles.mini.copyWith(color: foreground),+ child: FittedBox(+ fit: BoxFit.scaleDown,+ child: Text(+ label,+ maxLines: 1,+ style: TextStyles.mini.copyWith(color: foreground),+ ),),),const SizedBox(width: Spacing.xs),diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex 0ec0b3c1e8..a72d30a396 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -4927,5 +4927,17 @@}}},- "grantAccess": "Grant access"+ "grantAccess": "Grant access",+ "sharePhotos": "Share photos",+ "sharePersonPhotos": "Share {name}βs photos",+ "@sharePersonPhotos": {"placeholders": {"name": {"type": "String"}}},+ "unnamedPersonAlbumName": "Portrait - {date}",+ "@unnamedPersonAlbumName": {"placeholders": {"date": {"type": "String"}}},+ "shareAllPersonPhotos": "Share all photos",+ "shareAllPersonPhotosDescription": "All photos of {name} including future ones",+ "@shareAllPersonPhotosDescription": {"placeholders": {"name": {"type": "String"}}},+ "personShareFailedTitle": "Could not share photos",+ "personShareFailedBody": "The shared album could not be created. Your photos and selection are unchanged. Please try again.",+ "personShareRollbackFailed": "The share did not finish, and the album β{name}β could not be removed. It remains in Albums and may have an active public link. Review or delete it there before trying again. Your original photos are safe.",+ "@personShareRollbackFailed": {"placeholders": {"name": {"type": "String"}}}}