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

175 lines
5.3 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/magic_metadata.dart';
import 'package:photos/models/selected_files.dart';
2022-12-16 10:27:09 +00:00
import 'package:photos/theme/ente_theme.dart';
2023-02-14 10:32:56 +00:00
import 'package:photos/ui/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;
const FileSelectionOverlayBar(
this.galleryType,
this.selectedFiles, {
this.collection,
this.deviceCollection,
Key? key,
}) : super(key: key);
@override
State<FileSelectionOverlayBar> createState() =>
_FileSelectionOverlayBarState();
}
class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
final GlobalKey shareButtonKey = GlobalKey();
final ValueNotifier<double> _bottomPosition = ValueNotifier(-150.0);
late bool showDeleteOption;
@override
void initState() {
showDeleteOption = widget.galleryType.showDeleteIconOption();
widget.selectedFiles.addListener(_selectedFilesListener);
super.initState();
}
@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(),
)) {
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,
),
),
);
return ValueListenableBuilder(
valueListenable: _bottomPosition,
builder: (context, value, child) {
return AnimatedPositioned(
curve: Curves.easeInOutExpo,
bottom: _bottomPosition.value,
right: 0,
left: 0,
duration: const Duration(milliseconds: 400),
child: 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,
),
);
},
);
}
2022-12-16 07:36:43 +00:00
Future<void> _onUnArchiveClick() async {
await changeVisibility(
context,
widget.selectedFiles.files.toList(),
visibilityVisible,
);
widget.selectedFiles.clearAll();
}
_selectedFilesListener() {
widget.selectedFiles.files.isNotEmpty
? _bottomPosition.value = 0.0
: _bottomPosition.value = -150.0;
}
}