π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Use contact's face if linked to a person for user avatar
ashilkn61e1153a36c4
diff --git a/mobile/lib/ui/sharing/album_share_info_widget.dart b/mobile/lib/ui/sharing/album_share_info_widget.dartindex 98a885cf49..7c1017ea2d 100644--- a/mobile/lib/ui/sharing/album_share_info_widget.dart+++ b/mobile/lib/ui/sharing/album_share_info_widget.dart@@ -66,7 +66,10 @@ class AlbumSharesIcons extends StatelessWidget {return Padding(padding: padding,- child: Stack(children: widgets),+ child: Stack(+ clipBehavior: Clip.none,+ children: widgets,+ ),);}}diff --git a/mobile/lib/ui/sharing/more_count_badge.dart b/mobile/lib/ui/sharing/more_count_badge.dartindex 50815987f8..c828642bbc 100644--- a/mobile/lib/ui/sharing/more_count_badge.dart+++ b/mobile/lib/ui/sharing/more_count_badge.dart@@ -10,7 +10,8 @@ class MoreCountWidget extends StatelessWidget {final bool thumbnailView;final int count;- const MoreCountWidget(this.count, {+ const MoreCountWidget(+ this.count, {super.key,this.type = MoreCountType.mini,this.thumbnailView = false,@@ -30,34 +31,39 @@ class MoreCountWidget extends StatelessWidget {? avatarStyle.item2.copyWith(color: textFaintLight): avatarStyle.item2.copyWith(color: Colors.white);return Container(- height: size,- width: size,- padding: thumbnailView- ? const EdgeInsets.only(bottom: 1)- : const EdgeInsets.all(2),- decoration: thumbnailView- ? null- : BoxDecoration(+ padding: const EdgeInsets.all(0.5),+ decoration: BoxDecoration(shape: BoxShape.circle,- color: decorationColor,border: Border.all(- color: strokeBaseDark,+ color: thumbnailView+ ? strokeMutedDark+ : getEnteColorScheme(context).strokeMuted,width: 1.0,+ strokeAlign: BorderSide.strokeAlignOutside,),),- child: CircleAvatar(- backgroundColor: decorationColor,- child: Text(- displayChar.toUpperCase(),- // fixed color- style: textStyle,+ child: SizedBox(+ height: size,+ width: size,+ child: CircleAvatar(+ backgroundColor: decorationColor,+ child: Transform.scale(+ scale: 0.85,+ child: Text(+ displayChar.toUpperCase(),+ // fixed color+ style: textStyle,+ ),+ ),),),);}- Tuple2<double, TextStyle> getAvatarStyle(BuildContext context,- MoreCountType type,) {+ Tuple2<double, TextStyle> getAvatarStyle(+ BuildContext context,+ MoreCountType type,+ ) {final enteTextTheme = getEnteTextTheme(context);switch (type) {case MoreCountType.small:diff --git a/mobile/lib/ui/sharing/user_avator_widget.dart b/mobile/lib/ui/sharing/user_avator_widget.dartindex 2df85755b5..c9abe72433 100644--- a/mobile/lib/ui/sharing/user_avator_widget.dart+++ b/mobile/lib/ui/sharing/user_avator_widget.dart@@ -1,13 +1,18 @@+import "package:collection/collection.dart";import 'package:flutter/material.dart';+import "package:logging/logging.dart";import "package:photos/extensions/user_extension.dart";import "package:photos/models/api/collection/user.dart";-import 'package:photos/theme/colors.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';+import "package:photos/ui/viewer/search/result/person_face_widget.dart";import 'package:tuple/tuple.dart';enum AvatarType { small, mini, tiny, extra }-class UserAvatarWidget extends StatelessWidget {+class UserAvatarWidget extends StatefulWidget {final User user;final AvatarType type;final int currentUserID;@@ -21,45 +26,162 @@ class UserAvatarWidget extends StatelessWidget {this.thumbnailView = false,});+ @override+ State<UserAvatarWidget> createState() => _UserAvatarWidgetState();+}++class _UserAvatarWidgetState extends State<UserAvatarWidget> {+ Future<String?>? _personID;+ EnteFile? _faceThumbnail;+ final _logger = Logger("_UserAvatarWidgetState");++ @override+ void initState() {+ super.initState();+ if (PersonService.instance.emailToNameMapCache[widget.user.email] != null) {+ _personID = PersonService.instance.getPersons().then((people) async {+ final person = people.firstWhereOrNull(+ (person) => person.data.email == widget.user.email,+ );+ if (person != null) {+ _faceThumbnail =+ await PersonService.instance.getRecentFileOfPerson(person);+ }+ return person?.remoteID;+ });+ }+ }++ @override+ Widget build(BuildContext context) {+ final double size = getAvatarSize(widget.type);++ return _personID != null+ ? Container(+ padding: const EdgeInsets.all(0.5),+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ border: Border.all(+ color: widget.thumbnailView+ ? strokeMutedDark+ : getEnteColorScheme(context).strokeMuted,+ width: 1,+ strokeAlign: BorderSide.strokeAlignOutside,+ ),+ ),+ child: SizedBox(+ height: size,+ width: size,+ child: FutureBuilder(+ future: _personID,+ builder: (context, snapshot) {+ if (snapshot.hasData) {+ final personID = snapshot.data as String;+ return ClipOval(+ child: PersonFaceWidget(+ _faceThumbnail!,+ personId: personID,+ ),+ );+ } else if (snapshot.hasError) {+ _logger.severe("Error loading personID", snapshot.error);+ return _FirstLetterAvatar(+ user: widget.user,+ currentUserID: widget.currentUserID,+ thumbnailView: widget.thumbnailView,+ type: widget.type,+ );+ }+ return const SizedBox.shrink();+ },+ ),+ ),+ )+ : _FirstLetterAvatar(+ user: widget.user,+ currentUserID: widget.currentUserID,+ thumbnailView: widget.thumbnailView,+ type: widget.type,+ );+ }++ double getAvatarSize(+ AvatarType type,+ ) {+ switch (type) {+ case AvatarType.small:+ return 36.0;+ case AvatarType.mini:+ return 24.0;+ case AvatarType.tiny:+ return 18.0;+ case AvatarType.extra:+ return 18.0;+ }+ }+}++class _FirstLetterAvatar extends StatefulWidget {+ final User user;+ final int currentUserID;+ final bool thumbnailView;+ final AvatarType type;+ const _FirstLetterAvatar({+ required this.user,+ required this.currentUserID,+ required this.thumbnailView,+ required this.type,+ });++ @override+ State<_FirstLetterAvatar> createState() => _FirstLetterAvatarState();+}++class _FirstLetterAvatarState extends State<_FirstLetterAvatar> {@overrideWidget build(BuildContext context) {final colorScheme = getEnteColorScheme(context);- final displayChar = (user.displayName == null || user.displayName!.isEmpty)- ? ((user.email.isEmpty) ? " " : user.email.substring(0, 1))- : user.displayName!.substring(0, 1);+ final displayChar =+ (widget.user.displayName == null || widget.user.displayName!.isEmpty)+ ? ((widget.user.email.isEmpty)+ ? " "+ : widget.user.email.substring(0, 1))+ : widget.user.displayName!.substring(0, 1);Color decorationColor;- if (user.id == null || user.id! <= 0 || user.id == currentUserID) {+ if (widget.user.id == null ||+ widget.user.id! <= 0 ||+ widget.user.id == widget.currentUserID) {decorationColor = Colors.black;} else {- decorationColor = colorScheme- .avatarColors[(user.id!).remainder(colorScheme.avatarColors.length)];+ decorationColor = colorScheme.avatarColors[+ (widget.user.id!).remainder(colorScheme.avatarColors.length)];}- final avatarStyle = getAvatarStyle(context, type);+ final avatarStyle = getAvatarStyle(context, widget.type);final double size = avatarStyle.item1;final TextStyle textStyle = avatarStyle.item2;return Container(- height: size,- width: size,- padding: thumbnailView- ? const EdgeInsets.only(bottom: 1)- : const EdgeInsets.all(2),- decoration: thumbnailView- ? null- : BoxDecoration(- shape: BoxShape.circle,- color: decorationColor,- border: Border.all(- color: strokeBaseDark,- width: 1.0,- ),- ),- child: CircleAvatar(- backgroundColor: decorationColor,- child: Text(- displayChar.toUpperCase(),- // fixed color- style: textStyle.copyWith(color: Colors.white),+ padding: const EdgeInsets.all(0.5),+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ border: Border.all(+ color: widget.thumbnailView+ ? strokeMutedDark+ : getEnteColorScheme(context).strokeMuted,+ width: 1.0,+ strokeAlign: BorderSide.strokeAlignOutside,+ ),+ ),+ child: SizedBox(+ height: size,+ width: size,+ child: CircleAvatar(+ backgroundColor: decorationColor,+ child: Text(+ displayChar.toUpperCase(),+ // fixed color+ style: textStyle.copyWith(color: Colors.white),+ ),),),);