Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Reduce flicker on bulk ignore persons events

laurenspriema6d0401db36a
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
index 716c74b47f..de188f8323 100644
--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
@@ -477,6 +477,7 @@ class ClusterFeedbackService<T> {
Future<bool> checkAndDoAutomaticMerges(
PersonEntity p, {
required String personClusterID,
+ bool firePeopleChangedEvent = true,
}) async {
final faceIDs = await mlDataDB.getFaceIDsForCluster(personClusterID);
@@ -516,7 +517,9 @@ class ClusterFeedbackService<T> {
);
}
- Bus.instance.fire(PeopleChangedEvent());
+ if (firePeopleChangedEvent) {
+ Bus.instance.fire(PeopleChangedEvent());
+ }
return true;
}
@@ -550,14 +553,20 @@ class ClusterFeedbackService<T> {
);
}
- Future<void> ignoreCluster(String clusterID) async {
+ Future<void> ignoreCluster(
+ String clusterID, {
+ bool firePeopleChangedEvent = true,
+ }) async {
final ignoredPerson = await PersonService.instance
.addPerson(name: '', clusterID: clusterID, isHidden: true);
- final mergedAndFired = await checkAndDoAutomaticMerges(
+ final merged = await checkAndDoAutomaticMerges(
ignoredPerson,
personClusterID: clusterID,
+ firePeopleChangedEvent: firePeopleChangedEvent,
);
- if (!mergedAndFired) Bus.instance.fire(PeopleChangedEvent());
+ if (!merged && firePeopleChangedEvent) {
+ Bus.instance.fire(PeopleChangedEvent());
+ }
}
Future<List<(String, int)>> checkForMixedClusters() async {
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.dart
index a0990b3e7e..5415ea33b7 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
@@ -15,6 +15,7 @@ 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/components/buttons/button_widget.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,7 +422,7 @@ class _PeopleSelectionActionWidgetState
if (selectedPersonIds.isEmpty && selectedClusterIds.isEmpty) return;
final multiple = (selectedPersonIds.length + selectedClusterIds.length) > 1;
- await showChoiceDialog(
+ final result = await showChoiceDialog(
context,
title: multiple
? AppLocalizations.of(context).areYouSureYouWantToIgnoreThesePersons
@@ -430,26 +431,99 @@ class _PeopleSelectionActionWidgetState
? AppLocalizations.of(context).thePersonGroupsWillNotBeDisplayed
: AppLocalizations.of(context).thePersonWillNotBeDisplayed,
firstButtonLabel: AppLocalizations.of(context).yesIgnore,
- firstButtonOnTap: () async {
- try {
- for (final clusterID in selectedClusterIds) {
- await ClusterFeedbackService.instance.ignoreCluster(clusterID);
- }
- for (final personID in selectedPersonIds) {
- final person = personMap[personID];
- if (person == null || person.data.isIgnored) continue;
- final ignoredPerson = person.copyWith(
- data: person.data.copyWith(isHidden: true),
- );
- await PersonService.instance.updatePerson(ignoredPerson);
- }
- Bus.instance.fire(PeopleChangedEvent());
- widget.selectedPeople.clearAll();
- } catch (e, s) {
- _logger.severe('Ignoring a cluster failed', e, s);
- }
- },
);
+ if (!mounted || result?.action != ButtonAction.first) {
+ return;
+ }
+
+ try {
+ await _ignoreSelectedItems(
+ personMap: personMap,
+ selectedPersonIds: selectedPersonIds,
+ selectedClusterIds: selectedClusterIds,
+ );
+ } catch (e, s) {
+ _logger.severe('Ignoring a cluster failed', e, s);
+ }
+ }
+
+ Future<void> _ignoreSelectedItems({
+ required Map<String, PersonEntity> personMap,
+ required List<String> selectedPersonIds,
+ required List<String> selectedClusterIds,
+ }) async {
+ final l10n = AppLocalizations.of(context);
+ final personIdsToIgnore = selectedPersonIds.where((personID) {
+ final person = personMap[personID];
+ return person != null && !person.data.isIgnored;
+ }).toList();
+ final total = selectedClusterIds.length + personIdsToIgnore.length;
+ if (total == 0) {
+ widget.selectedPeople.clearAll();
+ return;
+ }
+
+ final shouldShowProgressDialog = total > 1;
+ final dialog = shouldShowProgressDialog
+ ? createProgressDialog(
+ context,
+ _bulkIgnoreProgressMessage(l10n, 0, total),
+ )
+ : null;
+ if (dialog != null) {
+ await dialog.show();
+ }
+ var completed = 0;
+ var hasUpdates = false;
+ var completedAll = false;
+
+ try {
+ for (final clusterID in selectedClusterIds) {
+ await ClusterFeedbackService.instance.ignoreCluster(
+ clusterID,
+ firePeopleChangedEvent: false,
+ );
+ completed++;
+ hasUpdates = true;
+ dialog?.update(
+ message: _bulkIgnoreProgressMessage(l10n, completed, total),
+ );
+ }
+
+ for (final personID in personIdsToIgnore) {
+ final person = personMap[personID];
+ if (person == null) continue;
+ final ignoredPerson = person.copyWith(
+ data: person.data.copyWith(isHidden: true),
+ );
+ await PersonService.instance.updatePerson(ignoredPerson);
+ completed++;
+ hasUpdates = true;
+ dialog?.update(
+ message: _bulkIgnoreProgressMessage(l10n, completed, total),
+ );
+ }
+
+ completedAll = true;
+ } finally {
+ if (completedAll) {
+ widget.selectedPeople.clearAll();
+ }
+ if (hasUpdates) {
+ Bus.instance.fire(PeopleChangedEvent());
+ }
+ if (dialog != null) {
+ await dialog.hide();
+ }
+ }
+ }
+
+ String _bulkIgnoreProgressMessage(
+ AppLocalizations l10n,
+ int completed,
+ int total,
+ ) {
+ return "${l10n.pleaseWait} ($completed/$total)";
}
Future<void> _onShowPerson() async {
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
index b7535a9d8f..8aa3da6678 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
@@ -343,6 +343,8 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
bool userDismissedPersonGallerySuggestion = false;
String _searchQuery = "";
int _suggestionReloadToken = 0;
+ final Debouncer _peopleReloadDebouncer =
+ Debouncer(const Duration(milliseconds: 400));
late PeopleSortKey _sortKey;
bool _nameSortAscending = true;
bool _updatedSortAscending = false;
@@ -428,11 +430,16 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
_suggestionReloadToken++;
});
} else {
- setState(() {
- _suggestionReloadToken++;
- _isInitialLoad = false;
- _isLoaded = false;
- sectionData = getResults();
+ _peopleReloadDebouncer.run(() async {
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ _suggestionReloadToken++;
+ _isInitialLoad = false;
+ _isLoaded = false;
+ sectionData = getResults();
+ });
});
}
}),
@@ -585,6 +592,7 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
@override
void dispose() {
+ _peopleReloadDebouncer.cancelDebounceTimer();
for (var subscriptions in streamSubscriptions) {
subscriptions.cancel();
}