Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move contact unlink action to avatar badge

Neeraj Gupta70401ed2fa2f
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dart
index 1c74c5ddfc..22e2047714 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dart
@@ -25,21 +25,15 @@ class ContactPersonPickerPickPhoto extends ContactPersonPickerResult {
const ContactPersonPickerPickPhoto();
}
-class ContactPersonPickerUnlink extends ContactPersonPickerResult {
- const ContactPersonPickerUnlink();
-}
-
class ContactPersonPickerPage extends StatefulWidget {
const ContactPersonPickerPage({
required this.contactUserId,
required this.contactEmail,
- required this.linkedPerson,
super.key,
});
final int contactUserId;
final String contactEmail;
- final PersonEntity? linkedPerson;
@override
State<ContactPersonPickerPage> createState() =>
@@ -116,7 +110,6 @@ class _ContactPersonPickerPageState extends State<ContactPersonPickerPage> {
Widget _buildHeader(BuildContext context, AppLocalizations l10n) {
final colors = context.componentColors;
final topPadding = MediaQuery.paddingOf(context).top;
- final linkedPerson = widget.linkedPerson;
return Padding(
padding: EdgeInsets.fromLTRB(
@@ -151,20 +144,10 @@ class _ContactPersonPickerPageState extends State<ContactPersonPickerPage> {
IconButtonComponent(
variant: IconButtonComponentVariant.primary,
shouldSurfaceExecutionStates: false,
- tooltip: linkedPerson == null
- ? l10n.setAContactPhoto
- : l10n.removeLink,
- icon: HugeIcon(
- icon: linkedPerson == null
- ? HugeIcons.strokeRoundedImageAdd02
- : HugeIcons.strokeRoundedCancel01,
- ),
+ tooltip: l10n.setAContactPhoto,
+ icon: const HugeIcon(icon: HugeIcons.strokeRoundedImageAdd02),
onTap: () {
- Navigator.of(context).pop(
- linkedPerson == null
- ? const ContactPersonPickerPickPhoto()
- : const ContactPersonPickerUnlink(),
- );
+ Navigator.of(context).pop(const ContactPersonPickerPickPhoto());
},
),
],
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart
index ab09219e0f..66cd7946e8 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart
@@ -94,6 +94,7 @@ class _EditContactPageState extends State<EditContactPage> {
String get _initialName => (widget.existingContact?.data?.name ?? "").trim();
bool get _hasUnsavedChanges =>
_nameController.text.trim() != _initialName || _photoDirty || _linkDirty;
+ bool get _hasLinkedPersonDraft => !_unlinkDraft && _draftLinkedPerson != null;
bool get _hasContactPhoto =>
_draftPhotoBytes != null ||
(!_photoDirty &&
@@ -158,9 +159,12 @@ class _EditContactPageState extends State<EditContactPage> {
Positioned(
right: 0,
bottom: 0,
- child: _AvatarEditButton(
+ child: _AvatarActionButton(
size: _editBadgeSize,
- onTap: _openAvatarEditor,
+ isUnlink: _hasLinkedPersonDraft,
+ onTap: _hasLinkedPersonDraft
+ ? _draftUnlinkPerson
+ : _openAvatarEditor,
),
),
],
@@ -332,7 +336,6 @@ class _EditContactPageState extends State<EditContactPage> {
ContactPersonPickerPage(
contactUserId: widget.contactUserId,
contactEmail: widget.email,
- linkedPerson: _unlinkDraft ? null : _draftLinkedPerson,
),
);
if (!mounted || result == null) {
@@ -342,19 +345,19 @@ class _EditContactPageState extends State<EditContactPage> {
await _pickContactPhoto();
return;
}
- if (result is ContactPersonPickerUnlink) {
- setState(() {
- _draftLinkedPerson = null;
- _unlinkDraft = true;
- _linkDirty = _initialLinkedPerson != null;
- });
- return;
- }
if (result is ContactPersonPickerSelected) {
await _draftSelectedPerson(result.person);
}
}
+ void _draftUnlinkPerson() {
+ setState(() {
+ _draftLinkedPerson = null;
+ _unlinkDraft = true;
+ _linkDirty = _initialLinkedPerson != null;
+ });
+ }
+
Future<void> _draftSelectedPerson(PersonEntity person) async {
final success = await _loadPersonPhotoDraft(person, showError: true);
if (!success || !mounted) {
@@ -770,26 +773,34 @@ class _ContactSaveButton extends StatelessWidget {
}
}
-class _AvatarEditButton extends StatelessWidget {
+class _AvatarActionButton extends StatelessWidget {
final double size;
+ final bool isUnlink;
final VoidCallback onTap;
- const _AvatarEditButton({required this.size, required this.onTap});
+ const _AvatarActionButton({
+ required this.size,
+ required this.isUnlink,
+ required this.onTap,
+ });
@override
Widget build(BuildContext context) {
+ final colors = context.componentColors;
return GestureDetector(
onTap: onTap,
child: Container(
width: size,
height: size,
decoration: BoxDecoration(
- color: getEnteColorScheme(context).greenBase,
+ color: isUnlink ? colors.warning : colors.primary,
shape: BoxShape.circle,
),
- child: const Center(
+ child: Center(
child: HugeIcon(
- icon: HugeIcons.strokeRoundedEdit03,
+ icon: isUnlink
+ ? HugeIcons.strokeRoundedCancel01
+ : HugeIcons.strokeRoundedEdit03,
color: Colors.white,
size: 12,
strokeWidth: 2,