ente/lib/ui/viewer/actions/file_selection_overlay_bar.dart

179 lines
5.6 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2023-04-07 03:59:23 +00:00
import "package:photos/generated/l10n.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/metadata/common_keys.dart";
import 'package:photos/models/selected_files.dart';
2022-12-16 10:27:09 +00:00
import 'package:photos/theme/ente_theme.dart';
2023-06-06 09:57:17 +00:00
import 'package:photos/ui/collections/collection_action_sheet.dart';
import 'package:photos/ui/components/bottom_action_bar/bottom_action_bar_widget.dart';
import 'package:photos/ui/components/buttons/icon_button_widget.dart';
import 'package:photos/ui/viewer/actions/file_selection_actions_widget.dart';
import 'package:photos/utils/delete_file_util.dart';
2022-12-16 07:36:43 +00:00
import 'package:photos/utils/magic_util.dart';
import 'package:photos/utils/share_util.dart';
class FileSelectionOverlayBar extends StatefulWidget {
final GalleryType galleryType;
final SelectedFiles selectedFiles;
final Collection? collection;
final DeviceCollection? deviceCollection;
final Color? backgroundColor;
const FileSelectionOverlayBar(
this.galleryType,
this.selectedFiles, {
this.collection,
this.deviceCollection,
this.backgroundColor,
Key? key,
}) : super(key: key);
@override
State<FileSelectionOverlayBar> createState() =>
_FileSelectionOverlayBarState();
}
class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
final GlobalKey shareButtonKey = GlobalKey();
final ValueNotifier<bool> _hasSelectedFilesNotifier = ValueNotifier(false);
late bool showDeleteOption;
@override
void initState() {
2023-06-24 16:18:03 +00:00
super.initState();
showDeleteOption = widget.galleryType.showDeleteIconOption();
widget.selectedFiles.addListener(_selectedFilesListener);
}
@override
void dispose() {
widget.selectedFiles.removeListener(_selectedFilesListener);
super.dispose();
}
@override
Widget build(BuildContext context) {
debugPrint(
2022-12-30 03:29:48 +00:00
'$runtimeType building with ${widget.selectedFiles.files.length}',
);
2022-12-16 08:12:37 +00:00
final List<IconButtonWidget> iconsButton = [];
2022-12-16 10:27:09 +00:00
final iconColor = getEnteColorScheme(context).blurStrokeBase;
2022-12-16 08:12:37 +00:00
if (showDeleteOption) {
iconsButton.add(
IconButtonWidget(
icon: Icons.delete_outlined,
iconButtonType: IconButtonType.primary,
2022-12-16 10:27:09 +00:00
iconColor: iconColor,
2022-12-16 08:12:37 +00:00
onTap: () => showDeleteSheet(context, widget.selectedFiles),
),
);
}
if (widget.galleryType.showUnArchiveOption()) {
iconsButton.add(
IconButtonWidget(
icon: Icons.unarchive,
iconButtonType: IconButtonType.primary,
2022-12-16 10:27:09 +00:00
iconColor: iconColor,
2022-12-16 08:12:37 +00:00
onTap: () => _onUnArchiveClick(),
),
);
}
if (widget.galleryType.showUnHideOption()) {
iconsButton.add(
IconButtonWidget(
icon: Icons.visibility_off_outlined,
iconButtonType: IconButtonType.primary,
2022-12-16 10:27:09 +00:00
iconColor: iconColor,
onTap: () {
2023-02-14 10:13:34 +00:00
showCollectionActionSheet(
context,
2023-02-14 10:13:34 +00:00
selectedFiles: widget.selectedFiles,
2023-01-25 04:57:40 +00:00
actionType: CollectionActionType.unHide,
);
},
2022-12-16 08:12:37 +00:00
),
);
}
2023-01-27 13:56:29 +00:00
if (widget.galleryType == GalleryType.trash) {
iconsButton.add(
IconButtonWidget(
icon: Icons.delete_forever_outlined,
iconButtonType: IconButtonType.primary,
iconColor: iconColor,
onTap: () async {
if (await deleteFromTrash(
context,
widget.selectedFiles.files.toList(),
2023-01-27 13:56:29 +00:00
)) {
widget.selectedFiles.clearAll();
}
},
),
);
}
2022-12-16 08:12:37 +00:00
iconsButton.add(
IconButtonWidget(
2022-12-19 04:40:00 +00:00
icon: Icons.adaptive.share_outlined,
2022-12-16 08:12:37 +00:00
iconButtonType: IconButtonType.primary,
2023-01-27 13:56:29 +00:00
iconColor: iconColor,
2022-12-16 08:12:37 +00:00
onTap: () => shareSelected(
context,
shareButtonKey,
widget.selectedFiles.files.toList(),
2022-12-16 08:12:37 +00:00
),
),
);
return ValueListenableBuilder(
valueListenable: _hasSelectedFilesNotifier,
builder: (context, value, child) {
return AnimatedCrossFade(
firstCurve: Curves.easeInOutExpo,
secondCurve: Curves.easeInOutExpo,
sizeCurve: Curves.easeInOutExpo,
crossFadeState: _hasSelectedFilesNotifier.value
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: const Duration(milliseconds: 400),
firstChild: BottomActionBarWidget(
selectedFiles: widget.selectedFiles,
hasSmallerBottomPadding: true,
type: widget.galleryType,
expandedMenu: FileSelectionActionWidget(
widget.galleryType,
widget.selectedFiles,
collection: widget.collection,
),
2023-04-07 03:59:23 +00:00
text: S
.of(context)
.itemSelectedCount(widget.selectedFiles.files.length),
onCancel: () {
if (widget.selectedFiles.files.isNotEmpty) {
widget.selectedFiles.clearAll();
}
},
2022-12-16 08:12:37 +00:00
iconButtons: iconsButton,
backgroundColor: widget.backgroundColor,
),
secondChild: const SizedBox(width: double.infinity),
);
},
);
}
2022-12-16 07:36:43 +00:00
Future<void> _onUnArchiveClick() async {
await changeVisibility(
context,
widget.selectedFiles.files.toList(),
visibleVisibility,
2022-12-16 07:36:43 +00:00
);
widget.selectedFiles.clearAll();
}
_selectedFilesListener() {
_hasSelectedFilesNotifier.value = widget.selectedFiles.files.isNotEmpty;
}
}