Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Better sorting of faces in file info

laurenspriemd0420ce477d3
diff --git a/mobile/lib/ui/viewer/file_details/faces_item_widget.dart b/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
index 783ed2262b..6ffdcbd37c 100644
--- a/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
@@ -85,9 +85,6 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
];
}
- // Sort the faces by score in descending order, so that the highest scoring face is first.
- faces.sort((Face a, Face b) => b.score.compareTo(a.score));
-
// TODO: add deduplication of faces of same person
final faceIdsToClusterIds = await FaceMLDataDB.instance
.getFaceIdsToClusterIds(faces.map((face) => face.faceID));
@@ -96,6 +93,29 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
final clusterIDToPerson =
await FaceMLDataDB.instance.getClusterIDToPersonID();
+ // Sort faces by name and score
+ final faceIdToPersonID = <String, String>{};
+ for (final face in faces) {
+ final clusterID = faceIdsToClusterIds[face.faceID];
+ if (clusterID != null) {
+ final personID = clusterIDToPerson[clusterID];
+ if (personID != null) {
+ faceIdToPersonID[face.faceID] = personID;
+ }
+ }
+ }
+ faces.sort((Face a, Face b) {
+ final aPersonID = faceIdToPersonID[a.faceID];
+ final bPersonID = faceIdToPersonID[b.faceID];
+ if (aPersonID != null && bPersonID == null) {
+ return -1;
+ } else if (aPersonID == null && bPersonID != null) {
+ return 1;
+ } else {
+ return b.score.compareTo(a.score);
+ }
+ });
+
final lastViewedClusterID = ClusterFeedbackService.lastViewedClusterID;
final faceWidgets = <FaceWidget>[];