2020-10-24 23:10:37 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-28 18:39:43 +00:00
|
|
|
import 'package:photos/core/configuration.dart';
|
2020-10-30 19:57:14 +00:00
|
|
|
import 'package:photos/core/event_bus.dart';
|
2020-10-24 23:10:37 +00:00
|
|
|
import 'package:photos/db/files_db.dart';
|
2023-05-26 04:35:19 +00:00
|
|
|
import "package:photos/events/collection_meta_event.dart";
|
2020-10-30 19:57:14 +00:00
|
|
|
import 'package:photos/events/collection_updated_event.dart';
|
2021-10-29 23:55:29 +00:00
|
|
|
import 'package:photos/events/files_updated_event.dart';
|
2023-01-12 05:33:01 +00:00
|
|
|
import 'package:photos/models/collection.dart';
|
2021-05-13 18:05:32 +00:00
|
|
|
import 'package:photos/models/collection_items.dart';
|
2022-12-30 18:24:25 +00:00
|
|
|
import 'package:photos/models/file.dart';
|
2022-09-12 09:58:52 +00:00
|
|
|
import 'package:photos/models/file_load_result.dart';
|
2022-07-03 10:09:01 +00:00
|
|
|
import 'package:photos/models/gallery_type.dart';
|
2020-10-24 23:10:37 +00:00
|
|
|
import 'package:photos/models/selected_files.dart';
|
2022-09-12 09:58:52 +00:00
|
|
|
import 'package:photos/services/ignored_files_service.dart';
|
2022-12-15 14:14:26 +00:00
|
|
|
import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart';
|
2023-07-03 06:48:16 +00:00
|
|
|
import "package:photos/ui/viewer/gallery/empty_album_state.dart";
|
2022-10-31 10:53:23 +00:00
|
|
|
import 'package:photos/ui/viewer/gallery/empty_state.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/viewer/gallery/gallery.dart';
|
|
|
|
import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
|
2020-10-24 23:10:37 +00:00
|
|
|
|
2023-02-22 05:46:13 +00:00
|
|
|
class CollectionPage extends StatelessWidget {
|
2021-05-13 18:05:32 +00:00
|
|
|
final CollectionWithThumbnail c;
|
2020-11-02 14:38:59 +00:00
|
|
|
final String tagPrefix;
|
2023-08-19 05:43:05 +00:00
|
|
|
final GalleryType appBarType;
|
2023-08-10 13:03:56 +00:00
|
|
|
final bool? hasVerifiedLock;
|
2020-10-24 23:10:37 +00:00
|
|
|
|
2023-02-22 05:46:13 +00:00
|
|
|
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,
|
2022-10-31 10:53:23 +00:00
|
|
|
this.hasVerifiedLock = false,
|
2022-12-30 12:10:17 +00:00
|
|
|
Key? key,
|
2022-06-11 08:23:52 +00:00
|
|
|
}) : super(key: key);
|
2020-10-24 23:10:37 +00:00
|
|
|
|
2022-11-29 14:33:40 +00:00
|
|
|
final _selectedFiles = SelectedFiles();
|
|
|
|
|
2022-12-15 14:14:26 +00:00
|
|
|
final GlobalKey shareButtonKey = GlobalKey();
|
2022-11-29 14:33:40 +00:00
|
|
|
|
2020-10-24 23:10:37 +00:00
|
|
|
@override
|
2023-06-28 07:45:17 +00:00
|
|
|
Widget build(BuildContext context) {
|
2023-02-22 05:46:13 +00:00
|
|
|
if (hasVerifiedLock == false && c.collection.isHidden()) {
|
2022-10-31 10:53:23 +00:00
|
|
|
return const EmptyState();
|
|
|
|
}
|
2023-01-28 18:39:43 +00:00
|
|
|
|
2023-06-12 11:01:57 +00:00
|
|
|
final galleryType = _getGalleryType(c.collection);
|
2022-12-30 18:24:25 +00:00
|
|
|
final List<File>? initialFiles =
|
2023-02-22 05:46:13 +00:00
|
|
|
c.thumbnail != null ? [c.thumbnail!] : null;
|
2021-05-02 11:19:05 +00:00
|
|
|
final gallery = Gallery(
|
2022-09-12 09:58:52 +00:00
|
|
|
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) async {
|
|
|
|
final FileLoadResult result =
|
|
|
|
await FilesDB.instance.getFilesInCollection(
|
2023-02-22 05:46:13 +00:00
|
|
|
c.collection.id,
|
2022-06-11 08:23:52 +00:00
|
|
|
creationStartTime,
|
|
|
|
creationEndTime,
|
|
|
|
limit: limit,
|
|
|
|
asc: asc,
|
|
|
|
);
|
2022-09-12 09:58:52 +00:00
|
|
|
// 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;
|
2021-05-02 11:19:05 +00:00
|
|
|
},
|
|
|
|
reloadEvent: Bus.instance
|
|
|
|
.on<CollectionUpdatedEvent>()
|
2023-02-22 05:46:13 +00:00
|
|
|
.where((event) => event.collectionID == c.collection.id),
|
2023-05-26 04:35:19 +00:00
|
|
|
forceReloadEvents: [
|
|
|
|
Bus.instance.on<CollectionMetaEvent>().where(
|
|
|
|
(event) =>
|
|
|
|
event.id == c.collection.id &&
|
|
|
|
event.type == CollectionMetaEventType.sortChanged,
|
|
|
|
)
|
|
|
|
],
|
2021-10-29 23:55:29 +00:00
|
|
|
removalEventTypes: const {
|
2021-10-29 23:56:27 +00:00
|
|
|
EventType.deletedFromRemote,
|
|
|
|
EventType.deletedFromEverywhere,
|
2022-11-03 08:09:05 +00:00
|
|
|
EventType.hide,
|
2021-10-29 23:55:29 +00:00
|
|
|
},
|
2023-02-22 05:46:13 +00:00
|
|
|
tagPrefix: tagPrefix,
|
2021-05-02 11:19:05 +00:00
|
|
|
selectedFiles: _selectedFiles,
|
2021-05-13 18:05:32 +00:00
|
|
|
initialFiles: initialFiles,
|
2023-05-23 04:56:48 +00:00
|
|
|
albumName: c.collection.displayName,
|
2023-05-26 04:34:32 +00:00
|
|
|
sortAsyncFn: () => c.collection.pubMagicMetadata.asc ?? false,
|
2023-06-12 11:01:57 +00:00
|
|
|
showSelectAllByDefault: galleryType != GalleryType.sharedCollection,
|
2023-06-28 07:45:17 +00:00
|
|
|
emptyState: galleryType == GalleryType.ownedCollection
|
2023-07-03 06:48:16 +00:00
|
|
|
? EmptyAlbumState(c.collection)
|
2023-06-28 07:45:17 +00:00
|
|
|
: const EmptyState(),
|
2021-05-02 11:19:05 +00:00
|
|
|
);
|
2020-10-24 23:10:37 +00:00
|
|
|
return Scaffold(
|
2021-10-12 07:24:18 +00:00
|
|
|
appBar: PreferredSize(
|
2022-07-04 06:02:17 +00:00
|
|
|
preferredSize: const Size.fromHeight(50.0),
|
2021-10-12 07:24:18 +00:00
|
|
|
child: GalleryAppBarWidget(
|
2023-06-12 11:01:57 +00:00
|
|
|
galleryType,
|
2023-05-23 04:56:48 +00:00
|
|
|
c.collection.displayName,
|
2021-10-12 07:24:18 +00:00
|
|
|
_selectedFiles,
|
2023-02-22 05:46:13 +00:00
|
|
|
collection: c.collection,
|
2021-05-02 11:19:05 +00:00
|
|
|
),
|
2021-10-12 07:24:18 +00:00
|
|
|
),
|
2022-05-04 11:08:06 +00:00
|
|
|
body: Stack(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
children: [
|
|
|
|
gallery,
|
2022-12-15 14:14:26 +00:00
|
|
|
FileSelectionOverlayBar(
|
2023-06-12 11:01:57 +00:00
|
|
|
galleryType,
|
2022-12-15 14:14:26 +00:00
|
|
|
_selectedFiles,
|
2023-02-22 05:46:13 +00:00
|
|
|
collection: c.collection,
|
2022-12-15 14:14:26 +00:00
|
|
|
)
|
2022-05-04 11:08:06 +00:00
|
|
|
],
|
|
|
|
),
|
2020-10-24 23:10:37 +00:00
|
|
|
);
|
|
|
|
}
|
2022-11-29 14:33:40 +00:00
|
|
|
|
2023-01-28 18:39:43 +00:00
|
|
|
GalleryType _getGalleryType(Collection c) {
|
|
|
|
final currentUserID = Configuration.instance.getUserID()!;
|
|
|
|
if (!c.isOwner(currentUserID)) {
|
|
|
|
return GalleryType.sharedCollection;
|
|
|
|
}
|
|
|
|
if (c.isDefaultHidden()) {
|
|
|
|
return GalleryType.hidden;
|
|
|
|
} else if (c.type == CollectionType.uncategorized) {
|
|
|
|
return GalleryType.uncategorized;
|
|
|
|
} else if (c.type == CollectionType.favorites) {
|
|
|
|
return GalleryType.favorite;
|
2023-08-04 07:25:03 +00:00
|
|
|
} else if (c.isQuickLinkCollection()) {
|
2023-08-04 06:53:58 +00:00
|
|
|
return GalleryType.quickLink;
|
2023-01-28 18:39:43 +00:00
|
|
|
}
|
2023-08-19 05:43:05 +00:00
|
|
|
return appBarType;
|
2022-11-29 14:33:40 +00:00
|
|
|
}
|
2020-10-24 23:10:37 +00:00
|
|
|
}
|