Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add bulk ignore action for selected faces in photos details

Rahul Raman9825ff0adc52
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart
index 20dfb1aa7f..6e360aefd1 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_face_widget.dart
@@ -39,6 +39,10 @@ class FileInfoFaceWidget extends StatefulWidget {
final double? width;
final bool highlight;
final bool isEditMode;
+ final bool isSelected;
+ final bool isSelectionMode;
+ final VoidCallback? onSelected;
+ final VoidCallback? onLongPressSelected;
final Future<void> Function() reloadAllFaces;
const FileInfoFaceWidget(
@@ -50,6 +54,10 @@ class FileInfoFaceWidget extends StatefulWidget {
this.highlight = false,
this.isEditMode = false,
this.width,
+ this.isSelected = false,
+ this.isSelectionMode = false,
+ this.onSelected,
+ this.onLongPressSelected,
required this.reloadAllFaces,
super.key,
});
@@ -61,6 +69,7 @@ class FileInfoFaceWidget extends StatefulWidget {
class _FileInfoFaceWidgetState extends State<FileInfoFaceWidget> {
bool get hasPerson => widget.person != null;
bool get isEditMode => widget.isEditMode;
+ bool get isSelectionMode => widget.isSelectionMode;
double get thumbnailWidth => widget.width ?? 68;
@override
@@ -71,35 +80,73 @@ class _FileInfoFaceWidgetState extends State<FileInfoFaceWidget> {
clipBehavior: Clip.none,
children: [
GestureDetector(
- onTap: isEditMode
- ? hasPerson
- ? _onMinusIconTap
- : (isLocalGalleryMode ? null : _onPlusIconTap)
- : _routeToPersonOrClusterPage,
+ onTap: isSelectionMode
+ ? widget.onSelected
+ : isEditMode
+ ? hasPerson
+ ? _onMinusIconTap
+ : (isLocalGalleryMode ? null : _onPlusIconTap)
+ : _routeToPersonOrClusterPage,
+ onLongPress: isEditMode && !isSelectionMode
+ ? widget.onLongPressSelected
+ : null,
child: Container(
height: thumbnailWidth,
width: thumbnailWidth,
decoration: ShapeDecoration(
shape: faceThumbnailSquircleBorder(
side: thumbnailWidth,
- borderSide: widget.highlight
+ borderSide: widget.highlight || widget.isSelected
? BorderSide(
- color: getEnteColorScheme(context).primary700,
+ color: widget.isSelected
+ ? getEnteColorScheme(context).primary500
+ : getEnteColorScheme(context).primary700,
width: 1.0,
)
: BorderSide.none,
),
),
child: FaceThumbnailSquircleClip(
- child: FileFaceWidget(
- key: ValueKey(widget.face.faceID),
- widget.file,
- faceCrop: widget.faceCrop,
+ child: Stack(
+ fit: StackFit.expand,
+ children: [
+ FileFaceWidget(
+ key: ValueKey(widget.face.faceID),
+ widget.file,
+ faceCrop: widget.faceCrop,
+ ),
+ if (widget.isSelected)
+ Container(
+ color: Colors.black.withValues(alpha: 0.12),
+ ),
+ ],
),
),
),
),
- if (isEditMode) _buildEditIcon(context),
+ if (widget.isSelected)
+ Positioned(
+ left: -4,
+ top: -4,
+ child: Container(
+ width: 16,
+ height: 16,
+ decoration: BoxDecoration(
+ color: getEnteColorScheme(context).primary500,
+ shape: BoxShape.circle,
+ border: Border.all(
+ color: getEnteColorScheme(context).backgroundBase,
+ width: 1.5,
+ ),
+ ),
+ child: Icon(
+ Icons.check,
+ size: 10,
+ color: getEnteColorScheme(context).backgroundBase,
+ ),
+ ),
+ ),
+ if (isEditMode && !isSelectionMode) _buildEditIcon(context),
],
),
const SizedBox(height: 8),
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart
index b26c475ed5..2e99b6bfc1 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart
@@ -9,6 +9,7 @@ import "package:photos/db/ml/db.dart";
import "package:photos/db/offline_files_db.dart";
import "package:photos/events/people_changed_event.dart";
import "package:photos/generated/l10n.dart";
+import "package:photos/models/base/id.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/ml/face/face.dart";
import "package:photos/models/ml/face/person.dart";
@@ -36,6 +37,7 @@ final Logger _logger = Logger("FacesItemWidget");
class FacesItemWidget extends StatefulWidget {
final EnteFile file;
+
const FacesItemWidget(this.file, {super.key});
@override
@@ -47,6 +49,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
bool _isEditMode = false;
bool _showRemainingFaces = false;
bool _isLoading = true;
+ final Set<String> _selectedFaceIDs = {};
List<_FaceInfo> _defaultFaces = [];
List<_FaceInfo> _remainingFaces = [];
List<PersonEntity> _manualPersons = [];
@@ -76,11 +79,17 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
}
final result = await _fetchFaceData();
if (mounted) {
+ final currentFaceIDs = {
+ ...result.defaultFaces.map((faceInfo) => faceInfo.face.faceID),
+ ...result.remainingFaces.map((faceInfo) => faceInfo.face.faceID),
+ };
setState(() {
_defaultFaces = result.defaultFaces;
_remainingFaces = result.remainingFaces;
_manualPersons = result.manualPersons;
_errorReason = result.errorReason;
+ _selectedFaceIDs
+ .removeWhere((faceID) => !currentFaceIDs.contains(faceID));
if (!isRefresh) {
_isLoading = false;
}
@@ -194,6 +203,10 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
clusterID: faceInfo.clusterID,
width: thumbnailWidth,
isEditMode: _isEditMode,
+ isSelectionMode: _selectedFaceIDs.isNotEmpty,
+ isSelected: _selectedFaceIDs.contains(faceInfo.face.faceID),
+ onSelected: () => _toggleSelectedFace(faceInfo.face.faceID),
+ onLongPressSelected: () => _startSelectionMode(faceInfo.face.faceID),
reloadAllFaces: () => loadFaces(isRefresh: true),
),
);
@@ -364,6 +377,11 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
clusterID: faceInfo.clusterID,
width: thumbnailWidth,
isEditMode: _isEditMode,
+ isSelectionMode: _selectedFaceIDs.isNotEmpty,
+ isSelected: _selectedFaceIDs.contains(faceInfo.face.faceID),
+ onSelected: () => _toggleSelectedFace(faceInfo.face.faceID),
+ onLongPressSelected: () =>
+ _startSelectionMode(faceInfo.face.faceID),
reloadAllFaces: () => loadFaces(isRefresh: true),
),
)
@@ -415,31 +433,47 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
return const SizedBox.shrink();
}
if (_isEditMode) {
+ final hasSelection = _selectedFaceInfos().isNotEmpty;
return Padding(
padding: const EdgeInsets.only(right: 12.0),
child: SizedBox(
height: _kHeaderActionHeight,
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: _toggleEditMode,
- child: Center(
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
- decoration: BoxDecoration(
- border: Border.all(
- color: getEnteColorScheme(context).primary500,
- width: 1,
- ),
- borderRadius: BorderRadius.circular(12),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (hasSelection)
+ IconButtonWidget(
+ icon: Icons.person_off,
+ iconButtonType: IconButtonType.secondary,
+ onTap: _onIgnoreSelectedFaces,
),
- child: Text(
- AppLocalizations.of(context).done,
- style: getEnteTextTheme(context).small.copyWith(
+ if (hasSelection) const SizedBox(width: 8),
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _toggleEditMode,
+ child: Center(
+ child: Container(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8,
+ vertical: 4,
+ ),
+ decoration: BoxDecoration(
+ border: Border.all(
color: getEnteColorScheme(context).primary500,
+ width: 1,
),
+ borderRadius: BorderRadius.circular(12),
+ ),
+ child: Text(
+ AppLocalizations.of(context).done,
+ style: getEnteTextTheme(context).small.copyWith(
+ color: getEnteColorScheme(context).primary500,
+ ),
+ ),
+ ),
),
),
- ),
+ ],
),
),
);
@@ -451,6 +485,108 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
);
}
+ List<_FaceInfo> _allFaceInfos() => [..._defaultFaces, ..._remainingFaces];
+
+ List<_FaceInfo> _selectedFaceInfos() {
+ return _allFaceInfos()
+ .where((f) => _selectedFaceIDs.contains(f.face.faceID))
+ .toList(growable: false);
+ }
+
+ void _startSelectionMode(String faceID) {
+ setState(() {
+ _isEditMode = true;
+ _selectedFaceIDs.add(faceID);
+ });
+ }
+
+ void _toggleSelectedFace(String faceID) {
+ if (!_isEditMode) return;
+ setState(() {
+ if (_selectedFaceIDs.contains(faceID)) {
+ _selectedFaceIDs.remove(faceID);
+ } else {
+ _selectedFaceIDs.add(faceID);
+ }
+ });
+ }
+
+ void _clearSelectionMode() {
+ if (_selectedFaceIDs.isEmpty) {
+ return;
+ }
+ setState(() {
+ _selectedFaceIDs.clear();
+ });
+ }
+
+ Future<void> _onIgnoreSelectedFaces() async {
+ final selectedFaces = _selectedFaceInfos();
+ if (selectedFaces.isEmpty) return;
+
+ final result = await showChoiceActionSheet(
+ context,
+ title: selectedFaces.length == 1
+ ? AppLocalizations.of(context).areYouSureYouWantToIgnoreThisPerson
+ : AppLocalizations.of(context).areYouSureYouWantToIgnoreThesePersons,
+ body: selectedFaces.length == 1
+ ? AppLocalizations.of(context).thePersonWillNotBeDisplayed
+ : AppLocalizations.of(context).thePersonGroupsWillNotBeDisplayed,
+ firstButtonLabel: AppLocalizations.of(context).yesIgnore,
+ firstButtonType: ButtonType.critical,
+ secondButtonLabel: AppLocalizations.of(context).cancel,
+ isCritical: true,
+ );
+ if (result?.action != ButtonAction.first) return;
+
+ final mlDataDB =
+ isLocalGalleryMode ? MLDataDB.localGalleryInstance : MLDataDB.instance;
+ final faceIDToNewClusterID = <String, String>{};
+ final createdPersonIDs = <String>[];
+ try {
+ final clusterIDs = <String>{};
+ for (final f in selectedFaces) {
+ var clusterID =
+ f.clusterID ?? await mlDataDB.getClusterIDForFaceID(f.face.faceID);
+ if (clusterID == null) {
+ clusterID = newClusterID();
+ faceIDToNewClusterID[f.face.faceID] = clusterID;
+ }
+ clusterIDs.add(clusterID);
+ }
+
+ if (faceIDToNewClusterID.isNotEmpty) {
+ await mlDataDB.updateFaceIdToClusterId(faceIDToNewClusterID);
+ }
+
+ for (final clusterID in clusterIDs) {
+ try {
+ final ignoredPerson = await PersonService.instance.addPerson(
+ name: '',
+ clusterID: clusterID,
+ isHidden: true,
+ );
+ createdPersonIDs.add(ignoredPerson.remoteID);
+ // Try automatic merges for the ignored person but avoid firing events per cluster
+ await ClusterFeedbackService.instance.checkAndDoAutomaticMerges(
+ ignoredPerson,
+ personClusterID: clusterID,
+ firePeopleChangedEvent: false,
+ );
+ } catch (e, s) {
+ _logger.warning('Error ignoring cluster $clusterID', e, s);
+ }
+ }
+
+ // Fire a single people changed event and reload faces
+ Bus.instance.fire(PeopleChangedEvent());
+ _clearSelectionMode();
+ await loadFaces(isRefresh: true);
+ } catch (e, s) {
+ _logger.severe('Error while ignoring unlinked faces', e, s);
+ }
+ }
+
Future<_FaceDataResult> _fetchFaceData() async {
final bool isLocalGallery = isLocalGalleryMode;
int? fileKey;
@@ -598,7 +734,12 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
);
}
- void _toggleEditMode() => setState(() => _isEditMode = !_isEditMode);
+ void _toggleEditMode() => setState(() {
+ _isEditMode = !_isEditMode;
+ if (!_isEditMode) {
+ _selectedFaceIDs.clear();
+ }
+ });
void _toggleRemainingFaces() =>
setState(() => _showRemainingFaces = !_showRemainingFaces);