Skip to content

armgit / ente

Public Imported from GitHub
0

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

Pinning on mobile

laurenspriemcb255f8776be
diff --git a/mobile/apps/photos/lib/models/ml/face/person.dart b/mobile/apps/photos/lib/models/ml/face/person.dart
index 3a7a5727a8..b692555c21 100644
--- a/mobile/apps/photos/lib/models/ml/face/person.dart
+++ b/mobile/apps/photos/lib/models/ml/face/person.dart
@@ -52,6 +52,7 @@ class PersonData {
/// Used to mark a person to not show in the people section.
/// WARNING: When checking whether to show a person, use [isIgnored] instead, as it also checks legacy hidden names.
final bool isHidden;
+ final bool isPinned;
String? avatarFaceID;
List<ClusterInfo> assigned = List<ClusterInfo>.empty();
@@ -78,6 +79,7 @@ class PersonData {
this.rejectedFaceIDs = const <String>[],
this.avatarFaceID,
this.isHidden = false,
+ this.isPinned = false,
this.birthDate,
this.email,
this.userID,
@@ -88,6 +90,7 @@ class PersonData {
List<ClusterInfo>? assigned,
String? avatarFaceId,
bool? isHidden,
+ bool? isPinned,
int? version,
String? birthDate,
String? email,
@@ -99,6 +102,7 @@ class PersonData {
assigned: assigned ?? this.assigned,
avatarFaceID: avatarFaceId ?? avatarFaceID,
isHidden: isHidden ?? this.isHidden,
+ isPinned: isPinned ?? this.isPinned,
birthDate: birthDate ?? this.birthDate,
email: email ?? this.email,
userID: userID ?? this.userID,
@@ -131,6 +135,7 @@ class PersonData {
'rejectedFaceIDs': rejectedFaceIDs,
'avatarFaceID': avatarFaceID,
'isHidden': isHidden,
+ 'isPinned': isPinned,
'birthDate': birthDate,
'email': email,
'userID': userID,
@@ -160,6 +165,7 @@ class PersonData {
rejectedFaceIDs: rejectedFaceIDs,
avatarFaceID: json['avatarFaceID'] as String?,
isHidden: json['isHidden'] as bool? ?? false,
+ isPinned: json['isPinned'] as bool? ?? false,
birthDate: json['birthDate'] as String?,
userID: json['userID'] as int?,
email: json['email'] as String?,
diff --git a/mobile/apps/photos/lib/models/search/search_constants.dart b/mobile/apps/photos/lib/models/search/search_constants.dart
index f05dfc50cb..c5d64a2645 100644
--- a/mobile/apps/photos/lib/models/search/search_constants.dart
+++ b/mobile/apps/photos/lib/models/search/search_constants.dart
@@ -1,5 +1,6 @@
const kPersonParamID = 'person_id';
const kPersonWidgetKey = 'person_widget_key';
+const kPersonPinned = 'person_pinned';
const kClusterParamId = 'cluster_id';
const kFileID = 'file_id';
const kContactEmail = 'contact_email';
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
index 074f0a7876..9fdc03d990 100644
--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
@@ -240,6 +240,7 @@ class PersonService {
required String name,
required String clusterID,
bool isHidden = false,
+ bool isPinned = false,
String? birthdate,
String? email,
}) async {
@@ -253,6 +254,7 @@ class PersonService {
),
],
isHidden: isHidden,
+ isPinned: isPinned,
birthDate: birthdate,
email: email,
);
@@ -530,6 +532,7 @@ class PersonService {
String? name,
String? avatarFaceId,
bool? isHidden,
+ bool? isPinned,
int? version,
String? birthDate,
String? email,
@@ -540,6 +543,7 @@ class PersonService {
name: name,
avatarFaceId: avatarFaceId,
isHidden: isHidden,
+ isPinned: isPinned,
version: version,
birthDate: birthDate,
email: email,
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index 8cd531ac51..b8d7b9ba6e 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -797,7 +797,18 @@ class SearchService {
personIdToFiles[a]!.length,
),
);
- for (final personID in sortedPersonIds) {
+ final pinnedPersonIds = <String>[];
+ final unpinnedPersonIds = <String>[];
+ for (final personId in sortedPersonIds) {
+ final person = personIdToPerson[personId];
+ if (person != null && person.data.isPinned) {
+ pinnedPersonIds.add(personId);
+ } else {
+ unpinnedPersonIds.add(personId);
+ }
+ }
+ final orderedPersonIds = [...pinnedPersonIds, ...unpinnedPersonIds];
+ for (final personID in orderedPersonIds) {
final files = personIdToFiles[personID]!;
final PersonEntity p = personIdToPerson[personID]!;
if (p.data.isIgnored) continue;
@@ -810,6 +821,7 @@ class SearchService {
kPersonWidgetKey: p.data.avatarFaceID ?? p.hashCode.toString(),
kPersonParamID: personID,
kFileID: files.first.uploadedFileID,
+ kPersonPinned: p.data.isPinned,
},
onResultTap: (ctx) {
routeToPage(
@@ -825,6 +837,7 @@ class SearchService {
kPersonWidgetKey:
p.data.avatarFaceID ?? p.hashCode.toString(),
kPersonParamID: personID,
+ kPersonPinned: p.data.isPinned,
kFileID: files.first.uploadedFileID,
},
hierarchicalSearchFilter: FaceFilter(
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
index de26e9d614..b2de4ebc3a 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart
@@ -70,98 +70,132 @@ class _PeopleSelectionActionWidgetState
return const SizedBox.shrink();
}
- final List<SelectionActionButton> items = [];
- final selectedPersonIds = _getSelectedPersonIds();
- final selectedClusterIds = _getSelectedClusterIds();
- final onlyOnePerson =
- selectedPersonIds.length == 1 && selectedClusterIds.isEmpty;
- final onlyPersonSelected =
- selectedPersonIds.isNotEmpty && selectedClusterIds.isEmpty;
- final onePersonAndClusters =
- selectedPersonIds.length == 1 && selectedClusterIds.isNotEmpty;
- final anythingSelected =
- selectedPersonIds.isNotEmpty || selectedClusterIds.isNotEmpty;
-
- items.add(
- SelectionActionButton(
- labelText: AppLocalizations.of(context).edit,
- icon: Icons.edit_outlined,
- onTap: _onEditPerson,
- shouldShow: onlyOnePerson,
- ),
- );
- items.add(
- SelectionActionButton(
- labelText: AppLocalizations.of(context).review,
- icon: Icons.search_outlined,
- onTap: _onReviewSuggestion,
- shouldShow: onlyOnePerson,
- ),
- );
- items.add(
- SelectionActionButton(
- labelText: AppLocalizations.of(context).ignore,
- icon: Icons.hide_image_outlined,
- onTap: _onIgnore,
- shouldShow: anythingSelected,
- ),
- );
- items.add(
- SelectionActionButton(
- labelText: AppLocalizations.of(context).merge,
- icon: Icons.merge_outlined,
- onTap: _onMerge,
- shouldShow: onePersonAndClusters,
- ),
- );
- items.add(
- SelectionActionButton(
- labelText: AppLocalizations.of(context).reset,
- icon: Icons.remove_outlined,
- onTap: _onResetPerson,
- shouldShow: onlyOnePerson,
- ),
- );
- items.add(
- SelectionActionButton(
- labelText: AppLocalizations.of(context).autoAddToAlbum,
- iconWidget: Image.asset(
- "assets/auto-add-people.png",
- width: 24,
- height: 24,
- color: EnteTheme.isDark(context) ? Colors.white : Colors.black,
- ),
- onTap: _autoAddToAlbum,
- shouldShow: onlyPersonSelected,
- ),
- );
+ return FutureBuilder<Map<String, PersonEntity>>(
+ future: personEntitiesMapFuture,
+ builder: (context, snapshot) {
+ if (!snapshot.hasData) {
+ return const SizedBox.shrink();
+ }
+ final personMap = snapshot.data!;
+ final List<SelectionActionButton> items = [];
+ final selectedPersonIds = _getSelectedPersonIds();
+ final selectedClusterIds = _getSelectedClusterIds();
+ final onlyOnePerson =
+ selectedPersonIds.length == 1 && selectedClusterIds.isEmpty;
+ final onlyPersonSelected =
+ selectedPersonIds.isNotEmpty && selectedClusterIds.isEmpty;
+ final onePersonAndClusters =
+ selectedPersonIds.length == 1 && selectedClusterIds.isNotEmpty;
+ final anythingSelected =
+ selectedPersonIds.isNotEmpty || selectedClusterIds.isNotEmpty;
+ final bool showPinAction = onlyPersonSelected &&
+ selectedPersonIds.any(
+ (id) => !(personMap[id]?.data.isPinned ?? false),
+ );
+ final bool showUnpinAction = onlyPersonSelected &&
+ selectedPersonIds.isNotEmpty &&
+ selectedPersonIds.every(
+ (id) => personMap[id]?.data.isPinned ?? false,
+ );
- return MediaQuery(
- data: MediaQuery.of(context).removePadding(removeBottom: true),
- child: SafeArea(
- child: Scrollbar(
- radius: const Radius.circular(1),
- thickness: 2,
- thumbVisibility: true,
- child: SingleChildScrollView(
- physics: const BouncingScrollPhysics(
- decelerationRate: ScrollDecelerationRate.fast,
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).edit,
+ icon: Icons.edit_outlined,
+ onTap: _onEditPerson,
+ shouldShow: onlyOnePerson,
+ ),
+ );
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).review,
+ icon: Icons.search_outlined,
+ onTap: _onReviewSuggestion,
+ shouldShow: onlyOnePerson,
+ ),
+ );
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).ignore,
+ icon: Icons.hide_image_outlined,
+ onTap: _onIgnore,
+ shouldShow: anythingSelected,
+ ),
+ );
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).merge,
+ icon: Icons.merge_outlined,
+ onTap: _onMerge,
+ shouldShow: onePersonAndClusters,
+ ),
+ );
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).reset,
+ icon: Icons.remove_outlined,
+ onTap: _onResetPerson,
+ shouldShow: onlyOnePerson,
+ ),
+ );
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).pin,
+ icon: Icons.push_pin_outlined,
+ onTap: () => _updatePinState(true),
+ shouldShow: showPinAction,
+ ),
+ );
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).unpin,
+ icon: Icons.push_pin,
+ onTap: () => _updatePinState(false),
+ shouldShow: showUnpinAction,
+ ),
+ );
+ items.add(
+ SelectionActionButton(
+ labelText: AppLocalizations.of(context).autoAddToAlbum,
+ iconWidget: Image.asset(
+ "assets/auto-add-people.png",
+ width: 24,
+ height: 24,
+ color: EnteTheme.isDark(context) ? Colors.white : Colors.black,
),
- scrollDirection: Axis.horizontal,
- child: Container(
- padding: const EdgeInsets.only(bottom: 24),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(width: 4),
- ...items,
- const SizedBox(width: 4),
- ],
+ onTap: _autoAddToAlbum,
+ shouldShow: onlyPersonSelected,
+ ),
+ );
+
+ return MediaQuery(
+ data: MediaQuery.of(context).removePadding(removeBottom: true),
+ child: SafeArea(
+ child: Scrollbar(
+ radius: const Radius.circular(1),
+ thickness: 2,
+ thumbVisibility: true,
+ child: SingleChildScrollView(
+ physics: const BouncingScrollPhysics(
+ decelerationRate: ScrollDecelerationRate.fast,
+ ),
+ scrollDirection: Axis.horizontal,
+ child: Container(
+ padding: const EdgeInsets.only(bottom: 24),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(width: 4),
+ ...items,
+ const SizedBox(width: 4),
+ ],
+ ),
+ ),
),
),
),
- ),
- ),
+ );
+ },
);
}
@@ -210,6 +244,28 @@ class _PeopleSelectionActionWidgetState
widget.selectedPeople.clearAll();
}
+ Future<void> _updatePinState(bool shouldPin) async {
+ final selectedPersonIds = _getSelectedPersonIds();
+ if (selectedPersonIds.isEmpty) return;
+ try {
+ final personMap = await personEntitiesMapFuture;
+ for (final personID in selectedPersonIds) {
+ final person = personMap[personID];
+ if (person == null || person.data.name.isEmpty) continue;
+ if (person.data.isPinned == shouldPin) continue;
+ final updatedPerson = person.copyWith(
+ data: person.data.copyWith(isPinned: shouldPin),
+ );
+ await PersonService.instance.updatePerson(updatedPerson);
+ }
+ Bus.instance.fire(PeopleChangedEvent());
+ } catch (e, s) {
+ _logger.severe('Failed to update pin state', e, s);
+ } finally {
+ widget.selectedPeople.clearAll();
+ }
+ }
+
Future<void> _onResetPerson() async {
final selectedPersonIds = _getSelectedPersonIds();
if (selectedPersonIds.length != 1) return;
diff --git a/mobile/apps/photos/lib/ui/viewer/people/pinned_person_badge.dart b/mobile/apps/photos/lib/ui/viewer/people/pinned_person_badge.dart
new file mode 100644
index 0000000000..aae4208fe6
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/people/pinned_person_badge.dart
@@ -0,0 +1,35 @@
+import "package:flutter/material.dart";
+import "package:photos/theme/ente_theme.dart";
+
+class PinnedPersonBadge extends StatelessWidget {
+ const PinnedPersonBadge({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ return Container(
+ width: 26,
+ height: 26,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: colorScheme.backgroundElevated2,
+ border: Border.all(
+ color: colorScheme.backgroundElevated,
+ width: 2,
+ ),
+ boxShadow: [
+ BoxShadow(
+ color: Colors.black.withValues(alpha: 0.12),
+ blurRadius: 6,
+ offset: const Offset(0, 2),
+ ),
+ ],
+ ),
+ child: Icon(
+ Icons.push_pin,
+ size: 14,
+ color: colorScheme.textMuted,
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart
index 0bb294bc95..5a63904789 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart
@@ -23,7 +23,11 @@ import "package:photos/ui/common/date_input.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/components/action_sheet_widget.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
+import "package:photos/ui/components/captioned_text_widget.dart";
+import "package:photos/ui/components/expandable_menu_item_widget.dart";
+import "package:photos/ui/components/menu_item_widget/menu_item_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
+import "package:photos/ui/components/toggle_switch_widget.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/sharing/album_share_info_widget.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
@@ -64,6 +68,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
String _inputName = "";
String? _selectedDate;
String? _email;
+ bool _isPinned = false;
bool userAlreadyAssigned = false;
late final Logger _logger = Logger("_SavePersonState");
Timer? _debounce;
@@ -78,6 +83,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
_selectedDate = widget.person?.data.birthDate;
_email = widget.person?.data.email;
person = widget.person;
+ _isPinned = widget.person?.data.isPinned ?? false;
}
@override
@@ -297,7 +303,9 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
curve: Curves.easeInOutQuad,
child: _EmailSection(_email, person?.remoteID),
),
- const SizedBox(height: 32),
+ const SizedBox(height: 24),
+ _buildVisibilitySection(context),
+ const SizedBox(height: 24),
ButtonWidget(
buttonType: ButtonType.primary,
labelText: context.l10n.save,
@@ -354,6 +362,33 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
);
}
+ Widget _buildVisibilitySection(BuildContext context) {
+ return ExpandableMenuItemWidget(
+ title: context.l10n.visibility,
+ leadingIcon: Icons.visibility_outlined,
+ selectionOptionsWidget: Column(
+ children: [
+ MenuItemWidget(
+ captionedTextWidget: CaptionedTextWidget(
+ title: context.l10n.pinToTop,
+ ),
+ trailingWidget: ToggleSwitchWidget(
+ value: () => _isPinned,
+ onChanged: () async {
+ if (!mounted) return;
+ setState(() {
+ _isPinned = !_isPinned;
+ });
+ },
+ ),
+ singleBorderRadius: 8,
+ isGestureDetectorDisabled: true,
+ ),
+ ],
+ ),
+ );
+ }
+
Future<dynamic> _saveChangesPrompt(BuildContext context) async {
PersonEntity? updatedPersonEntity;
return await showActionSheet(
@@ -570,6 +605,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
final personEntity = await PersonService.instance.addPerson(
name: text,
clusterID: clusterID,
+ isPinned: _isPinned,
birthdate: birthdate,
email: email,
);
@@ -599,8 +635,9 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
bool get changed => widget.isEditing
? (_inputName.trim() != person!.data.name ||
- _selectedDate != person!.data.birthDate) ||
- _email != person!.data.email
+ _selectedDate != person!.data.birthDate ||
+ _email != person!.data.email ||
+ _isPinned != person!.data.isPinned)
: _inputName.trim().isNotEmpty;
Future<PersonEntity?> updatePerson(BuildContext context) async {
@@ -618,6 +655,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
person!.remoteID,
name: name,
birthDate: birthDate,
+ isPinned: _isPinned,
email: _email,
);
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
index b42b2cd444..ddfe90f72e 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/people_section_all_page.dart
@@ -23,6 +23,7 @@ import "package:photos/ui/viewer/people/add_person_action_sheet.dart";
import "package:photos/ui/viewer/people/people_page.dart";
import "package:photos/ui/viewer/people/person_face_widget.dart";
import "package:photos/ui/viewer/people/person_gallery_suggestion.dart";
+import "package:photos/ui/viewer/people/pinned_person_badge.dart";
import "package:photos/ui/viewer/search/result/search_result_page.dart";
import "package:photos/ui/viewer/search_tab/people_section.dart";
import "package:photos/utils/navigation_util.dart";
@@ -146,6 +147,8 @@ class SelectablePersonSearchExample extends StatelessWidget {
final borderRadius = 82 * (size / 102);
final bool isCluster = (searchResult.type() == ResultType.faces &&
int.tryParse(searchResult.name()) != null);
+ final bool isPinnedPerson =
+ !isCluster && (searchResult.params[kPersonPinned] as bool? ?? false);
return ListenableBuilder(
listenable: selectedPeople,
@@ -247,6 +250,12 @@ class SelectablePersonSearchExample extends StatelessWidget {
: null,
),
),
+ if (isPinnedPerson)
+ const Positioned(
+ right: -6,
+ bottom: -6,
+ child: PinnedPersonBadge(),
+ ),
],
),
isCluster
@@ -425,6 +434,10 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
false;
if (aIndex && !bIndex) return -1;
if (!aIndex && bIndex) return 1;
+ final bool aPinned = a.params[kPersonPinned] as bool? ?? false;
+ final bool bPinned = b.params[kPersonPinned] as bool? ?? false;
+ if (aPinned && !bPinned) return -1;
+ if (!aPinned && bPinned) return 1;
return a.name().compareTo(b.name());
});
}