π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use new face widget in file info
laurenspriem7519ed5e1598
diff --git a/mobile/lib/ui/viewer/file_details/file_info_face_widget.dart b/mobile/lib/ui/viewer/file_details/file_info_face_widget.dartindex eee2b42ccb..8fdb2c3510 100644--- a/mobile/lib/ui/viewer/file_details/file_info_face_widget.dart+++ b/mobile/lib/ui/viewer/file_details/file_info_face_widget.dart@@ -3,7 +3,6 @@ import "dart:typed_data";import "package:flutter/foundation.dart" show kDebugMode;import "package:flutter/material.dart";-import "package:logging/logging.dart";import "package:photos/db/ml/db.dart";import "package:photos/generated/l10n.dart";import "package:photos/models/base/id.dart";@@ -16,15 +15,14 @@ import "package:photos/services/machine_learning/ml_service.dart";import "package:photos/services/search_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/notification/toast.dart";-import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";import "package:photos/ui/viewer/people/cluster_page.dart";+import "package:photos/ui/viewer/people/face_widget.dart";import "package:photos/ui/viewer/people/people_page.dart";-import "package:photos/utils/face/face_box_crop.dart";class FileInfoFaceWidget extends StatefulWidget {final EnteFile file;final Face face;- final Future<Map<String, Uint8List>?>? faceCrops;+ final Uint8List faceCrop;final PersonEntity? person;final String? clusterID;final bool highlight;@@ -32,7 +30,7 @@ class FileInfoFaceWidget extends StatefulWidget {const FileInfoFaceWidget(this.file,this.face, {- this.faceCrops,+ required this.faceCrop,this.person,this.clusterID,this.highlight = false,@@ -44,90 +42,49 @@ class FileInfoFaceWidget extends StatefulWidget {}class _FileInfoFaceWidgetState extends State<FileInfoFaceWidget> {- bool isJustRemoved = false;-- final _logger = Logger("FaceWidget");-@overrideWidget build(BuildContext context) {- final bool givenFaces = widget.faceCrops != null;- return FutureBuilder<Map<String, Uint8List>?>(- future: givenFaces- ? widget.faceCrops- : getCachedFaceCrops(widget.file, [widget.face]),- builder: (context, snapshot) {- if (snapshot.hasData) {- final ImageProvider imageProvider =- MemoryImage(snapshot.data![widget.face.faceID]!);-- return GestureDetector(- onTap: _onTap,- child: Column(- children: [- Stack(- children: [- Container(- height: 60,- width: 60,- decoration: ShapeDecoration(- shape: RoundedRectangleBorder(- borderRadius: const BorderRadius.all(- Radius.elliptical(16, 12),- ),- side: widget.highlight- ? BorderSide(- color: getEnteColorScheme(context).primary700,- width: 1.0,- )- : BorderSide.none,- ),- ),- child: ClipRRect(- borderRadius:- const BorderRadius.all(Radius.elliptical(16, 12)),- child: SizedBox(- width: 60,- height: 60,- child: Image(- image: imageProvider,- fit: BoxFit.cover,- ),- ),- ),+ return GestureDetector(+ onTap: _routeToPersonOrClusterPage,+ child: Column(+ children: [+ Stack(+ children: [+ Container(+ height: 60,+ width: 60,+ decoration: ShapeDecoration(+ shape: RoundedRectangleBorder(+ borderRadius: const BorderRadius.all(+ Radius.elliptical(16, 12),),- ],+ side: widget.highlight+ ? BorderSide(+ color: getEnteColorScheme(context).primary700,+ width: 1.0,+ )+ : BorderSide.none,+ ),+ ),+ child: ClipRRect(+ borderRadius:+ const BorderRadius.all(Radius.elliptical(16, 12)),+ child: SizedBox(+ width: 60,+ height: 60,+ child: FaceWidget(+ widget.file,+ faceCrop: widget.faceCrop,+ ),+ ),),- const SizedBox(height: 8),- ..._buildFaceInfo(),- ],- ),- );- } else {- if (snapshot.connectionState == ConnectionState.waiting) {- return const ClipRRect(- borderRadius: BorderRadius.all(Radius.elliptical(16, 12)),- child: SizedBox(- width: 60,- height: 60,- child: CircularProgressIndicator(),),- );- }- if (snapshot.hasError) {- _logger.severe(- 'Error getting face: ${snapshot.error} ${snapshot.stackTrace}',- );- }- return const ClipRRect(- borderRadius: BorderRadius.all(Radius.elliptical(16, 12)),- child: SizedBox(- width: 60,- height: 60,- child: NoThumbnailWidget(),- ),- );- }- },+ ],+ ),+ const SizedBox(height: 8),+ ..._buildFaceInfo(),+ ],+ ),);}@@ -187,7 +144,7 @@ class _FileInfoFaceWidgetState extends State<FileInfoFaceWidget> {return faceInfo;}- Future<void> _onTap() async {+ Future<void> _routeToPersonOrClusterPage() async {final mlDataDB = MLDataDB.instance;if (widget.person != null) {await Navigator.of(context).push(diff --git a/mobile/lib/ui/viewer/file_details/file_info_faces_item_widget.dart b/mobile/lib/ui/viewer/file_details/file_info_faces_item_widget.dartindex bdbcc49656..778d323f8b 100644--- a/mobile/lib/ui/viewer/file_details/file_info_faces_item_widget.dart+++ b/mobile/lib/ui/viewer/file_details/file_info_faces_item_widget.dart@@ -122,13 +122,21 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {final faceWidgets = <FileInfoFaceWidget>[];- // await generation of the face crops here, so that the file info shows one central loading spinner- final _ = await getCachedFaceCrops(file, faces);-- final faceCrops = getCachedFaceCrops(file, faces);+ final faceCrops = await getCachedFaceCrops(file, faces);final List<String> faceIDs = [];final List<double> faceScores = [];for (final Face face in faces) {+ final faceCrop = faceCrops != null ? faceCrops[face.faceID] : null;+ if (faceCrop == null) {+ _logger.severe(+ 'Face crop for face ${face.faceID} in file ${file.uploadedFileID} is null, skipping face widget.',+ );+ return [+ const NoFaceChipButtonWidget(+ NoFacesReason.faceThumbnailGenerationFailed,+ ),+ ];+ }final String? clusterID = faceIdsToClusterIds[face.faceID];final PersonEntity? person = clusterIDToPerson[clusterID] != null? persons[clusterIDToPerson[clusterID]!]@@ -141,7 +149,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {FileInfoFaceWidget(file,face,- faceCrops: faceCrops,+ faceCrop: faceCrop,clusterID: clusterID,person: person,highlight: highlight,@@ -165,6 +173,7 @@ enum NoFacesReason {fileNotUploaded,fileNotAnalyzed,noFacesFound,+ faceThumbnailGenerationFailed,}String getNoFaceReasonText(@@ -178,6 +187,8 @@ String getNoFaceReasonText(return S.of(context).imageNotAnalyzed;case NoFacesReason.noFacesFound:return S.of(context).noFacesFound;+ case NoFacesReason.faceThumbnailGenerationFailed:+ return "Unable to generate face thumbnails";}}diff --git a/mobile/lib/ui/viewer/people/face_widget.dart b/mobile/lib/ui/viewer/people/face_widget.dartnew file mode 100644index 0000000000..8394593ab2--- /dev/null+++ b/mobile/lib/ui/viewer/people/face_widget.dart@@ -0,0 +1,95 @@+import "dart:typed_data";++import 'package:flutter/widgets.dart';+import "package:logging/logging.dart";+import 'package:photos/models/file/file.dart';+import "package:photos/models/ml/face/face.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/common/loading_widget.dart";+import "package:photos/ui/viewer/file/thumbnail_widget.dart";+import "package:photos/utils/face/face_box_crop.dart";++final _logger = Logger("FaceWidget");++class FaceWidget extends StatefulWidget {+ final EnteFile file;+ final Face? face;+ final Uint8List? faceCrop;+ final String? clusterID;+ final bool useFullFile;+ final bool thumbnailFallback;++ const FaceWidget(+ this.file, {+ this.face,+ this.faceCrop,+ this.clusterID,+ this.useFullFile = true,+ this.thumbnailFallback = false,+ super.key,+ });++ @override+ State<FaceWidget> createState() => _FaceWidgetState();+}++class _FaceWidgetState extends State<FaceWidget> {+ Future<Uint8List?>? faceCropFuture;++ @override+ void initState() {+ super.initState();+ faceCropFuture = _getFaceCrop();+ }++ @override+ void dispose() {+ super.dispose();+ if (widget.faceCrop == null) {+ checkStopTryingToGenerateFaceThumbnails(+ widget.file,+ useFullFile: widget.useFullFile,+ );+ }+ }++ @override+ Widget build(BuildContext context) {+ return FutureBuilder<Uint8List?>(+ future: faceCropFuture,+ builder: (context, snapshot) {+ if (snapshot.hasData) {+ final ImageProvider imageProvider = MemoryImage(snapshot.data!);+ return Stack(+ fit: StackFit.expand,+ children: [+ Image(+ image: imageProvider,+ fit: BoxFit.cover,+ ),+ ],+ );+ } else {+ if (snapshot.hasError) {+ _logger.severe(+ "Error getting cover face",+ snapshot.error,+ snapshot.stackTrace,+ );+ }+ return widget.thumbnailFallback+ ? ThumbnailWidget(widget.file)+ : EnteLoadingWidget(+ color: getEnteColorScheme(context).fillMuted,+ );+ }+ },+ );+ }++ Future<Uint8List?> _getFaceCrop() async {+ if (widget.faceCrop != null) {+ return widget.faceCrop;+ }+ }+}