Skip to content

armgit / ente

Public Imported from GitHub
0

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

Integrate new PersonFaceWidget everywhere

laurenspriemcfeca1f56423
diff --git a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart
index f195d43518..06cce08cfa 100644
--- a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart
+++ b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart
@@ -500,6 +500,7 @@ class PersonService {
}
}
+ // TODO: lau-face: rework this method using new scores logic
Future<EnteFile?> getThumbnailFileOfPerson(
PersonEntity person,
) async {
diff --git a/mobile/lib/ui/sharing/user_avator_widget.dart b/mobile/lib/ui/sharing/user_avator_widget.dart
index 11d7566c17..b77ba2d2a0 100644
--- a/mobile/lib/ui/sharing/user_avator_widget.dart
+++ b/mobile/lib/ui/sharing/user_avator_widget.dart
@@ -8,7 +8,6 @@ import "package:photos/core/event_bus.dart";
import "package:photos/events/people_changed_event.dart";
import "package:photos/extensions/user_extension.dart";
import "package:photos/models/api/collection/user.dart";
-import "package:photos/models/file/file.dart";
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/theme/colors.dart";
import 'package:photos/theme/ente_theme.dart';
@@ -39,7 +38,7 @@ class UserAvatarWidget extends StatefulWidget {
class _UserAvatarWidgetState extends State<UserAvatarWidget> {
Future<String?>? _personID;
- EnteFile? _faceThumbnail;
+ bool _canUsePersonFaceWidget = false;
final _logger = Logger("_UserAvatarWidgetState");
late final StreamSubscription<PeopleChangedEvent> _peopleChangedSubscription;
final _debouncer = Debouncer(
@@ -78,10 +77,7 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {
final person = people.firstWhereOrNull(
(person) => person.data.email == widget.user.email,
);
- if (person != null) {
- _faceThumbnail =
- await PersonService.instance.getThumbnailFileOfPerson(person);
- }
+ _canUsePersonFaceWidget = person != null;
return person?.remoteID;
});
} else {
@@ -117,24 +113,23 @@ class _UserAvatarWidgetState extends State<UserAvatarWidget> {
if (snapshot.hasData) {
final personID = snapshot.data as String;
return ClipOval(
- child: _faceThumbnail == null
- ? _FirstLetterCircularAvatar(
- user: widget.user,
- currentUserID: widget.currentUserID,
- thumbnailView: widget.thumbnailView,
- type: widget.type,
- )
- : PersonFaceWidget(
- _faceThumbnail!,
+ child: _canUsePersonFaceWidget
+ ? PersonFaceWidget(
personId: personID,
onErrorCallback: () {
if (mounted) {
setState(() {
_personID = null;
- _faceThumbnail = null;
+ _canUsePersonFaceWidget = false;
});
}
},
+ )
+ : _FirstLetterCircularAvatar(
+ user: widget.user,
+ currentUserID: widget.currentUserID,
+ thumbnailView: widget.thumbnailView,
+ type: widget.type,
),
);
} else if (snapshot.hasError) {
diff --git a/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart b/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
index 652a5b5afa..48621a0f73 100644
--- a/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
+++ b/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
@@ -171,11 +171,8 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
? PeopleBanner(
type: PeopleBannerType.addName,
faceWidget: PersonFaceWidget(
- _firstUnnamedAppliedFaceFilter!.faceFile,
clusterID:
_firstUnnamedAppliedFaceFilter!.clusterId,
- thumbnailFallback: false,
- cannotTrustFile: true,
),
actionIcon: Icons.add_outlined,
text: S.of(context).savePerson,
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/applied_filters_for_appbar.dart b/mobile/lib/ui/viewer/hierarchicial_search/applied_filters_for_appbar.dart
index bc41ed77af..869df13bca 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/applied_filters_for_appbar.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/applied_filters_for_appbar.dart
@@ -66,7 +66,6 @@ class _AppliedFiltersForAppbarState extends State<AppliedFiltersForAppbar> {
? FaceFilterChip(
personId: filter.personId,
clusterId: filter.clusterId,
- faceThumbnailFile: filter.faceFile,
apply: () {
_searchFilterDataProvider.applyFilters([filter]);
},
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
index bc74acc3b1..b7f36eaf2d 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
@@ -1,13 +1,11 @@
import "package:flutter/material.dart";
import "package:photos/core/constants.dart";
-import "package:photos/models/file/file.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/viewer/people/person_face_widget.dart";
class FaceFilterChip extends StatefulWidget {
final String? personId;
final String? clusterId;
- final EnteFile faceThumbnailFile;
final VoidCallback apply;
final VoidCallback remove;
final bool isApplied;
@@ -16,7 +14,6 @@ class FaceFilterChip extends StatefulWidget {
const FaceFilterChip({
required this.personId,
required this.clusterId,
- required this.faceThumbnailFile,
required this.apply,
required this.remove,
required this.isApplied,
@@ -72,12 +69,9 @@ class _FaceFilterChipState extends State<FaceFilterChip> {
width: kFilterChipHeight * scale,
height: kFilterChipHeight * scale,
child: PersonFaceWidget(
- widget.faceThumbnailFile,
personId: widget.personId,
clusterID: widget.clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
),
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
index 5210a71fb9..85c616602e 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
@@ -88,12 +88,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
width: kFilterChipHeight,
height: kFilterChipHeight,
child: PersonFaceWidget(
- faceFilters.first.faceFile,
personId: faceFilters.first.personId,
clusterID: faceFilters.first.clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
);
@@ -105,12 +102,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
width: kFilterChipHeight / 2,
height: kFilterChipHeight,
child: PersonFaceWidget(
- faceFilters.first.faceFile,
personId: faceFilters.first.personId,
clusterID: faceFilters.first.clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
const SizedBox(width: 1),
@@ -118,12 +112,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
width: kFilterChipHeight / 2,
height: kFilterChipHeight,
child: PersonFaceWidget(
- faceFilters.last.faceFile,
personId: faceFilters.last.personId,
clusterID: faceFilters.last.clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
],
@@ -138,12 +129,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
height: kFilterChipHeight,
width: kFilterChipHeight / 2 - 0.5,
child: PersonFaceWidget(
- faceFilters[0].faceFile,
personId: faceFilters[0].personId,
clusterID: faceFilters[0].clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
const SizedBox(width: 1),
@@ -158,12 +146,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
bottomLeft: Radius.circular(1),
),
child: PersonFaceWidget(
- faceFilters[1].faceFile,
personId: faceFilters[1].personId,
clusterID: faceFilters[1].clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
),
@@ -176,12 +161,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
topLeft: Radius.circular(1),
),
child: PersonFaceWidget(
- faceFilters[2].faceFile,
personId: faceFilters[2].personId,
clusterID: faceFilters[2].clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
),
@@ -206,12 +188,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
bottomRight: Radius.circular(1),
),
child: PersonFaceWidget(
- faceFilters[0].faceFile,
personId: faceFilters[0].personId,
clusterID: faceFilters[0].clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
),
@@ -224,12 +203,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
bottomLeft: Radius.circular(1),
),
child: PersonFaceWidget(
- faceFilters[1].faceFile,
personId: faceFilters[1].personId,
clusterID: faceFilters[1].clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
),
@@ -247,12 +223,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
topRight: Radius.circular(1),
),
child: PersonFaceWidget(
- faceFilters[2].faceFile,
personId: faceFilters[2].personId,
clusterID: faceFilters[2].clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
),
@@ -265,12 +238,9 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
topLeft: Radius.circular(1),
),
child: PersonFaceWidget(
- faceFilters[3].faceFile,
personId: faceFilters[3].personId,
clusterID: faceFilters[3].clusterId,
- thumbnailFallback: false,
useFullFile: false,
- cannotTrustFile: true,
),
),
),
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart b/mobile/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart
index bd9c245ed9..8fae99a750 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/filter_options_bottom_sheet.dart
@@ -57,7 +57,6 @@ class _FilterOptionsBottomSheetState extends State<FilterOptionsBottomSheet> {
FaceFilterChip(
personId: filter.personId,
clusterId: filter.clusterId,
- faceThumbnailFile: filter.faceFile,
isInAllFiltersView: true,
apply: () {
widget.searchFilterDataProvider
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters_for_appbar.dart b/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters_for_appbar.dart
index 132f3a2b2b..2c98a5bd38 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters_for_appbar.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/recommended_filters_for_appbar.dart
@@ -121,7 +121,6 @@ class _RecommendedFiltersForAppbarState
? FaceFilterChip(
personId: filter.personId,
clusterId: filter.clusterId,
- faceThumbnailFile: filter.faceFile,
apply: () {
_searchFilterDataProvider.applyFilters([filter]);
},
diff --git a/mobile/lib/ui/viewer/people/cluster_breakup_page.dart b/mobile/lib/ui/viewer/people/cluster_breakup_page.dart
index dadf9bbba5..73df061387 100644
--- a/mobile/lib/ui/viewer/people/cluster_breakup_page.dart
+++ b/mobile/lib/ui/viewer/people/cluster_breakup_page.dart
@@ -59,7 +59,6 @@ class _ClusterBreakupPageState extends State<ClusterBreakupPage> {
Radius.elliptical(16, 12),
),
child: PersonFaceWidget(
- files.first,
clusterID: clusterID,
),
)
diff --git a/mobile/lib/ui/viewer/people/cluster_page.dart b/mobile/lib/ui/viewer/people/cluster_page.dart
index c2510ab22e..2541892d0f 100644
--- a/mobile/lib/ui/viewer/people/cluster_page.dart
+++ b/mobile/lib/ui/viewer/people/cluster_page.dart
@@ -136,7 +136,6 @@ class _ClusterPageState extends State<ClusterPage> {
? PeopleBanner(
type: PeopleBannerType.addName,
faceWidget: PersonFaceWidget(
- files.first,
clusterID: widget.clusterID,
),
actionIcon: Icons.add_outlined,
diff --git a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart
index 419d9df8b8..3d19a86fb0 100644
--- a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart
+++ b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart
@@ -18,8 +18,8 @@ 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/cluster_page.dart";
+import "package:photos/ui/viewer/people/file_face_widget.dart";
import "package:photos/ui/viewer/people/person_clusters_page.dart";
-import "package:photos/ui/viewer/people/person_face_widget.dart";
import "package:photos/utils/face/face_box_crop.dart";
class SuggestionUserFeedback {
@@ -408,11 +408,9 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {
borderRadius: BorderRadius.circular(75),
),
),
- child: PersonFaceWidget(
+ child: FileFaceWidget(
files[start + index],
clusterID: cluserId,
- useFullFile: true,
- thumbnailFallback: false,
faceCrop:
faceThumbnails[files[start + index].uploadedFileID!],
),
diff --git a/mobile/lib/ui/viewer/people/person_clusters_page.dart b/mobile/lib/ui/viewer/people/person_clusters_page.dart
index 8764e15f28..63b0715303 100644
--- a/mobile/lib/ui/viewer/people/person_clusters_page.dart
+++ b/mobile/lib/ui/viewer/people/person_clusters_page.dart
@@ -81,7 +81,6 @@ class _PersonClustersPageState extends State<PersonClustersPage> {
),
child: files.isNotEmpty
? PersonFaceWidget(
- files.first,
clusterID: clusterID,
)
: const NoThumbnailWidget(
@@ -283,7 +282,6 @@ class __ClusterWrapperForGirdState extends State<_ClusterWrapperForGird> {
),
child: widget.files.isNotEmpty
? PersonFaceWidget(
- widget.files.first,
clusterID: widget.clusterID,
)
: const NoThumbnailWidget(
diff --git a/mobile/lib/ui/viewer/people/person_row_item.dart b/mobile/lib/ui/viewer/people/person_row_item.dart
index 265df2ab25..5380863c68 100644
--- a/mobile/lib/ui/viewer/people/person_row_item.dart
+++ b/mobile/lib/ui/viewer/people/person_row_item.dart
@@ -28,7 +28,7 @@ class PersonRowItem extends StatelessWidget {
borderRadius: const BorderRadius.all(
Radius.elliptical(16, 12),
),
- child: PersonFaceWidget(personFile, personId: person.remoteID),
+ child: PersonFaceWidget(personId: person.remoteID),
),
),
title: Text(person.data.name),
@@ -67,7 +67,7 @@ class PersonGridItem extends StatelessWidget {
borderRadius: BorderRadius.circular(80),
),
),
- child: PersonFaceWidget(personFile, personId: person.remoteID),
+ child: PersonFaceWidget(personId: person.remoteID),
),
),
const SizedBox(height: 4),
diff --git a/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart b/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart
index 23206975b8..3f89bbc558 100644
--- a/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart
+++ b/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart
@@ -428,7 +428,6 @@ class _RoundedPersonFaceWidget extends StatelessWidget {
child: personEntitiesWithThumbnailFile.thumbnailFile == null
? const NoThumbnailWidget(addBorder: false)
: PersonFaceWidget(
- personEntitiesWithThumbnailFile.thumbnailFile!,
personId:
personEntitiesWithThumbnailFile.person.remoteID,
useFullFile: true,
diff --git a/mobile/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/lib/ui/viewer/people/save_or_edit_person.dart
index 30f89377f1..8a3f597873 100644
--- a/mobile/lib/ui/viewer/people/save_or_edit_person.dart
+++ b/mobile/lib/ui/viewer/people/save_or_edit_person.dart
@@ -21,7 +21,6 @@ import "package:photos/models/ml/face/person.dart";
import "package:photos/services/account/user_service.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/machine_learning/ml_result.dart";
import "package:photos/services/search_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/date_input.dart";
@@ -155,94 +154,72 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
children: [
const SizedBox(height: 48),
if (person != null)
- FutureBuilder<(String, EnteFile)>(
- future: _getRecentFileWithClusterID(person!),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- final String personClusterID =
- snapshot.data!.$1;
- final personFile = snapshot.data!.$2;
- return Stack(
- children: [
- SizedBox(
- height: 110,
- width: 110,
- child: ClipPath(
- clipper: ShapeBorderClipper(
- shape: ContinuousRectangleBorder(
- borderRadius:
- BorderRadius.circular(80),
- ),
- ),
- child: snapshot.hasData
- ? PersonFaceWidget(
- key: ValueKey(
- person?.data.avatarFaceID ??
- "",
- ),
- personFile,
- clusterID: personClusterID,
- personId: person!.remoteID,
- )
- : const NoThumbnailWidget(
- addBorder: false,
- ),
- ),
+ Stack(
+ children: [
+ SizedBox(
+ height: 110,
+ width: 110,
+ child: ClipPath(
+ clipper: ShapeBorderClipper(
+ shape: ContinuousRectangleBorder(
+ borderRadius: BorderRadius.circular(80),
),
- if (person != null)
- Positioned(
- right: 0,
- bottom: 0,
- child: Container(
- width: 28,
- height: 28,
- decoration: BoxDecoration(
- borderRadius:
- BorderRadius.circular(8.0),
- boxShadow: Theme.of(context)
- .colorScheme
- .enteTheme
- .shadowMenu,
- color: getEnteColorScheme(context)
- .backgroundElevated2,
- ),
- child: IconButton(
- icon: const Icon(Icons.edit),
- iconSize:
- 16, // specify the size of the icon
- onPressed: () async {
- final result =
- await showPersonAvatarPhotoSheet(
- context,
- person!,
- );
- if (result != null) {
- _logger.info(
- 'Person avatar updated',
- );
- setState(() {
- person = result;
- });
- Bus.instance.fire(
- PeopleChangedEvent(
- type: PeopleEventType
- .saveOrEditPerson,
- source:
- "_SaveOrEditPersonState",
- person: result,
- ),
- );
- }
- },
- ),
- ),
- ),
- ],
- );
- } else {
- return const SizedBox.shrink();
- }
- },
+ ),
+ child: PersonFaceWidget(
+ key: ValueKey(
+ person?.data.avatarFaceID ?? "",
+ ),
+ personId: person!.remoteID,
+ ),
+ ),
+ ),
+ if (person != null)
+ Positioned(
+ right: 0,
+ bottom: 0,
+ child: Container(
+ width: 28,
+ height: 28,
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(8.0),
+ boxShadow: Theme.of(context)
+ .colorScheme
+ .enteTheme
+ .shadowMenu,
+ color: getEnteColorScheme(context)
+ .backgroundElevated2,
+ ),
+ child: IconButton(
+ icon: const Icon(Icons.edit),
+ iconSize:
+ 16, // specify the size of the icon
+ onPressed: () async {
+ final result =
+ await showPersonAvatarPhotoSheet(
+ context,
+ person!,
+ );
+ if (result != null) {
+ _logger.info(
+ 'Person avatar updated',
+ );
+ setState(() {
+ person = result;
+ });
+ Bus.instance.fire(
+ PeopleChangedEvent(
+ type: PeopleEventType
+ .saveOrEditPerson,
+ source: "_SaveOrEditPersonState",
+ person: result,
+ ),
+ );
+ }
+ },
+ ),
+ ),
+ ),
+ ],
),
if (person == null)
SizedBox(
@@ -256,7 +233,6 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
),
child: widget.file != null
? PersonFaceWidget(
- widget.file!,
clusterID: widget.clusterID,
)
: const NoThumbnailWidget(
@@ -733,40 +709,6 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
}
return personAndFileID;
}
-
- Future<(String, EnteFile)> _getRecentFileWithClusterID(
- PersonEntity person,
- ) async {
- final clustersToFiles =
- await SearchService.instance.getClusterFilesForPersonID(
- person.remoteID,
- );
- int? avatarFileID;
- if (person.data.hasAvatar()) {
- avatarFileID = tryGetFileIdFromFaceId(person.data.avatarFaceID!);
- }
- EnteFile? resultFile;
- // iterate over all clusters and get the first file
- for (final clusterFiles in clustersToFiles.values) {
- for (final file in clusterFiles) {
- if (avatarFileID != null && file.uploadedFileID! == avatarFileID) {
- resultFile = file;
- break;
- }
- resultFile ??= file;
- if (resultFile.creationTime! < file.creationTime!) {
- resultFile = file;
- }
- }
- }
- if (resultFile == null) {
- debugPrint(
- "Person ${kDebugMode ? person.data.name : person.remoteID} has no files",
- );
- return ("", EnteFile());
- }
- return (person.remoteID, resultFile);
- }
}
class _EmailSection extends StatefulWidget {
diff --git a/mobile/lib/ui/viewer/search/result/search_thumbnail_widget.dart b/mobile/lib/ui/viewer/search/result/search_thumbnail_widget.dart
index 87cd440a11..3d26c1b9ae 100644
--- a/mobile/lib/ui/viewer/search/result/search_thumbnail_widget.dart
+++ b/mobile/lib/ui/viewer/search/result/search_thumbnail_widget.dart
@@ -6,9 +6,7 @@ import "package:photos/models/search/generic_search_result.dart";
import "package:photos/models/search/search_constants.dart";
import "package:photos/models/search/search_result.dart";
import "package:photos/models/search/search_types.dart";
-import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/theme/ente_theme.dart";
-import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
import 'package:photos/ui/viewer/file/no_thumbnail_widget.dart';
import 'package:photos/ui/viewer/file/thumbnail_widget.dart';
@@ -39,7 +37,6 @@ class SearchThumbnailWidget extends StatelessWidget {
? (searchResult != null &&
searchResult!.type() == ResultType.faces)
? PersonFaceWidget(
- file!,
personId: (searchResult as GenericSearchResult)
.params[kPersonParamID],
clusterID: (searchResult as GenericSearchResult)
@@ -73,7 +70,7 @@ class ContactSearchThumbnailWidget extends StatefulWidget {
class _ContactSearchThumbnailWidgetState
extends State<ContactSearchThumbnailWidget> {
- Future<EnteFile?>? _mostRecentFileOfPerson;
+ bool _canUsePersonFaceWidget = true;
late String? _personID;
late String _email;
final _logger = Logger("_ContactSearchThumbnailWidgetState");
@@ -83,16 +80,7 @@ class _ContactSearchThumbnailWidgetState
super.initState();
_personID = widget.searchResult.params[kPersonParamID];
_email = widget.searchResult.params[kContactEmail];
- if (_personID != null) {
- _mostRecentFileOfPerson =
- PersonService.instance.getPerson(_personID!).then((person) {
- if (person == null) {
- return null;
- } else {
- return PersonService.instance.getThumbnailFileOfPerson(person);
- }
- });
- }
+ _canUsePersonFaceWidget = _personID != null;
}
@override
@@ -102,37 +90,17 @@ class _ContactSearchThumbnailWidgetState
width: 60,
child: ClipRRect(
borderRadius: const BorderRadius.horizontal(left: Radius.circular(4)),
- child: _mostRecentFileOfPerson != null
- ? FutureBuilder(
- future: _mostRecentFileOfPerson,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return PersonFaceWidget(
- snapshot.data!,
- personId: _personID,
- onErrorCallback: () {
- if (mounted) {
- setState(() {
- _mostRecentFileOfPerson = null;
- });
- }
- },
- );
- } else if (snapshot.connectionState == ConnectionState.done &&
- snapshot.data == null) {
- return NoFaceForContactWidget(
- user: User(email: _email),
- );
- } else if (snapshot.hasError) {
+ child: _canUsePersonFaceWidget
+ ? PersonFaceWidget(
+ personId: _personID,
+ onErrorCallback: () {
+ if (mounted) {
_logger.severe(
- "Error loading personID",
- snapshot.error,
- );
- return NoFaceForContactWidget(
- user: User(email: _email),
+ "Failed to load face for person with ID: $_personID",
);
- } else {
- return const EnteLoadingWidget();
+ setState(() {
+ _canUsePersonFaceWidget = false;
+ });
}
},
)
diff --git a/mobile/lib/ui/viewer/search_tab/contacts_section.dart b/mobile/lib/ui/viewer/search_tab/contacts_section.dart
index b4750e8960..f162aaa8bc 100644
--- a/mobile/lib/ui/viewer/search_tab/contacts_section.dart
+++ b/mobile/lib/ui/viewer/search_tab/contacts_section.dart
@@ -7,14 +7,11 @@ import "package:photos/core/constants.dart";
import "package:photos/events/event.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/api/collection/user.dart";
-import "package:photos/models/file/file.dart";
import "package:photos/models/search/generic_search_result.dart";
import "package:photos/models/search/recent_searches.dart";
import "package:photos/models/search/search_constants.dart";
import "package:photos/models/search/search_types.dart";
-import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/theme/ente_theme.dart";
-import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
import "package:photos/ui/viewer/people/person_face_widget.dart";
import "package:photos/ui/viewer/search/result/contact_result_page.dart";
@@ -149,7 +146,7 @@ class ContactRecommendation extends StatefulWidget {
}
class _ContactRecommendationState extends State<ContactRecommendation> {
- Future<EnteFile?>? _mostRecentFileOfPerson;
+ bool _canUsePersonFaceWidget = true;
late String? _personID;
final _logger = Logger("_ContactRecommendationState");
@@ -157,16 +154,7 @@ class _ContactRecommendationState extends State<ContactRecommendation> {
void initState() {
super.initState();
_personID = widget.contactSearchResult.params[kPersonParamID];
- if (_personID != null) {
- _mostRecentFileOfPerson =
- PersonService.instance.getPerson(_personID!).then((person) {
- if (person == null) {
- return null;
- } else {
- return PersonService.instance.getThumbnailFileOfPerson(person);
- }
- });
- }
+ _canUsePersonFaceWidget = _personID != null;
}
@override
@@ -203,44 +191,17 @@ class _ContactRecommendationState extends State<ContactRecommendation> {
child: SizedBox(
width: 67.75,
height: 67.75,
- child: _mostRecentFileOfPerson != null
- ? FutureBuilder(
- future: _mostRecentFileOfPerson,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return PersonFaceWidget(
- snapshot.data!,
- personId: _personID,
- onErrorCallback: () {
- if (mounted) {
- setState(() {
- _mostRecentFileOfPerson = null;
- });
- }
- },
- );
- } else if (snapshot.connectionState ==
- ConnectionState.done &&
- snapshot.data == null) {
- return FirstLetterUserAvatar(
- User(
- email: widget.contactSearchResult
- .params[kContactEmail],
- ),
- );
- } else if (snapshot.hasError) {
+ child: _canUsePersonFaceWidget
+ ? PersonFaceWidget(
+ personId: _personID,
+ onErrorCallback: () {
+ if (mounted) {
_logger.severe(
- "Error loading personID",
- snapshot.error,
- );
- return FirstLetterUserAvatar(
- User(
- email: widget.contactSearchResult
- .params[kContactEmail],
- ),
+ "Failed to load face for person with ID: $_personID",
);
- } else {
- return const EnteLoadingWidget();
+ setState(() {
+ _canUsePersonFaceWidget = false;
+ });
}
},
)
diff --git a/mobile/lib/ui/viewer/search_tab/people_section.dart b/mobile/lib/ui/viewer/search_tab/people_section.dart
index ce760eeba6..95ff7c4f8b 100644
--- a/mobile/lib/ui/viewer/search_tab/people_section.dart
+++ b/mobile/lib/ui/viewer/search_tab/people_section.dart
@@ -333,7 +333,6 @@ class FaceSearchResult extends StatelessWidget {
Widget build(BuildContext context) {
final params = (searchResult as GenericSearchResult).params;
return PersonFaceWidget(
- searchResult.previewThumbnail()!,
personId: params[kPersonParamID],
clusterID: params[kClusterParamId],
key: params.containsKey(kPersonWidgetKey)