ente/lib/ui/viewer/gallery/archive_page.dart

97 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:collection/collection.dart' show IterableExtension;
2021-09-17 04:44:10 +00:00
import 'package:flutter/material.dart';
import 'package:photos/core/configuration.dart';
2021-09-17 04:44:10 +00:00
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
import 'package:photos/events/files_updated_event.dart';
2023-04-07 05:06:43 +00:00
import "package:photos/generated/l10n.dart";
2022-07-03 10:09:01 +00:00
import 'package:photos/models/gallery_type.dart';
import "package:photos/models/metadata/common_keys.dart";
2021-09-17 04:44:10 +00:00
import 'package:photos/models/selected_files.dart';
import 'package:photos/services/collections_service.dart';
2023-06-06 14:43:41 +00:00
import "package:photos/ui/collections/album/horizontal_list.dart";
2022-12-16 07:27:29 +00:00
import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart';
import "package:photos/ui/viewer/gallery/empty_state.dart";
import 'package:photos/ui/viewer/gallery/gallery.dart';
import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
2021-09-17 04:44:10 +00:00
class ArchivePage extends StatelessWidget {
final String tagPrefix;
final GalleryType appBarType;
final GalleryType overlayType;
2021-09-17 04:44:10 +00:00
final _selectedFiles = SelectedFiles();
2022-06-11 08:23:52 +00:00
ArchivePage({
this.tagPrefix = "archived_page",
this.appBarType = GalleryType.archive,
this.overlayType = GalleryType.archive,
Key? key,
2022-06-11 08:23:52 +00:00
}) : super(key: key);
2021-09-17 04:44:10 +00:00
@override
2023-04-07 05:06:43 +00:00
Widget build(BuildContext context) {
final Set<int> hiddenCollectionIDs =
CollectionsService.instance.getHiddenCollections();
2021-09-17 04:44:10 +00:00
final gallery = Gallery(
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) {
return FilesDB.instance.getAllPendingOrUploadedFiles(
2022-06-11 08:23:52 +00:00
creationStartTime,
creationEndTime,
Configuration.instance.getUserID()!,
visibility: archiveVisibility,
2022-06-11 08:23:52 +00:00
limit: limit,
asc: asc,
ignoredCollectionIDs: hiddenCollectionIDs,
applyOwnerCheck: true,
2022-06-11 08:23:52 +00:00
);
2021-09-17 04:44:10 +00:00
},
2021-09-23 11:09:56 +00:00
reloadEvent: Bus.instance.on<FilesUpdatedEvent>().where(
(event) =>
event.updatedFiles.firstWhereOrNull(
2022-06-11 08:23:52 +00:00
(element) => element.uploadedFileID != null,
) !=
2021-09-23 11:09:56 +00:00
null,
),
removalEventTypes: const {EventType.unarchived},
2021-09-23 11:09:56 +00:00
forceReloadEvents: [
Bus.instance.on<FilesUpdatedEvent>().where(
(event) =>
event.updatedFiles.firstWhereOrNull(
2022-06-11 08:23:52 +00:00
(element) => element.uploadedFileID != null,
) !=
2021-09-23 11:09:56 +00:00
null,
),
],
2021-09-17 04:44:10 +00:00
tagPrefix: tagPrefix,
selectedFiles: _selectedFiles,
initialFiles: null,
2023-04-07 05:06:43 +00:00
emptyState: EmptyState(
text: S.of(context).youDontHaveAnyArchivedItems,
),
2023-06-06 14:43:41 +00:00
header: AlbumHorizontalList(
2023-04-20 10:20:49 +00:00
CollectionsService.instance.getArchivedCollectionWithThumb,
),
2021-09-17 04:44:10 +00:00
);
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(50.0),
child: GalleryAppBarWidget(
appBarType,
2023-04-07 05:06:43 +00:00
S.of(context).archive,
_selectedFiles,
2021-09-17 04:44:10 +00:00
),
),
body: Stack(
alignment: Alignment.bottomCenter,
children: [
gallery,
2022-12-16 07:27:29 +00:00
FileSelectionOverlayBar(
overlayType,
_selectedFiles,
2022-12-16 07:27:29 +00:00
),
],
),
2021-09-17 04:44:10 +00:00
);
}
}