123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:page_transition/page_transition.dart';
- import 'package:photos/core/configuration.dart';
- import 'package:photos/models/collection.dart';
- import 'package:photos/models/device_collection.dart';
- import 'package:photos/models/gallery_type.dart';
- import 'package:photos/models/magic_metadata.dart';
- import 'package:photos/models/selected_file_breakup.dart';
- import 'package:photos/models/selected_files.dart';
- import 'package:photos/services/collections_service.dart';
- import 'package:photos/services/hidden_service.dart';
- import 'package:photos/theme/ente_theme.dart';
- import 'package:photos/ui/actions/collection/collection_file_actions.dart';
- import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
- import 'package:photos/ui/components/blur_menu_item_widget.dart';
- import 'package:photos/ui/components/bottom_action_bar/expanded_menu_widget.dart';
- import 'package:photos/ui/create_collection_page.dart';
- import 'package:photos/utils/delete_file_util.dart';
- import 'package:photos/utils/magic_util.dart';
- class FileSelectionActionWidget extends StatefulWidget {
- final GalleryType type;
- final Collection? collection;
- final DeviceCollection? deviceCollection;
- final SelectedFiles selectedFiles;
- const FileSelectionActionWidget(
- this.type,
- this.selectedFiles, {
- Key? key,
- this.collection,
- this.deviceCollection,
- }) : super(key: key);
- @override
- State<FileSelectionActionWidget> createState() =>
- _FileSelectionActionWidgetState();
- }
- class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
- late int currentUserID;
- late SelectedFileSplit split;
- late CollectionActions collectionActions;
- @override
- void initState() {
- currentUserID = Configuration.instance.getUserID()!;
- split = widget.selectedFiles.split(currentUserID);
- widget.selectedFiles.addListener(_selectFileChangeListener);
- collectionActions = CollectionActions(CollectionsService.instance);
- super.initState();
- }
- @override
- void dispose() {
- widget.selectedFiles.removeListener(_selectFileChangeListener);
- super.dispose();
- }
- void _selectFileChangeListener() {
- split = widget.selectedFiles.split(currentUserID);
- if (mounted) {
- setState(() => {});
- }
- }
- @override
- Widget build(BuildContext context) {
- final bool showPrefix =
- split.pendingUploads.isNotEmpty || split.ownedByOtherUsers.isNotEmpty;
- final String suffix = showPrefix
- ? " (${split.ownedByCurrentUser.length})"
- ""
- : "";
- debugPrint('$runtimeType building $mounted');
- final colorScheme = getEnteColorScheme(context);
- final List<List<BlurMenuItemWidget>> items = [];
- final List<BlurMenuItemWidget> firstList = [];
- if (widget.type.showAddToAlbum()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.add_outlined,
- labelText: "Add to album$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _addToAlbum,
- ),
- );
- }
- if (widget.type.showMoveToAlbum()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.arrow_forward_outlined,
- labelText: "Move to album$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _moveFiles,
- ),
- );
- }
- if (widget.type.showRemoveFromAlbum()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.remove_outlined,
- labelText: "Remove from album$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _removeFilesFromAlbum,
- ),
- );
- }
- if (widget.type.showDeleteOption()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.delete_outline,
- labelText: "Delete$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _onDeleteClick,
- ),
- );
- }
- if (widget.type.showHideOption()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.visibility_off_outlined,
- labelText: "Hide$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _onHideClick,
- ),
- );
- } else if (widget.type.showUnHideOption()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.visibility_off_outlined,
- labelText: "Unhide$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _onUnhideClick,
- ),
- );
- }
- if (widget.type.showArchiveOption()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.archive_outlined,
- labelText: "Archive$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _onArchiveClick,
- ),
- );
- } else if (widget.type.showUnArchiveOption()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.unarchive_outlined,
- labelText: "Unarchive$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _onUnArchiveClick,
- ),
- );
- }
- if (widget.type.showFavoriteOption()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.favorite_border_rounded,
- labelText: "Favorite$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _onFavoriteClick,
- ),
- );
- } else if (widget.type.showUnFavoriteOption()) {
- firstList.add(
- BlurMenuItemWidget(
- leadingIcon: Icons.favorite,
- labelText: "Remove from favorite$suffix",
- menuItemColor: colorScheme.fillFaint,
- onTap: _onUnFavoriteClick,
- ),
- );
- }
- if (firstList.isNotEmpty) {
- items.add(firstList);
- }
- return ExpandedMenuWidget(
- items: items,
- );
- }
- Future<void> _moveFiles() async {
- if (split.pendingUploads.isNotEmpty || split.ownedByOtherUsers.isNotEmpty) {
- widget.selectedFiles
- .unSelectAll(split.pendingUploads.toSet(), skipNotify: true);
- widget.selectedFiles
- .unSelectAll(split.ownedByOtherUsers.toSet(), skipNotify: true);
- }
- await _selectionCollectionForAction(CollectionActionType.moveFiles);
- }
- Future<void> _addToAlbum() async {
- if (split.ownedByOtherUsers.isNotEmpty) {
- widget.selectedFiles
- .unSelectAll(split.ownedByOtherUsers.toSet(), skipNotify: true);
- }
- await _selectionCollectionForAction(CollectionActionType.addFiles);
- }
- Future<void> _onDeleteClick() async {
- showDeleteSheet(context, widget.selectedFiles);
- }
- Future<void> _removeFilesFromAlbum() async {
- await collectionActions.showRemoveFromCollectionSheet(
- context,
- widget.collection!,
- widget.selectedFiles,
- );
- }
- Future<void> _onFavoriteClick() async {
- final result = await collectionActions.updateFavorites(
- context,
- split.ownedByCurrentUser,
- true,
- );
- if (result) {
- widget.selectedFiles.clearAll();
- }
- }
- Future<void> _onUnFavoriteClick() async {
- final result = await collectionActions.updateFavorites(
- context,
- split.ownedByCurrentUser,
- false,
- );
- if (result) {
- widget.selectedFiles.clearAll();
- }
- }
- Future<void> _onArchiveClick() async {
- await changeVisibility(
- context,
- split.ownedByCurrentUser,
- visibilityArchive,
- );
- widget.selectedFiles.clearAll();
- }
- Future<void> _onUnArchiveClick() async {
- await changeVisibility(
- context,
- split.ownedByCurrentUser,
- visibilityVisible,
- );
- widget.selectedFiles.clearAll();
- }
- Future<void> _onHideClick() async {
- await CollectionsService.instance.hideFiles(
- context,
- split.ownedByCurrentUser,
- );
- widget.selectedFiles.clearAll();
- }
- Future<void> _onUnhideClick() async {
- if (split.pendingUploads.isNotEmpty || split.ownedByOtherUsers.isNotEmpty) {
- widget.selectedFiles
- .unSelectAll(split.pendingUploads.toSet(), skipNotify: true);
- widget.selectedFiles
- .unSelectAll(split.ownedByOtherUsers.toSet(), skipNotify: true);
- }
- await _selectionCollectionForAction(CollectionActionType.unHide);
- }
- Future<Object?> _selectionCollectionForAction(
- CollectionActionType type,
- ) async {
- return Navigator.push(
- context,
- PageTransition(
- type: PageTransitionType.bottomToTop,
- child: CreateCollectionPage(
- widget.selectedFiles,
- null,
- actionType: type,
- ),
- ),
- );
- }
- }
|