Skip to content

armgit / ente

Public Imported from GitHub
0

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

Sort people reversed on photo count

laurenspriem66f744dd55b9
diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dart
index 849927ec89..f4467121ee 100644
--- a/mobile/apps/photos/lib/services/search_service.dart
+++ b/mobile/apps/photos/lib/services/search_service.dart
@@ -1023,6 +1023,7 @@ class SearchService {
sortKey: localSettings.peopleSortKey(),
nameSortAscending: localSettings.peopleNameSortAscending,
updatedSortAscending: localSettings.peopleUpdatedSortAscending,
+ photosSortAscending: localSettings.peoplePhotosSortAscending,
),
);
if (limit != null) {
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 e6d956df96..bf4c6edb93 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
@@ -375,6 +375,7 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
late PeopleSortKey _sortKey;
bool _nameSortAscending = true;
bool _updatedSortAscending = false;
+ bool _photosSortAscending = false;
static const double _sortMenuItemHeight = 52;
static const double _sortMenuCornerRadius = 12;
@@ -424,6 +425,7 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
_sortKey = settings.peopleSortKey();
_nameSortAscending = settings.peopleNameSortAscending;
_updatedSortAscending = settings.peopleUpdatedSortAscending;
+ _photosSortAscending = settings.peoplePhotosSortAscending;
sectionData = getResults(init: true);
final streamsToListenTo = SectionType.face.viewAllUpdateEvents();
@@ -515,7 +517,7 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
case PeopleSortKey.lastUpdated:
return _updatedSortAscending;
case PeopleSortKey.mostPhotos:
- return false;
+ return _photosSortAscending;
}
}
@@ -528,12 +530,15 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
_updatedSortAscending = !_updatedSortAscending;
return true;
case PeopleSortKey.mostPhotos:
- return false;
+ _photosSortAscending = !_photosSortAscending;
+ return true;
}
}
bool _canToggleSortDirection(PeopleSortKey key) {
- return key == PeopleSortKey.name || key == PeopleSortKey.lastUpdated;
+ return key == PeopleSortKey.name ||
+ key == PeopleSortKey.lastUpdated ||
+ key == PeopleSortKey.mostPhotos;
}
void _sortFaces(List<GenericSearchResult> faces) {
@@ -543,6 +548,7 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
sortKey: _sortKey,
nameSortAscending: _nameSortAscending,
updatedSortAscending: _updatedSortAscending,
+ photosSortAscending: _photosSortAscending,
),
);
}
@@ -551,6 +557,7 @@ class _PeopleSectionAllWidgetState extends State<PeopleSectionAllWidget> {
await localSettings.setPeopleSortKey(_sortKey);
await localSettings.setPeopleNameSortAscending(_nameSortAscending);
await localSettings.setPeopleUpdatedSortAscending(_updatedSortAscending);
+ await localSettings.setPeoplePhotosSortAscending(_photosSortAscending);
Bus.instance.fire(PeopleSortOrderChangeEvent());
}
diff --git a/mobile/apps/photos/lib/utils/local_settings.dart b/mobile/apps/photos/lib/utils/local_settings.dart
index 3d07add0f5..16050362bd 100644
--- a/mobile/apps/photos/lib/utils/local_settings.dart
+++ b/mobile/apps/photos/lib/utils/local_settings.dart
@@ -54,6 +54,7 @@ class LocalSettings {
static const kPeopleSortKey = "people_sort_key";
static const kPeopleSortNameAscending = "people_sort_name_ascending";
static const kPeopleSortUpdatedAscending = "people_sort_updated_ascending";
+ static const kPeopleSortPhotosAscending = "people_sort_photos_ascending";
static const kShowLocalIDOverThumbnails = "show_local_id_over_thumbnails";
static const kEnableDatabaseLogging = "enable_db_logging";
static const _kInternalUserDisabled = "ls.internal_user_disabled";
@@ -118,6 +119,13 @@ class LocalSettings {
await _prefs.setBool(kPeopleSortUpdatedAscending, value);
}
+ bool get peoplePhotosSortAscending =>
+ _prefs.getBool(kPeopleSortPhotosAscending) ?? false;
+
+ Future<void> setPeoplePhotosSortAscending(bool value) async {
+ await _prefs.setBool(kPeopleSortPhotosAscending, value);
+ }
+
GroupType getGalleryGroupType() {
final groupTypeString = _prefs.getString(kGalleryGroupType);
if (groupTypeString != null) {
diff --git a/mobile/apps/photos/lib/utils/people_sort_util.dart b/mobile/apps/photos/lib/utils/people_sort_util.dart
index 9c18034e87..e0507ff9cb 100644
--- a/mobile/apps/photos/lib/utils/people_sort_util.dart
+++ b/mobile/apps/photos/lib/utils/people_sort_util.dart
@@ -7,11 +7,13 @@ class PeopleSortConfig {
final PeopleSortKey sortKey;
final bool nameSortAscending;
final bool updatedSortAscending;
+ final bool photosSortAscending;
const PeopleSortConfig({
required this.sortKey,
required this.nameSortAscending,
required this.updatedSortAscending,
+ required this.photosSortAscending,
});
}
@@ -46,7 +48,10 @@ void sortPeopleFaces(
int compareValue;
switch (config.sortKey) {
case PeopleSortKey.mostPhotos:
- compareValue = b.fileCount().compareTo(a.fileCount());
+ compareValue = a.fileCount().compareTo(b.fileCount());
+ if (!config.photosSortAscending) {
+ compareValue = -compareValue;
+ }
break;
case PeopleSortKey.name:
if (!aHasPerson) {