Pass sort property to gallery

This commit is contained in:
Neeraj Gupta 2023-05-25 17:13:00 +05:30
parent 537b880281
commit e8594566b5
4 changed files with 19 additions and 3 deletions

View file

@ -74,6 +74,7 @@ class CollectionPage extends StatelessWidget {
selectedFiles: _selectedFiles, selectedFiles: _selectedFiles,
initialFiles: initialFiles, initialFiles: initialFiles,
albumName: c.collection.name, albumName: c.collection.name,
sortOrderAsc: false,
); );
return Scaffold( return Scaffold(
appBar: PreferredSize( appBar: PreferredSize(

View file

@ -31,6 +31,7 @@ class GalleryListView extends StatelessWidget {
final bool shouldCollateFilesByDay; final bool shouldCollateFilesByDay;
final String logTag; final String logTag;
final Logger logger; final Logger logger;
final bool sortOrderAsc;
const GalleryListView({ const GalleryListView({
required this.hugeListViewKey, required this.hugeListViewKey,
@ -50,6 +51,7 @@ class GalleryListView extends StatelessWidget {
required this.shouldCollateFilesByDay, required this.shouldCollateFilesByDay,
required this.logTag, required this.logTag,
required this.logger, required this.logger,
required this.sortOrderAsc,
super.key, super.key,
}); });
@ -91,6 +93,7 @@ class GalleryListView extends StatelessWidget {
reloadEvent, reloadEvent,
removalEventTypes, removalEventTypes,
asyncLoader, asyncLoader,
sortOrderAsc,
selectedFiles, selectedFiles,
tagPrefix, tagPrefix,
Bus.instance Bus.instance

View file

@ -21,6 +21,7 @@ class LazyLoadingGallery extends StatefulWidget {
final Stream<FilesUpdatedEvent>? reloadEvent; final Stream<FilesUpdatedEvent>? reloadEvent;
final Set<EventType> removalEventTypes; final Set<EventType> removalEventTypes;
final GalleryLoader asyncLoader; final GalleryLoader asyncLoader;
final bool sortOrderAsc;
final SelectedFiles? selectedFiles; final SelectedFiles? selectedFiles;
final String tag; final String tag;
final String? logTag; final String? logTag;
@ -34,6 +35,7 @@ class LazyLoadingGallery extends StatefulWidget {
this.reloadEvent, this.reloadEvent,
this.removalEventTypes, this.removalEventTypes,
this.asyncLoader, this.asyncLoader,
this.sortOrderAsc,
this.selectedFiles, this.selectedFiles,
this.tag, this.tag,
this.currentIndexStream, this.currentIndexStream,
@ -112,6 +114,7 @@ class _LazyLoadingGalleryState extends State<LazyLoadingGallery> {
final result = await widget.asyncLoader( final result = await widget.asyncLoader(
dayStartTime.microsecondsSinceEpoch, dayStartTime.microsecondsSinceEpoch,
dayStartTime.microsecondsSinceEpoch + microSecondsInDay - 1, dayStartTime.microsecondsSinceEpoch + microSecondsInDay - 1,
asc: widget.sortOrderAsc,
); );
if (mounted) { if (mounted) {
setState(() { setState(() {

View file

@ -42,6 +42,7 @@ class Gallery extends StatefulWidget {
final Widget loadingWidget; final Widget loadingWidget;
final bool disableScroll; final bool disableScroll;
final bool limitSelectionToOne; final bool limitSelectionToOne;
final bool sortOrderAsc;
const Gallery({ const Gallery({
required this.asyncLoader, required this.asyncLoader,
@ -60,6 +61,7 @@ class Gallery extends StatefulWidget {
this.loadingWidget = const EnteLoadingWidget(), this.loadingWidget = const EnteLoadingWidget(),
this.disableScroll = false, this.disableScroll = false,
this.limitSelectionToOne = false, this.limitSelectionToOne = false,
this.sortOrderAsc = false,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -126,7 +128,7 @@ class _GalleryState extends State<Gallery> {
); );
} }
} }
if (widget.initialFiles != null) { if (widget.initialFiles != null && !widget.sortOrderAsc) {
_onFilesLoaded(widget.initialFiles!); _onFilesLoaded(widget.initialFiles!);
} }
_loadFiles(limit: kInitialLoadLimit).then((result) async { _loadFiles(limit: kInitialLoadLimit).then((result) async {
@ -154,6 +156,7 @@ class _GalleryState extends State<Gallery> {
galleryLoadStartTime, galleryLoadStartTime,
galleryLoadEndTime, galleryLoadEndTime,
limit: limit, limit: limit,
asc: widget.sortOrderAsc,
); );
final endTime = DateTime.now().microsecondsSinceEpoch; final endTime = DateTime.now().microsecondsSinceEpoch;
final duration = Duration(microseconds: endTime - startTime); final duration = Duration(microseconds: endTime - startTime);
@ -213,6 +216,7 @@ class _GalleryState extends State<Gallery> {
disableScroll: widget.disableScroll, disableScroll: widget.disableScroll,
emptyState: widget.emptyState, emptyState: widget.emptyState,
asyncLoader: widget.asyncLoader, asyncLoader: widget.asyncLoader,
sortOrderAsc: widget.sortOrderAsc,
removalEventTypes: widget.removalEventTypes, removalEventTypes: widget.removalEventTypes,
tagPrefix: widget.tagPrefix, tagPrefix: widget.tagPrefix,
scrollBottomSafeArea: widget.scrollBottomSafeArea, scrollBottomSafeArea: widget.scrollBottomSafeArea,
@ -244,8 +248,13 @@ class _GalleryState extends State<Gallery> {
if (dailyFiles.isNotEmpty) { if (dailyFiles.isNotEmpty) {
collatedFiles.add(dailyFiles); collatedFiles.add(dailyFiles);
} }
collatedFiles if (widget.sortOrderAsc) {
.sort((a, b) => b[0].creationTime!.compareTo(a[0].creationTime!)); 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; return collatedFiles;
} }
} }