Pass sort property to gallery and it's children (#1150)

This commit is contained in:
Neeraj Gupta 2023-05-25 20:42:49 +05:30 committed by GitHub
commit a5bdd19482
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View file

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

View file

@ -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

View file

@ -21,6 +21,7 @@ class LazyLoadingGallery extends StatefulWidget {
final Stream<FilesUpdatedEvent>? reloadEvent;
final Set<EventType> 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<LazyLoadingGallery> {
final result = await widget.asyncLoader(
dayStartTime.microsecondsSinceEpoch,
dayStartTime.microsecondsSinceEpoch + microSecondsInDay - 1,
asc: widget.sortOrderAsc,
);
if (mounted) {
setState(() {

View file

@ -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<Gallery> {
);
}
}
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<Gallery> {
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<Gallery> {
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<Gallery> {
if (dailyFiles.isNotEmpty) {
collatedFiles.add(dailyFiles);
}
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;
}
}