π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Move photo sorting into album options
r4khul68b2c0ff50a3
diff --git a/mobile/apps/photos/changes/album-photo-sort-options.md b/mobile/apps/photos/changes/album-photo-sort-options.mdnew file mode 100644index 0000000000..ac7eb5e8b5--- /dev/null+++ b/mobile/apps/photos/changes/album-photo-sort-options.md@@ -0,0 +1 @@+- Moved photo sorting into album options.diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dartindex e336fe94db..d0f2102921 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/collection_page.dart@@ -1,9 +1,6 @@import "dart:async";-import "package:ente_components/ente_components.dart";-import "package:ente_strings/ente_strings.dart";import 'package:flutter/material.dart';-import "package:hugeicons/hugeicons.dart";import "package:logging/logging.dart";import 'package:photos/core/configuration.dart';import 'package:photos/core/event_bus.dart';@@ -11,7 +8,6 @@ import 'package:photos/db/files_db.dart';import "package:photos/events/collection_meta_event.dart";import 'package:photos/events/collection_updated_event.dart';import 'package:photos/events/files_updated_event.dart';-import "package:photos/models/collection/collection.dart";import 'package:photos/models/collection/collection_items.dart';import 'package:photos/models/file/file.dart';import 'package:photos/models/file_load_result.dart';@@ -32,7 +28,6 @@ import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.daimport "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dart";import "package:photos/ui/viewer/gallery/state/search_filter_data_provider.dart";import "package:photos/ui/viewer/gallery/state/selection_state.dart";-import "package:photos/utils/magic_util.dart";class CollectionPage extends StatefulWidget {final CollectionWithThumbnail c;@@ -193,15 +188,6 @@ class _CollectionPageState extends State<CollectionPage> {sortAsyncFn: () => c.collection.pubMagicMetadata.asc ?? false,addHeaderOrFooterEmptyState: false,showSelectAll: true,- groupHeaderAction: galleryType.canSort()- ? ListenableBuilder(- listenable: _selectedFiles,- builder: (context, child) => _selectedFiles.files.isEmpty- ? child!- : const SizedBox.shrink(),- child: _SortButton(c.collection),- )- : null,emptyState: galleryType == GalleryType.ownedCollection? EmptyAlbumState(c.collection,@@ -264,34 +250,3 @@ class _CollectionPageState extends State<CollectionPage> {);}}--class _SortButton extends StatelessWidget {- const _SortButton(this.collection);-- final Collection collection;-- @override- Widget build(BuildContext context) {- final strings = context.strings;- return EntePopupMenuButton<bool>(- optionsBuilder: () => [- EntePopupMenuOption(value: false, label: strings.sortNewestFirst),- EntePopupMenuOption(value: true, label: strings.sortOldestFirst),- ],- onSelected: (sortByAsc) {- unawaited(changeSortOrder(context, collection, sortByAsc));- },- child: Tooltip(- message: strings.sort,- child: Padding(- padding: const EdgeInsets.all(Spacing.xs),- child: HugeIcon(- icon: HugeIcons.strokeRoundedArrowUpDown,- size: IconSizes.small,- color: context.componentColors.textLighter,- ),- ),- ),- );- }-}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dartindex c58f38ddb4..2a67d8a286 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart@@ -52,6 +52,7 @@ import "package:photos/ui/viewer/gallery/component/album_description_header.dartimport "package:photos/ui/viewer/gallery/gallery_app_bar_actions.dart";import "package:photos/ui/viewer/gallery/gallery_app_bar_config.dart";import "package:photos/ui/viewer/gallery/hooks/add_photos_sheet.dart";+import "package:photos/ui/viewer/gallery/hooks/album_sort_sheet.dart";import "package:photos/ui/viewer/gallery/hooks/edit_album_details_sheet.dart";import "package:photos/ui/viewer/gallery/state/inherited_search_filter_data.dart";import "package:photos/ui/viewer/hierarchicial_search/app_bar_filter_chips.dart";@@ -873,14 +874,21 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {size: IconSizes.small,),),- if (galleryType.canSort() && !onCover)+ if (galleryType.canSort())_menuOption(AlbumPopupAction.sort,- strings.sortAlbumsBy,+ strings.sort,const HugeIcon(icon: HugeIcons.strokeRoundedSorting01,size: IconSizes.small,),+ secondaryLabel: (widget.collection!.pubMagicMetadata.asc ?? false)+ ? strings.sortOldestFirst+ : strings.sortNewestFirst,+ trailingWidget: const HugeIcon(+ icon: HugeIcons.strokeRoundedArrowRight01,+ size: IconSizes.small,+ ),),if (galleryType == GalleryType.uncategorized)_menuOption(@@ -1116,12 +1124,16 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {String label,Widget leadingWidget, {Color? labelColor,+ String? secondaryLabel,+ Widget? trailingWidget,}) {return EntePopupMenuOption(value: value,label: label,labelColor: labelColor,leadingWidget: leadingWidget,+ secondaryLabel: secondaryLabel,+ trailingWidget: trailingWidget,);}@@ -1301,28 +1313,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {}Future<void> _showSortOption(BuildContext bContext) async {- final bool? sortByAsc = await showMenu<bool>(- context: bContext,- position: RelativeRect.fromLTRB(- MediaQuery.of(context).size.width,- kToolbarHeight + 12,- 12,- 0,- ),- items: [- PopupMenuItem(- value: false,- child: Text(context.strings.sortNewestFirst),- ),- PopupMenuItem(- value: true,- child: Text(context.strings.sortOldestFirst),- ),- ],+ final collection = widget.collection!;+ final sortByAsc = await showAlbumSortSheet(+ bContext,+ ascending: collection.pubMagicMetadata.asc ?? false,);- if (sortByAsc != null) {- if (!bContext.mounted) return;- unawaited(changeSortOrder(bContext, widget.collection!, sortByAsc));+ if (sortByAsc != null &&+ sortByAsc != (collection.pubMagicMetadata.asc ?? false) &&+ bContext.mounted) {+ await changeSortOrder(bContext, collection, sortByAsc);}}diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dartindex 12bef574d2..dc15dd6144 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_actions_sheet.dart@@ -43,7 +43,12 @@ Future<T?> showAlbumActionsSheet<T>(: 2;final tiles = [...options- .where((option) => option.labelColor == null)+ .where(+ (option) =>+ option.labelColor == null &&+ option.secondaryLabel == null &&+ option.trailingWidget == null,+ ).take(criticalIndex == -1 ? columns : columns - 1),if (criticalIndex != -1) options[criticalIndex],];@@ -305,6 +310,24 @@ class _AlbumActionRow<T> extends StatelessWidget {),),),+ if (option.secondaryLabel != null)+ Expanded(+ child: Text(+ option.secondaryLabel!,+ textAlign: TextAlign.end,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: TextStyles.mini.copyWith(color: colors.textLight),+ ),+ ),+ if (option.trailingWidget != null)+ IconTheme.merge(+ data: IconThemeData(+ color: colors.textLight,+ size: IconSizes.small,+ ),+ child: option.trailingWidget!,+ ),],),),diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_sort_sheet.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_sort_sheet.dartnew file mode 100644index 0000000000..1b117ef0fd--- /dev/null+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/album_sort_sheet.dart@@ -0,0 +1,36 @@+import "package:ente_components/ente_components.dart";+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:photos/ui/components/collection_share_badge.dart";++Future<bool?> showAlbumSortSheet(+ BuildContext context, {+ required bool ascending,+}) {+ return showBottomSheetComponent<bool>(+ context: context,+ builder: (sheetContext) => SingleChildScrollView(+ child: BottomSheetComponent(+ title: sheetContext.strings.sortPhotos,+ closeTooltip: sheetContext.strings.close,+ content: MenuGroupComponent(+ items: [+ for (final value in [false, true])+ Semantics(+ selected: value == ascending,+ child: MenuComponent(+ title: value+ ? sheetContext.strings.sortOldestFirst+ : sheetContext.strings.sortNewestFirst,+ trailing: value == ascending+ ? const CollectionSelectedBadge()+ : null,+ onTap: () => Navigator.of(sheetContext).pop(value),+ ),+ ),+ ],+ ),+ ),+ ),+ );+}diff --git a/mobile/apps/photos/test/ui/viewer/gallery/album_sort_sheet_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/album_sort_sheet_test.dartnew file mode 100644index 0000000000..c1a95f8e7f--- /dev/null+++ b/mobile/apps/photos/test/ui/viewer/gallery/album_sort_sheet_test.dart@@ -0,0 +1,90 @@+import "package:ente_components/ente_components.dart";+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/ente_theme_data.dart";+import "package:photos/ui/viewer/gallery/hooks/album_sort_sheet.dart";++void main() {+ testWidgets("shows the saved order and returns the selected order", (+ tester,+ ) async {+ for (final ascending in [false, true]) {+ bool? selected;+ await _pumpLauncher(+ tester,+ ascending: ascending,+ onSelected: (value) => selected = value,+ );+ await tester.tap(find.text("Sort"));+ await tester.pumpAndSettle();+ final currentOrder = ascending ? "Oldest first" : "Newest first";+ expect(find.text("Sort photos"), findsOneWidget);+ final choices = tester.widgetList<MenuComponent>(+ find.byType(MenuComponent),+ );+ expect(+ choices.singleWhere((choice) => choice.trailing != null).title,+ currentOrder,+ );+ await tester.tap(find.text(ascending ? "Newest first" : "Oldest first"));+ await tester.pumpAndSettle();+ expect(selected, !ascending);+ expect(find.byType(BottomSheetComponent), findsNothing);+ }+ });++ testWidgets("keeps sorting reachable in dark landscape with large text", (+ tester,+ ) async {+ tester.view.physicalSize = const Size(667, 240);+ tester.view.devicePixelRatio = 1;+ tester.platformDispatcher.textScaleFactorTestValue = 2;+ addTearDown(tester.view.reset);+ addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);+ bool? selected;+ await _pumpLauncher(+ tester,+ dark: true,+ onSelected: (value) => selected = value,+ );+ await tester.tap(find.text("Sort"));+ await tester.pumpAndSettle();+ await tester.ensureVisible(find.text("Oldest first"));+ await tester.tap(find.text("Oldest first"));+ await tester.pumpAndSettle();+ expect(tester.takeException(), isNull);+ expect(selected, isTrue);+ });+}++Future<void> _pumpLauncher(+ WidgetTester tester, {+ bool ascending = false,+ bool dark = false,+ required ValueChanged<bool> onSelected,+}) {+ return tester.pumpWidget(+ MaterialApp(+ theme: (dark ? darkThemeData : lightThemeData).copyWith(+ platform: dark ? TargetPlatform.iOS : TargetPlatform.android,+ ),+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ home: Scaffold(+ body: Builder(+ builder: (context) => TextButton(+ onPressed: () async {+ final selection = await showAlbumSortSheet(+ context,+ ascending: ascending,+ );+ if (selection != null) onSelected(selection);+ },+ child: Text(context.strings.sort),+ ),+ ),+ ),+ ),+ );+}diff --git a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dartindex df467f5a55..733c343635 100644--- a/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart+++ b/mobile/apps/photos/test/ui/viewer/gallery/collection_page_cover_test.dart@@ -188,7 +188,16 @@ void main() {.widget<GalleryAppBarWidget>(find.byType(GalleryAppBarWidget)).selectedFiles;expect(find.byType(AlbumCoverActionButton), findsNWidgets(2));- expect(find.byTooltip("Sort"), findsOneWidget);+ expect(find.byTooltip("Sort"), findsNothing);+ await tester.tap(find.byTooltip("More"));+ await tester.pumpAndSettle();+ expect(find.text("Newest first"), findsOneWidget);+ await tester.tap(find.text("Sort"));+ await tester.pumpAndSettle();+ expect(find.text("Sort photos"), findsOneWidget);+ await tester.tap(find.text("Newest first"));+ await tester.pumpAndSettle();+ expect(find.byType(BottomSheetComponent), findsNothing);selectedFiles.toggleSelection(newest);await tester.pumpAndSettle();expect(find.byType(AlbumCoverActionButton), findsNothing);@@ -237,7 +246,7 @@ void main() {MediaQuery.paddingOf(tester.element(find.byType(Gallery))).bottom,);expect(find.byType(AlbumCoverActionButton), findsNWidgets(2));- expect(find.byTooltip("Sort"), findsOneWidget);+ expect(find.byTooltip("Sort"), findsNothing);collection.pubMagicMetadata = CollectionPubMagicMetadata(asc: true);Bus.instance.fire(@@ -245,6 +254,11 @@ void main() {);await _expectCover(tester, oldest, count: 2);expect(find.text("1β3 JAN 2026"), findsOneWidget);+ await tester.tap(find.byTooltip("More"));+ await tester.pumpAndSettle();+ expect(find.text("Oldest first"), findsOneWidget);+ Navigator.of(tester.element(find.byType(CollectionPage))).pop();+ await tester.pumpAndSettle();final middle = _file(2);await tester.runAsync(() => FilesDB.instance.insertMultiple([middle]));@@ -393,6 +407,14 @@ void main() {AlbumPopupAction.albumSlideshow,]),);+ final sortSelection = Future.sync(+ () => menu.onSelected(AlbumPopupAction.sort),+ );+ await tester.pumpAndSettle();+ expect(find.text("Sort photos"), findsOneWidget);+ await tester.tap(find.text("Newest first"));+ await tester.pumpAndSettle();+ await sortSelection;await _disposeAlbum(tester);selectedFiles.dispose();},diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex 945b9da070..6892fe3c7a 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -4257,6 +4257,7 @@"sortAToZ": "A-Z","sortNewestFirst": "Newest first","sortOldestFirst": "Oldest first",+ "sortPhotos": "Sort photos","sortZToA": "Z-A","speed": "Speed","sportsAction": "Game on",