From f4024d2007e084cfb79fba74c86f2586ef9da908 Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Tue, 14 May 2024 11:51:50 +0530 Subject: [PATCH] [mob][photos] Suggestion option to assign to different person --- .../people/person_cluster_suggestion.dart | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart index e8e0e90211..9615ce6da7 100644 --- a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart +++ b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart @@ -14,6 +14,7 @@ import "package:photos/services/machine_learning/face_ml/person/person_service.d import "package:photos/theme/ente_theme.dart"; import "package:photos/ui/components/buttons/button_widget.dart"; import "package:photos/ui/components/models/button_type.dart"; +import "package:photos/ui/viewer/people/add_person_action_sheet.dart"; import "package:photos/ui/viewer/people/cluster_page.dart"; import "package:photos/ui/viewer/people/person_clusters_page.dart"; import "package:photos/ui/viewer/search/result/person_face_widget.dart"; @@ -193,22 +194,29 @@ class _PersonClustersState extends State { setState(() {}); } } else { - canGiveFeedback = false; - await FaceMLDataDB.instance.captureNotPersonFeedback( - personID: widget.person.remoteID, - clusterID: clusterID, - ); - // Recalculate the suggestions when a suggestion is rejected - setState(() { - currentSuggestionIndex = 0; - futureBuilderKeySuggestions = - UniqueKey(); // Reset to trigger FutureBuilder - futureBuilderKeyFaceThumbnails = UniqueKey(); - _fetchClusterSuggestions(); - }); + await _rejectSuggestion(clusterID, numberOfSuggestions); } } + Future _rejectSuggestion( + int clusterID, + int numberOfSuggestions, + ) async { + canGiveFeedback = false; + await FaceMLDataDB.instance.captureNotPersonFeedback( + personID: widget.person.remoteID, + clusterID: clusterID, + ); + // Recalculate the suggestions when a suggestion is rejected + setState(() { + currentSuggestionIndex = 0; + futureBuilderKeySuggestions = + UniqueKey(); // Reset to trigger FutureBuilder + futureBuilderKeyFaceThumbnails = UniqueKey(); + _fetchClusterSuggestions(); + }); + } + // Method to fetch cluster suggestions void _fetchClusterSuggestions() { futureClusterSuggestions = @@ -245,7 +253,7 @@ class _PersonClustersState extends State { ), const SizedBox( height: 24.0, - ), // Add some spacing between the thumbnail and the text + ), Padding( padding: const EdgeInsets.symmetric(horizontal: 24.0), child: Row( @@ -282,6 +290,25 @@ class _PersonClustersState extends State { ], ), ), + const SizedBox( + height: 24.0, + ), + ButtonWidget( + shouldSurfaceExecutionStates: false, + buttonType: ButtonType.neutral, + labelText: 'Assign different person', + buttonSize: ButtonSize.small, + onTap: () async { + final result = await showAssignPersonAction( + context, + clusterID: clusterID, + ); + if (result == null || result is! PersonEntity) { + return; + } + await _rejectSuggestion(clusterID, numberOfSuggestions); + }, + ), ], ); // Precompute face thumbnails for next suggestions, in case there are