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

127 lines
3.9 KiB
Dart
Raw Normal View History

// @dart=2.9
import 'package:flutter/material.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/files_db.dart';
import 'package:photos/events/collection_updated_event.dart';
import 'package:photos/events/files_updated_event.dart';
2021-05-13 18:05:32 +00:00
import 'package:photos/models/collection_items.dart';
import 'package:photos/models/file_load_result.dart';
2022-07-03 10:09:01 +00:00
import 'package:photos/models/gallery_type.dart';
import 'package:photos/models/selected_files.dart';
import 'package:photos/services/ignored_files_service.dart';
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';
class CollectionPage extends StatefulWidget {
2021-05-13 18:05:32 +00:00
final CollectionWithThumbnail c;
2020-11-02 14:38:59 +00:00
final String tagPrefix;
final GalleryType appBarType;
2022-11-21 06:04:39 +00:00
final bool hasVerifiedLock;
const CollectionPage(
2022-06-11 08:23:52 +00:00
this.c, {
this.tagPrefix = "collection",
2022-07-03 07:47:15 +00:00
this.appBarType = GalleryType.ownedCollection,
this.hasVerifiedLock = false,
2022-06-11 08:23:52 +00:00
Key key,
}) : super(key: key);
@override
State<CollectionPage> createState() => _CollectionPageState();
}
class _CollectionPageState extends State<CollectionPage> {
final _selectedFiles = SelectedFiles();
bool _isCollectionOwner = false;
final GlobalKey shareButtonKey = GlobalKey();
final ValueNotifier<double> _bottomPosition = ValueNotifier(-150.0);
@override
void initState() {
_selectedFiles.addListener(_selectedFilesListener);
_isCollectionOwner =
Configuration.instance.getUserID() == widget.c.collection.owner.id;
super.initState();
}
@override
void dispose() {
_selectedFiles.removeListener(_selectedFilesListener);
super.dispose();
}
@override
Widget build(Object context) {
if (widget.hasVerifiedLock == false && widget.c.collection.isHidden()) {
return const EmptyState();
}
final initialFiles =
widget.c.thumbnail != null ? [widget.c.thumbnail] : null;
final gallery = Gallery(
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {
final FileLoadResult result =
await FilesDB.instance.getFilesInCollection(
widget.c.collection.id,
2022-06-11 08:23:52 +00:00
creationStartTime,
creationEndTime,
limit: limit,
asc: asc,
);
// hide ignored files from home page UI
final ignoredIDs = await IgnoredFilesService.instance.ignoredIDs;
result.files.removeWhere(
(f) =>
f.uploadedFileID == null &&
IgnoredFilesService.instance.shouldSkipUpload(ignoredIDs, f),
);
return result;
},
reloadEvent: Bus.instance
.on<CollectionUpdatedEvent>()
.where((event) => event.collectionID == widget.c.collection.id),
removalEventTypes: const {
2021-10-29 23:56:27 +00:00
EventType.deletedFromRemote,
EventType.deletedFromEverywhere,
EventType.hide,
},
tagPrefix: widget.tagPrefix,
selectedFiles: _selectedFiles,
2021-05-13 18:05:32 +00:00
initialFiles: initialFiles,
albumName: widget.c.collection.name,
);
return Scaffold(
appBar: PreferredSize(
2022-07-04 06:02:17 +00:00
preferredSize: const Size.fromHeight(50.0),
child: GalleryAppBarWidget(
widget.appBarType,
widget.c.collection.name,
_selectedFiles,
collection: widget.c.collection,
),
),
body: Stack(
alignment: Alignment.bottomCenter,
children: [
gallery,
FileSelectionOverlayBar(
widget.appBarType,
_selectedFiles,
collection: widget.c.collection,
)
],
),
);
}
_selectedFilesListener() {
_selectedFiles.files.isNotEmpty
? _bottomPosition.value = 0.0
: _bottomPosition.value = -150.0;
}
}