diff --git a/lib/ui/viewer/gallery/collection_page.dart b/lib/ui/viewer/gallery/collection_page.dart index 3903fb043..5cc0dd314 100644 --- a/lib/ui/viewer/gallery/collection_page.dart +++ b/lib/ui/viewer/gallery/collection_page.dart @@ -74,6 +74,7 @@ class CollectionPage extends StatelessWidget { selectedFiles: _selectedFiles, initialFiles: initialFiles, albumName: c.collection.name, + sortOrderAsc: false, ); return Scaffold( appBar: PreferredSize( diff --git a/lib/ui/viewer/gallery/component/gallery_list_view_widget.dart b/lib/ui/viewer/gallery/component/gallery_list_view_widget.dart index 75f6f2624..22b9eb861 100644 --- a/lib/ui/viewer/gallery/component/gallery_list_view_widget.dart +++ b/lib/ui/viewer/gallery/component/gallery_list_view_widget.dart @@ -31,6 +31,7 @@ class GalleryListView extends StatelessWidget { final bool shouldCollateFilesByDay; final String logTag; final Logger logger; + final bool sortOrderAsc; const GalleryListView({ required this.hugeListViewKey, @@ -50,6 +51,7 @@ class GalleryListView extends StatelessWidget { required this.shouldCollateFilesByDay, required this.logTag, required this.logger, + required this.sortOrderAsc, super.key, }); @@ -91,6 +93,7 @@ class GalleryListView extends StatelessWidget { reloadEvent, removalEventTypes, asyncLoader, + sortOrderAsc, selectedFiles, tagPrefix, Bus.instance diff --git a/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart b/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart index ecd46e4f0..f4490a00c 100644 --- a/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart +++ b/lib/ui/viewer/gallery/component/lazy_loading_gallery.dart @@ -21,6 +21,7 @@ class LazyLoadingGallery extends StatefulWidget { final Stream? reloadEvent; final Set removalEventTypes; final GalleryLoader asyncLoader; + final bool sortOrderAsc; final SelectedFiles? selectedFiles; final String tag; final String? logTag; @@ -34,6 +35,7 @@ class LazyLoadingGallery extends StatefulWidget { this.reloadEvent, this.removalEventTypes, this.asyncLoader, + this.sortOrderAsc, this.selectedFiles, this.tag, this.currentIndexStream, @@ -112,6 +114,7 @@ class _LazyLoadingGalleryState extends State { final result = await widget.asyncLoader( dayStartTime.microsecondsSinceEpoch, dayStartTime.microsecondsSinceEpoch + microSecondsInDay - 1, + asc: widget.sortOrderAsc, ); if (mounted) { setState(() { diff --git a/lib/ui/viewer/gallery/gallery.dart b/lib/ui/viewer/gallery/gallery.dart index 6db8fe777..403146a32 100644 --- a/lib/ui/viewer/gallery/gallery.dart +++ b/lib/ui/viewer/gallery/gallery.dart @@ -42,6 +42,7 @@ class Gallery extends StatefulWidget { final Widget loadingWidget; final bool disableScroll; final bool limitSelectionToOne; + final bool sortOrderAsc; const Gallery({ required this.asyncLoader, @@ -60,6 +61,7 @@ class Gallery extends StatefulWidget { this.loadingWidget = const EnteLoadingWidget(), this.disableScroll = false, this.limitSelectionToOne = false, + this.sortOrderAsc = false, Key? key, }) : super(key: key); @@ -126,7 +128,7 @@ class _GalleryState extends State { ); } } - if (widget.initialFiles != null) { + if (widget.initialFiles != null && !widget.sortOrderAsc) { _onFilesLoaded(widget.initialFiles!); } _loadFiles(limit: kInitialLoadLimit).then((result) async { @@ -154,6 +156,7 @@ class _GalleryState extends State { galleryLoadStartTime, galleryLoadEndTime, limit: limit, + asc: widget.sortOrderAsc, ); final endTime = DateTime.now().microsecondsSinceEpoch; final duration = Duration(microseconds: endTime - startTime); @@ -213,6 +216,7 @@ class _GalleryState extends State { disableScroll: widget.disableScroll, emptyState: widget.emptyState, asyncLoader: widget.asyncLoader, + sortOrderAsc: widget.sortOrderAsc, removalEventTypes: widget.removalEventTypes, tagPrefix: widget.tagPrefix, scrollBottomSafeArea: widget.scrollBottomSafeArea, @@ -244,8 +248,13 @@ class _GalleryState extends State { if (dailyFiles.isNotEmpty) { collatedFiles.add(dailyFiles); } - collatedFiles - .sort((a, b) => b[0].creationTime!.compareTo(a[0].creationTime!)); + if (widget.sortOrderAsc) { + collatedFiles + .sort((a, b) => a[0].creationTime!.compareTo(b[0].creationTime!)); + } else { + collatedFiles + .sort((a, b) => b[0].creationTime!.compareTo(a[0].creationTime!)); + } return collatedFiles; } }