Skip to content

armgit / ente

Public Imported from GitHub
0

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

add selected files to person

laurenspriemdac7ed88c02c
diff --git a/mobile/apps/photos/lib/models/ml/face/person.dart b/mobile/apps/photos/lib/models/ml/face/person.dart
index 54df3b6acc..aacbdd8252 100644
--- a/mobile/apps/photos/lib/models/ml/face/person.dart
+++ b/mobile/apps/photos/lib/models/ml/face/person.dart
@@ -171,16 +171,15 @@ class PersonData {
: List<String>.from(
json['rejectedFaceIDs'],
);
- final manuallyAssigned = (json['manuallyAssigned'] == null ||
- json['manuallyAssigned'].length == 0 ||
- json['manuallyAssigned'] is! Iterable)
- ? <int>[]
- : List<int>.from(
- (json['manuallyAssigned'] as Iterable<dynamic>).map<int?>((value) {
+ final manualAssignmentData = json['manuallyAssigned'];
+ final manuallyAssigned = manualAssignmentData is Iterable
+ ? List<int>.from(
+ manualAssignmentData.map<int?>((value) {
if (value is num) return value.toInt();
return int.tryParse(value.toString());
}).whereType<int>(),
- );
+ )
+ : <int>[];
return PersonData(
name: json['name'] as String,
assigned: assigned,
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
index fc231dd31f..941ced86df 100644
--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
@@ -19,6 +19,12 @@ import "package:photos/services/entity_service.dart";
import "package:photos/utils/face/face_thumbnail_cache.dart";
import "package:shared_preferences/shared_preferences.dart";
+typedef ManualPersonAssignmentResult = ({
+ PersonEntity person,
+ List<int> addedFileIds,
+ List<int> alreadyAssignedFileIds,
+});
+
class PersonService {
final EntityService entityService;
final MLDataDB faceMLDataDB;
@@ -568,6 +574,55 @@ class PersonService {
return updatedPerson;
}
+ Future<ManualPersonAssignmentResult> addManualFileAssignments({
+ required String personID,
+ required Set<int> fileIDs,
+ }) async {
+ final person = await getPerson(personID);
+ if (person == null) {
+ throw Exception("Person $personID not found");
+ }
+ if (fileIDs.isEmpty) {
+ return (
+ person: person,
+ addedFileIds: const <int>[],
+ alreadyAssignedFileIds: const <int>[],
+ );
+ }
+ final existingClusterFileIds =
+ await faceMLDataDB.getFileIdToClusterIDSet(personID);
+ final manualFileIDs = person.data.manuallyAssigned.toSet();
+ final addedFileIDs = <int>[];
+ final alreadyAssigned = <int>[];
+ for (final id in fileIDs) {
+ if (existingClusterFileIds.containsKey(id) ||
+ manualFileIDs.contains(id)) {
+ alreadyAssigned.add(id);
+ continue;
+ }
+ addedFileIDs.add(id);
+ }
+ if (addedFileIDs.isEmpty) {
+ return (
+ person: person,
+ addedFileIds: const <int>[],
+ alreadyAssignedFileIds: alreadyAssigned,
+ );
+ }
+ final updatedPerson = person.copyWith(
+ data: person.data.copyWith(
+ manuallyAssigned: [...manualFileIDs, ...addedFileIDs],
+ ),
+ );
+ await updatePerson(updatedPerson);
+ await refreshPersonCache();
+ return (
+ person: updatedPerson,
+ addedFileIds: addedFileIDs,
+ alreadyAssignedFileIds: alreadyAssigned,
+ );
+ }
+
Future<void> updatePerson(PersonEntity updatePerson) async {
try {
await _addOrUpdateEntity(
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
index 379e3f33d1..018816a15c 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
@@ -40,6 +40,7 @@ import "package:photos/ui/tools/collage/collage_creator_page.dart";
import "package:photos/ui/viewer/date/edit_date_sheet.dart";
import "package:photos/ui/viewer/file/detail_page.dart";
import "package:photos/ui/viewer/location/update_location_data_widget.dart";
+import "package:photos/ui/viewer/people/add_files_to_person_page.dart";
import 'package:photos/utils/delete_file_util.dart';
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/file_download_util.dart";
@@ -146,6 +147,8 @@ class _FileSelectionActionsWidgetState
ownedAndPendingUploadFilesCount > 0 && split.ownedByOtherUsers.isEmpty;
final bool anyUploadedFiles = split.ownedByCurrentUser.isNotEmpty;
+ final bool hasUploadedFileIDs =
+ widget.selectedFiles.files.any((file) => file.uploadedFileID != null);
final showCollageOption = CollageCreatorPage.isValidCount(
widget.selectedFiles.files.length,
) &&
@@ -350,6 +353,17 @@ class _FileSelectionActionsWidgetState
),
);
}
+ if (flagService.manualTagFileToPerson &&
+ widget.type != GalleryType.sharedPublicCollection) {
+ items.add(
+ SelectionActionButton(
+ icon: Icons.person_add_alt_1_outlined,
+ labelText: "(i) Add to person",
+ onTap: hasUploadedFileIDs ? _onAddFilesToPerson : null,
+ shouldShow: hasUploadedFileIDs,
+ ),
+ );
+ }
items.add(
SelectionActionButton(
svgAssetPath: "assets/icons/guest_view_icon.svg",
@@ -749,6 +763,63 @@ class _FileSelectionActionsWidgetState
}
}
+ Future<void> _onAddFilesToPerson() async {
+ final filesWithIds = widget.selectedFiles.files
+ .where((file) => file.uploadedFileID != null)
+ .toList();
+ if (filesWithIds.isEmpty) {
+ showShortToast(
+ context,
+ "Only uploaded files can be added to a person",
+ );
+ return;
+ }
+ final result = await routeToPage(
+ context,
+ AddFilesToPersonPage(files: filesWithIds),
+ forceCustomPageRoute: true,
+ );
+ if (result is! ManualPersonAssignmentResult) {
+ return;
+ }
+ final addedCount = result.addedFileIds.length;
+ if (addedCount > 0) {
+ final addedFiles = filesWithIds
+ .where(
+ (file) =>
+ file.uploadedFileID != null &&
+ result.addedFileIds.contains(file.uploadedFileID),
+ )
+ .toList();
+ Bus.instance.fire(
+ PeopleChangedEvent(
+ type: PeopleEventType.saveOrEditPerson,
+ source: "manual-add-files-to-person",
+ person: result.person,
+ relevantFiles: addedFiles,
+ ),
+ );
+ final suffix = addedCount == 1 ? "file" : "files";
+ showToast(
+ context,
+ "Added $addedCount $suffix to ${result.person.data.name}",
+ );
+ widget.selectedFiles.clearAll();
+ if (mounted) {
+ setState(() => {});
+ }
+ return;
+ }
+ final alreadyCount = result.alreadyAssignedFileIds.length;
+ if (alreadyCount > 0) {
+ final suffix = alreadyCount == 1 ? "file is" : "files are";
+ showShortToast(
+ context,
+ "$alreadyCount $suffix already linked to ${result.person.data.name}",
+ );
+ }
+ }
+
Future<void> _onGuestViewClick() async {
final List<EnteFile> selectedFiles = widget.selectedFiles.files.toList();
if (await LocalAuthentication().isDeviceSupported()) {
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 d13fadb3ff..29514c0ce7 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
@@ -15,6 +15,8 @@ import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/components/buttons/chip_button_widget.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
import "package:photos/ui/viewer/file_details/file_info_face_widget.dart";
+import "package:photos/ui/viewer/people/people_page.dart";
+import "package:photos/ui/viewer/people/person_face_widget.dart";
import "package:photos/utils/face/face_thumbnail_cache.dart";
final Logger _logger = Logger("FacesItemWidget");
@@ -33,6 +35,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
bool _isLoading = true;
List<_FaceInfo> _defaultFaces = [];
List<_FaceInfo> _remainingFaces = [];
+ List<PersonEntity> _manualPersons = [];
NoFacesReason? _errorReason;
@override
@@ -52,6 +55,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
setState(() {
_defaultFaces = result.defaultFaces;
_remainingFaces = result.remainingFaces;
+ _manualPersons = result.manualPersons;
_errorReason = result.errorReason;
if (!isRefresh) {
_isLoading = false;
@@ -97,11 +101,15 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
);
}
- if (_errorReason != null ||
- (_defaultFaces.isEmpty && _remainingFaces.isEmpty)) {
+ final hasFaceData = _defaultFaces.isNotEmpty || _remainingFaces.isNotEmpty;
+ final hasManual = _manualPersons.isNotEmpty;
+ if (!hasFaceData && !hasManual) {
return _buildNoFacesWidget();
}
+ final screenWidth = MediaQuery.of(context).size.width;
+ final thumbnailWidth = screenWidth * 0.16;
+
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -116,7 +124,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
height: 24,
child: Center(
child: Text(
- AppLocalizations.of(context).faces,
+ AppLocalizations.of(context).people,
style: getEnteTextTheme(context).small,
),
),
@@ -126,19 +134,25 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
],
),
const SizedBox(height: 20),
- if (_defaultFaces.isNotEmpty) _buildFaceGrid(_defaultFaces),
+ if (_defaultFaces.isNotEmpty)
+ _buildFaceGrid(_defaultFaces, thumbnailWidth),
+ if (_manualPersons.isNotEmpty) ...[
+ if (_defaultFaces.isNotEmpty) const SizedBox(height: 16),
+ _buildManualPersonGrid(thumbnailWidth),
+ ],
if (_remainingFaces.isNotEmpty) ...[
const SizedBox(height: 16),
- _buildRemainingFacesSection(),
+ _buildRemainingFacesSection(thumbnailWidth),
],
],
),
);
}
- Widget _buildFaceGrid(List<_FaceInfo> faceInfoList) {
- final screenWidth = MediaQuery.of(context).size.width;
- final thumbnailWidth = screenWidth * 0.16;
+ Widget _buildFaceGrid(
+ List<_FaceInfo> faceInfoList,
+ double thumbnailWidth,
+ ) {
return Padding(
padding: const EdgeInsets.only(right: 12.0),
child: Wrap(
@@ -162,6 +176,25 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
);
}
+ Widget _buildManualPersonGrid(double thumbnailWidth) {
+ return Padding(
+ padding: const EdgeInsets.only(right: 12.0),
+ child: Wrap(
+ runSpacing: 8,
+ spacing: 12,
+ children: _manualPersons
+ .map(
+ (person) => _ManualPersonTag(
+ person: person,
+ thumbnailWidth: thumbnailWidth,
+ onTap: () => _openPersonPage(person),
+ ),
+ )
+ .toList(),
+ ),
+ );
+ }
+
Future<List<_FaceInfo>> _buildFaceInfoList(
List<Face> faces,
Map<String, String?> faceIdsToClusterIds,
@@ -223,6 +256,34 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
return faceInfoList;
}
+ List<PersonEntity> _getManualPersonsForFile(
+ Map<String, PersonEntity> persons,
+ List<_FaceInfo> defaultFaces,
+ List<_FaceInfo> remainingFaces,
+ ) {
+ final uploadedFileID = widget.file.uploadedFileID;
+ if (uploadedFileID == null) return [];
+
+ final existingPersonIDs = <String>{
+ ...defaultFaces.map((face) => face.person?.remoteID).whereType<String>(),
+ ...remainingFaces
+ .map((face) => face.person?.remoteID)
+ .whereType<String>(),
+ };
+
+ final manualPersons = persons.values.where((person) {
+ if (existingPersonIDs.contains(person.remoteID)) {
+ return false;
+ }
+ return person.data.manuallyAssigned.contains(uploadedFileID);
+ }).toList();
+
+ manualPersons.sort(
+ (a, b) => a.data.name.toLowerCase().compareTo(b.data.name.toLowerCase()),
+ );
+ return manualPersons;
+ }
+
Widget _buildNoFacesWidget() {
final reason = _errorReason ?? NoFacesReason.noFacesFound;
return Expanded(
@@ -236,7 +297,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
);
}
- Widget _buildRemainingFacesSection() {
+ Widget _buildRemainingFacesSection(double thumbnailWidth) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -268,7 +329,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
),
if (_showRemainingFaces) ...[
const SizedBox(height: 16),
- _buildFaceGrid(_remainingFaces),
+ _buildFaceGrid(_remainingFaces, thumbnailWidth),
],
],
);
@@ -316,19 +377,27 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
return _FaceDataResult(
defaultFaces: [],
remainingFaces: [],
+ manualPersons: const [],
errorReason: NoFacesReason.fileNotUploaded,
);
}
+ // Fetch persons map early so we can check for manual assignments
+ // even when no faces are detected
+ final persons = await PersonService.instance.getPersonsMap();
+
final mlDataDB = MLDataDB.instance;
final faces =
await mlDataDB.getFacesForGivenFileID(widget.file.uploadedFileID!);
if (faces == null) {
+ final manualPersons = _getManualPersonsForFile(persons, [], []);
return _FaceDataResult(
defaultFaces: [],
remainingFaces: [],
- errorReason: NoFacesReason.fileNotAnalyzed,
+ manualPersons: manualPersons,
+ errorReason:
+ manualPersons.isEmpty ? NoFacesReason.fileNotAnalyzed : null,
);
}
@@ -336,7 +405,6 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
final faceIdsToClusterIds = await mlDataDB.getFaceIdsToClusterIds(
faces.map((face) => face.faceID).toList(),
);
- final persons = await PersonService.instance.getPersonsMap();
final clusterIDToPerson = await mlDataDB.getClusterIDToPersonID();
final faceCrops =
await getCachedFaceCrops(widget.file, faces, useTempCache: true);
@@ -355,49 +423,67 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
return _FaceDataResult(
defaultFaces: [],
remainingFaces: [],
+ manualPersons: const [],
errorReason: NoFacesReason.fileAnalysisFailed,
);
}
}
if (defaultFaces.isEmpty && remainingFaces.isEmpty) {
+ final manualPersons = _getManualPersonsForFile(persons, [], []);
return _FaceDataResult(
defaultFaces: [],
remainingFaces: [],
- errorReason: NoFacesReason.noFacesFound,
+ manualPersons: manualPersons,
+ errorReason: manualPersons.isEmpty ? NoFacesReason.noFacesFound : null,
);
}
if (faceCrops == null) {
+ final manualPersons = _getManualPersonsForFile(persons, [], []);
return _FaceDataResult(
defaultFaces: [],
remainingFaces: [],
- errorReason: NoFacesReason.faceThumbnailGenerationFailed,
+ manualPersons: manualPersons,
+ errorReason: manualPersons.isEmpty
+ ? NoFacesReason.faceThumbnailGenerationFailed
+ : null,
);
}
for (final face in defaultFaces) {
if (faceCrops[face.faceID] == null) {
+ final manualPersons = _getManualPersonsForFile(persons, [], []);
return _FaceDataResult(
defaultFaces: [],
remainingFaces: [],
- errorReason: NoFacesReason.faceThumbnailGenerationFailed,
+ manualPersons: manualPersons,
+ errorReason: manualPersons.isEmpty
+ ? NoFacesReason.faceThumbnailGenerationFailed
+ : null,
);
}
}
+ final defaultFacesInfo = await _buildFaceInfoList(
+ defaultFaces,
+ faceIdsToClusterIds,
+ persons,
+ clusterIDToPerson,
+ faceCrops,
+ );
+ final remainingFacesInfo = await _buildFaceInfoList(
+ remainingFaces,
+ faceIdsToClusterIds,
+ persons,
+ clusterIDToPerson,
+ faceCrops,
+ );
return _FaceDataResult(
- defaultFaces: await _buildFaceInfoList(
- defaultFaces,
- faceIdsToClusterIds,
- persons,
- clusterIDToPerson,
- faceCrops,
- ),
- remainingFaces: await _buildFaceInfoList(
- remainingFaces,
- faceIdsToClusterIds,
+ defaultFaces: defaultFacesInfo,
+ remainingFaces: remainingFacesInfo,
+ manualPersons: _getManualPersonsForFile(
persons,
- clusterIDToPerson,
- faceCrops,
+ defaultFacesInfo,
+ remainingFacesInfo,
),
);
}
@@ -406,16 +492,29 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
void _toggleRemainingFaces() =>
setState(() => _showRemainingFaces = !_showRemainingFaces);
+
+ Future<void> _openPersonPage(PersonEntity person) async {
+ await Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => PeoplePage(
+ person: person,
+ searchResult: null,
+ ),
+ ),
+ );
+ }
}
class _FaceDataResult {
final List<_FaceInfo> defaultFaces;
final List<_FaceInfo> remainingFaces;
+ final List<PersonEntity> manualPersons;
final NoFacesReason? errorReason;
_FaceDataResult({
required this.defaultFaces,
required this.remainingFaces,
+ required this.manualPersons,
this.errorReason,
});
}
@@ -434,6 +533,82 @@ class _FaceInfo {
});
}
+class _ManualPersonTag extends StatelessWidget {
+ final PersonEntity person;
+ final double thumbnailWidth;
+ final VoidCallback onTap;
+
+ const _ManualPersonTag({
+ required this.person,
+ required this.thumbnailWidth,
+ required this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final displayName = person.data.isIgnored
+ ? '(' + AppLocalizations.of(context).ignored + ')'
+ : person.data.name.trim();
+
+ return Semantics(
+ button: true,
+ label: displayName,
+ child: Material(
+ color: Colors.transparent,
+ child: InkWell(
+ borderRadius: BorderRadius.circular(16),
+ onTap: onTap,
+ child: Column(
+ children: [
+ Container(
+ height: thumbnailWidth,
+ width: thumbnailWidth,
+ decoration: const ShapeDecoration(
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.all(
+ Radius.elliptical(16, 12),
+ ),
+ side: BorderSide.none,
+ ),
+ ),
+ child: ClipRRect(
+ child: SizedBox(
+ width: thumbnailWidth,
+ height: thumbnailWidth,
+ child: ClipPath(
+ clipper: ShapeBorderClipper(
+ shape: ContinuousRectangleBorder(
+ borderRadius: BorderRadius.circular(52),
+ ),
+ ),
+ child: PersonFaceWidget(
+ personId: person.remoteID,
+ keepAlive: true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ const SizedBox(height: 8),
+ SizedBox(
+ width: thumbnailWidth,
+ child: Center(
+ child: Text(
+ displayName,
+ style: Theme.of(context).textTheme.bodySmall,
+ overflow: TextOverflow.ellipsis,
+ maxLines: 1,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
+
enum NoFacesReason {
fileNotUploaded,
fileNotAnalyzed,
diff --git a/mobile/apps/photos/lib/ui/viewer/people/add_files_to_person_page.dart b/mobile/apps/photos/lib/ui/viewer/people/add_files_to_person_page.dart
new file mode 100644
index 0000000000..5c877015ed
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/people/add_files_to_person_page.dart
@@ -0,0 +1,245 @@
+import "package:flutter/material.dart";
+import "package:logging/logging.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/search/generic_search_result.dart";
+import "package:photos/models/search/search_constants.dart";
+import "package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.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/common/loading_widget.dart";
+import "package:photos/ui/notification/toast.dart";
+import "package:photos/ui/viewer/people/person_face_widget.dart";
+import "package:photos/utils/dialog_util.dart";
+
+class AddFilesToPersonPage extends StatefulWidget {
+ final List<EnteFile> files;
+
+ const AddFilesToPersonPage({
+ required this.files,
+ super.key,
+ });
+
+ @override
+ State<AddFilesToPersonPage> createState() => _AddFilesToPersonPageState();
+}
+
+class _AddFilesToPersonPageState extends State<AddFilesToPersonPage> {
+ late Future<List<GenericSearchResult>> _personsFuture;
+ final _logger = Logger("AddFilesToPersonPage");
+
+ @override
+ void initState() {
+ super.initState();
+ assert(widget.files.isNotEmpty);
+ _personsFuture = _loadPersons();
+ }
+
+ Future<List<GenericSearchResult>> _loadPersons() async {
+ final results = await SearchService.instance
+ .getAllFace(null, minClusterSize: kMinimumClusterSizeAllFaces);
+ final named = results
+ .where(
+ (result) =>
+ (result.params[kPersonParamID] as String?)?.isNotEmpty ?? false,
+ )
+ .toList();
+ return named;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final smallFontSize = getEnteTextTheme(context).small.fontSize!;
+ final textScaleFactor =
+ MediaQuery.textScalerOf(context).scale(smallFontSize) / smallFontSize;
+ final textHeight = 24 * textScaleFactor;
+ const horizontalEdgePadding = 20.0;
+ const gridPadding = 16.0;
+
+ return Scaffold(
+ appBar: AppBar(
+ title: const Text("(i) Add to person"),
+ centerTitle: false,
+ ),
+ body: FutureBuilder<List<GenericSearchResult>>(
+ future: _personsFuture,
+ builder: (context, snapshot) {
+ if (snapshot.connectionState == ConnectionState.waiting) {
+ return const Center(child: EnteLoadingWidget());
+ } else if (snapshot.hasError) {
+ _logger.severe(
+ "Failed to load persons for manual tagging",
+ snapshot.error,
+ snapshot.stackTrace,
+ );
+ return const Center(child: Icon(Icons.error_outline_rounded));
+ } else if (!snapshot.hasData || snapshot.data!.isEmpty) {
+ return const Center(
+ child: Text("No results found."),
+ );
+ }
+
+ final results = snapshot.data!;
+ final screenWidth = MediaQuery.of(context).size.width;
+ final estimatedCount = (screenWidth / 100).floor();
+ final crossAxisCount = estimatedCount > 0 ? estimatedCount : 1;
+ final itemSize = (screenWidth -
+ ((horizontalEdgePadding * 2) +
+ ((crossAxisCount - 1) * gridPadding))) /
+ crossAxisCount;
+
+ final bottomPadding = MediaQuery.paddingOf(context).bottom;
+ return CustomScrollView(
+ slivers: [
+ SliverPadding(
+ padding: EdgeInsets.fromLTRB(
+ horizontalEdgePadding,
+ 16,
+ horizontalEdgePadding,
+ 16 + bottomPadding,
+ ),
+ sliver: SliverGrid(
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
+ mainAxisSpacing: gridPadding,
+ crossAxisSpacing: gridPadding,
+ crossAxisCount: crossAxisCount,
+ childAspectRatio: itemSize / (itemSize + textHeight),
+ ),
+ delegate: SliverChildBuilderDelegate(
+ childCount: results.length,
+ (context, index) {
+ final person = results[index];
+ return _ManualPersonGridTile(
+ result: person,
+ size: itemSize,
+ labelHeight: textHeight,
+ onTap: () => _onPersonSelected(person),
+ );
+ },
+ ),
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ );
+ }
+
+ Future<void> _onPersonSelected(GenericSearchResult result) async {
+ final personId = result.params[kPersonParamID] as String?;
+ if (personId == null || personId.isEmpty) {
+ return;
+ }
+ final uploadIds = widget.files
+ .map((file) => file.uploadedFileID)
+ .whereType<int>()
+ .toSet();
+ if (uploadIds.isEmpty) {
+ showShortToast(
+ context,
+ "Only uploaded files can be added to a person",
+ );
+ return;
+ }
+
+ final dialog = createProgressDialog(
+ context,
+ "Saving...",
+ );
+ await dialog.show();
+ try {
+ final result = await PersonService.instance.addManualFileAssignments(
+ personID: personId,
+ fileIDs: uploadIds,
+ );
+ await dialog.hide();
+ if (!mounted) {
+ return;
+ }
+ Navigator.of(context).pop(result);
+ } catch (e, s) {
+ await dialog.hide();
+ _logger.severe("Failed to add files to person", e, s);
+ if (!mounted) {
+ return;
+ }
+ await showGenericErrorDialog(context: context, error: e);
+ }
+ }
+}
+
+class _ManualPersonGridTile extends StatelessWidget {
+ final GenericSearchResult result;
+ final double size;
+ final double labelHeight;
+ final VoidCallback onTap;
+
+ const _ManualPersonGridTile({
+ required this.result,
+ required this.size,
+ required this.labelHeight,
+ required this.onTap,
+ });
+
+ double get _borderRadius => 82 * (size / 102);
+
+ @override
+ Widget build(BuildContext context) {
+ final textStyle = getEnteTextTheme(context).small;
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ ClipPath(
+ clipper: ShapeBorderClipper(
+ shape: ContinuousRectangleBorder(
+ borderRadius: BorderRadius.circular(_borderRadius),
+ ),
+ ),
+ child: Container(
+ width: size,
+ height: size,
+ decoration: BoxDecoration(
+ color: getEnteColorScheme(context).strokeFaint,
+ ),
+ child: _FaceSearchResult(result: result),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(top: 6),
+ child: Text(
+ result.name(),
+ maxLines: 1,
+ textAlign: TextAlign.center,
+ overflow: TextOverflow.ellipsis,
+ style: textStyle,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+class _FaceSearchResult extends StatelessWidget {
+ final GenericSearchResult result;
+
+ const _FaceSearchResult({required this.result});
+
+ @override
+ Widget build(BuildContext context) {
+ final params = result.params;
+ return PersonFaceWidget(
+ personId: params[kPersonParamID],
+ clusterID: params[kClusterParamId],
+ key: params.containsKey(kPersonWidgetKey)
+ ? ValueKey(params[kPersonWidgetKey])
+ : ValueKey(params[kPersonParamID] ?? params[kClusterParamId]),
+ );
+ }
+}
diff --git a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
index d2650f2d51..ce5e1c40ab 100644
--- a/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
+++ b/mobile/apps/photos/plugins/ente_feature_flag/lib/src/service.dart
@@ -95,6 +95,8 @@ class FlagService {
bool get streamEnabledByDefault => internalUser;
+ bool get manualTagFileToPerson => internalUser;
+
Future<void> tryRefreshFlags() async {
try {
await _fetch();