π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Better merge flow
laurenspriem9b327c30f16e
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dartindex 2f06cd26f5..e300cc03a6 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart@@ -6,13 +6,15 @@ import "package:photos/events/people_changed_event.dart";import "package:photos/generated/l10n.dart";import "package:photos/l10n/l10n.dart";import "package:photos/models/ml/face/person.dart";+import "package:photos/models/search/search_constants.dart";import "package:photos/models/selected_people.dart";+import "package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart";import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/search_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/collections/collection_action_sheet.dart";import "package:photos/ui/components/bottom_action_bar/selection_action_button_widget.dart";-import "package:photos/ui/viewer/people/add_files_to_person_page.dart";import "package:photos/ui/viewer/people/merge_clusters_to_person_sheet.dart";import "package:photos/ui/viewer/people/person_cluster_suggestion.dart";import "package:photos/ui/viewer/people/save_or_edit_person.dart";@@ -421,28 +423,43 @@ class _PeopleSelectionActionWidgetState_getNamedSelectedPersonIds(selectedPersonIds, personMap);String? targetPersonId;+ PersonEntity? targetPerson;+ String? seedClusterId;if (namedSelectedPersonIds.length == 1) {targetPersonId = namedSelectedPersonIds.first;+ targetPerson = personMap[targetPersonId];} else {- final initialPersons =- await AddFilesToPersonPage.prefetchNamedPersons(context);+ final initialPersons = await SearchService.instance.getAllFace(+ null,+ minClusterSize: kMinimumClusterSizeAllFaces,+ );if (!mounted) return;- if (initialPersons == null || initialPersons.isEmpty) {- return;- }- targetPersonId = await showMergeClustersToPersonSheet(+ final namedPersons = initialPersons+ .where(+ (result) =>+ (result.params[kPersonParamID] as String?)?.isNotEmpty ?? false,+ )+ .toList();+ final selection = await showMergeClustersToPersonPage(context,- initialPersons: initialPersons,+ initialPersons: namedPersons,+ seedClusterId: selectedClusterIds.first,);if (!mounted) return;+ targetPersonId = selection?.personId;+ seedClusterId = selection?.seedClusterId;+ targetPerson = selection?.person;}if (targetPersonId == null || targetPersonId.isEmpty) return;- final person = personMap[targetPersonId];+ final person = targetPerson ?? personMap[targetPersonId];if (person == null) return;try {for (final clusterID in selectedClusterIds) {+ if (seedClusterId != null && clusterID == seedClusterId) {+ continue;+ }await ClusterFeedbackService.instance.addClusterToExistingPerson(clusterID: clusterID,person: person,diff --git a/mobile/apps/photos/lib/ui/viewer/people/merge_clusters_to_person_sheet.dart b/mobile/apps/photos/lib/ui/viewer/people/merge_clusters_to_person_sheet.dartindex 35e6a796a7..2f2f328a6d 100644--- a/mobile/apps/photos/lib/ui/viewer/people/merge_clusters_to_person_sheet.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/merge_clusters_to_person_sheet.dart@@ -1,11 +1,14 @@import "dart:async";+import "package:dotted_border/dotted_border.dart";+import "package:ente_pure_utils/ente_pure_utils.dart";import "package:flutter/material.dart";+import "package:hugeicons/hugeicons.dart";import "package:logging/logging.dart";-import "package:modal_bottom_sheet/modal_bottom_sheet.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/people_sort_order_change_event.dart";import "package:photos/generated/l10n.dart";+import "package:photos/models/ml/face/person.dart";import "package:photos/models/search/generic_search_result.dart";import "package:photos/models/search/search_constants.dart";import "package:photos/service_locator.dart";@@ -19,48 +22,52 @@ import "package:photos/ui/components/buttons/icon_button_widget.dart";import "package:photos/ui/components/searchable_appbar.dart";import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";import "package:photos/ui/viewer/people/person_face_widget.dart";+import "package:photos/ui/viewer/people/save_or_edit_person.dart";import "package:photos/utils/local_settings.dart";import "package:photos/utils/people_sort_util.dart";-Future<String?> showMergeClustersToPersonSheet(+class MergePersonSelectionResult {+ final String personId;+ final PersonEntity? person;+ final String? seedClusterId;++ const MergePersonSelectionResult({+ required this.personId,+ this.person,+ this.seedClusterId,+ });+}++Future<MergePersonSelectionResult?> showMergeClustersToPersonPage(BuildContext context, {List<GenericSearchResult>? initialPersons,+ String? seedClusterId,}) {- return showBarModalBottomSheet<String>(- context: context,- builder: (context) {- return MergeClustersToPersonSheet(- initialPersons: initialPersons,- );- },- shape: const RoundedRectangleBorder(- side: BorderSide(width: 0),- borderRadius: BorderRadius.vertical(- top: Radius.circular(5),- ),+ return routeToPage(+ context,+ MergeClustersToPersonPage(+ initialPersons: initialPersons,+ seedClusterId: seedClusterId,),- topControl: const SizedBox.shrink(),- backgroundColor: getEnteColorScheme(context).backgroundElevated,- barrierColor: backdropFaintDark,- enableDrag: true,);}-class MergeClustersToPersonSheet extends StatefulWidget {+class MergeClustersToPersonPage extends StatefulWidget {final List<GenericSearchResult>? initialPersons;+ final String? seedClusterId;- const MergeClustersToPersonSheet({+ const MergeClustersToPersonPage({super.key,this.initialPersons,+ this.seedClusterId,});@override- State<MergeClustersToPersonSheet> createState() =>- _MergeClustersToPersonSheetState();+ State<MergeClustersToPersonPage> createState() =>+ _MergeClustersToPersonPageState();}-class _MergeClustersToPersonSheetState- extends State<MergeClustersToPersonSheet> {+class _MergeClustersToPersonPageState extends State<MergeClustersToPersonPage> {static final Logger _logger = Logger("MergeClustersToPersonSheet");late Future<List<GenericSearchResult>> _personsFuture;@@ -73,6 +80,9 @@ class _MergeClustersToPersonSheetStatestatic const double _sortMenuItemHeight = 52;static const double _sortMenuCornerRadius = 12;+ bool get _showNewPersonTile =>+ widget.seedClusterId != null && widget.seedClusterId!.isNotEmpty;+@overridevoid initState() {super.initState();@@ -125,6 +135,29 @@ class _MergeClustersToPersonSheetState}}+ Future<void> _onAddNewPersonSelected() async {+ final seedClusterId = widget.seedClusterId;+ if (seedClusterId == null || seedClusterId.isEmpty) {+ return;+ }+ final result = await routeToPage(+ context,+ SaveOrEditPerson(seedClusterId),+ );+ if (!mounted) {+ return;+ }+ if (result is PersonEntity) {+ Navigator.of(context).pop(+ MergePersonSelectionResult(+ personId: result.remoteID,+ person: result,+ seedClusterId: seedClusterId,+ ),+ );+ }+ }+bool _isSortAscending(PeopleSortKey key) {switch (key) {case PeopleSortKey.name:@@ -188,7 +221,6 @@ class _MergeClustersToPersonSheetStateconst gridPadding = 16.0;return Scaffold(- backgroundColor: colorScheme.backgroundElevated,body: FutureBuilder<List<GenericSearchResult>>(future: _personsFuture,builder: (context, snapshot) {@@ -237,7 +269,7 @@ class _MergeClustersToPersonSheetStatefinal sortedPersons = [...persons];_sortFaces(sortedPersons);final results = _filterPersons(sortedPersons);- if (results.isEmpty) {+ if (results.isEmpty && !_showNewPersonTile) {slivers.add(SliverFillRemaining(child: Center(@@ -272,9 +304,17 @@ class _MergeClustersToPersonSheetStatechildAspectRatio: itemSize / (itemSize + textHeight),),delegate: SliverChildBuilderDelegate(- childCount: results.length,+ childCount: results.length + (_showNewPersonTile ? 1 : 0),(context, index) {- final person = results[index];+ if (_showNewPersonTile && index == 0) {+ return _AddNewPersonGridTile(+ size: itemSize,+ labelHeight: textHeight,+ onTap: _onAddNewPersonSelected,+ );+ }+ final person =+ results[_showNewPersonTile ? index - 1 : index];final personId = person.params[kPersonParamID] as String?;final personKey = personId != null && personId.isNotEmpty? personId@@ -462,7 +502,60 @@ class _MergeClustersToPersonSheetStateif (personId == null || personId.isEmpty) {return;}- Navigator.of(context).pop(personId);+ Navigator.of(context).pop(+ MergePersonSelectionResult(+ personId: personId,+ ),+ );+ }+}++class _AddNewPersonGridTile extends StatelessWidget {+ final double size;+ final double labelHeight;+ final VoidCallback onTap;++ const _AddNewPersonGridTile({+ required this.size,+ required this.labelHeight,+ required this.onTap,+ });++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ const strokeWidth = 1.0;+ final innerSize = size - strokeWidth * 2;+ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.center,+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ DottedBorder(+ color: colorScheme.strokeMuted,+ strokeWidth: strokeWidth,+ dashPattern: const [4, 4],+ padding: EdgeInsets.zero,+ customPath: faceThumbnailSquircleOuterPath,+ child: SizedBox(+ height: innerSize,+ width: innerSize,+ child: Center(+ child: HugeIcon(+ icon: HugeIcons.strokeRoundedUserAdd02,+ color: colorScheme.strokeMuted,+ size: 24,+ ),+ ),+ ),+ ),+ SizedBox(height: labelHeight),+ ],+ ),+ );}}diff --git a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dartindex 52c484a6a3..d2e12f6249 100644--- a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart@@ -254,7 +254,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {height: 110,width: 110,child: FaceThumbnailSquircleClip(- child: widget.file != null+ child: widget.clusterID != null? PersonFaceWidget(clusterID: widget.clusterID,)