ente/lib/ui/viewer/file/file_bottom_bar.dart

290 lines
9.4 KiB
Dart
Raw Normal View History

import 'dart:io';
import 'package:flutter/cupertino.dart';
2023-08-29 14:05:41 +00:00
import "package:flutter/foundation.dart";
import 'package:flutter/material.dart';
2023-08-29 22:30:04 +00:00
import "package:logging/logging.dart";
2023-04-07 05:41:42 +00:00
import "package:photos/generated/l10n.dart";
2023-08-25 04:39:30 +00:00
import 'package:photos/models/file/file.dart';
import 'package:photos/models/file/file_type.dart';
import 'package:photos/models/file/trash_file.dart';
import 'package:photos/models/selected_files.dart';
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/actions/file/file_actions.dart";
2023-06-06 09:57:17 +00:00
import 'package:photos/ui/collections/collection_action_sheet.dart';
import 'package:photos/utils/delete_file_util.dart';
import 'package:photos/utils/share_util.dart';
class FileBottomBar extends StatefulWidget {
2023-08-24 16:56:24 +00:00
final EnteFile file;
final Function(EnteFile) onEditRequested;
final Function(EnteFile) onFileRemoved;
2021-09-15 20:40:08 +00:00
final bool showOnlyInfoButton;
final int? userID;
final ValueNotifier<bool> enableFullScreenNotifier;
const FileBottomBar(
2021-07-11 08:01:47 +00:00
this.file,
2021-09-15 20:40:08 +00:00
this.onEditRequested,
this.showOnlyInfoButton, {
required this.onFileRemoved,
required this.enableFullScreenNotifier,
this.userID,
Key? key,
}) : super(key: key);
@override
FileBottomBarState createState() => FileBottomBarState();
}
class FileBottomBarState extends State<FileBottomBar> {
final GlobalKey shareButtonKey = GlobalKey();
@override
Widget build(BuildContext context) {
return _getBottomBar();
}
void safeRefresh() {
if (mounted) {
setState(() {});
}
}
Widget _getBottomBar() {
Logger("FileBottomBar")
.fine("building bottom bar ${widget.file.generatedID}");
2022-08-29 14:43:31 +00:00
final List<Widget> children = [];
final bool isOwnedByUser =
widget.file.ownerID == null || widget.file.ownerID == widget.userID;
2023-08-29 14:05:41 +00:00
if (kDebugMode) {
children.add(
Text(
widget.file.generatedID?.toString() ?? 'null',
2023-08-29 22:30:04 +00:00
style: const TextStyle(color: Colors.white),
2023-08-29 14:05:41 +00:00
),
);
}
children.add(
2021-10-03 21:58:33 +00:00
Tooltip(
2022-05-17 11:38:21 +00:00
message: "Info",
2021-10-03 21:58:33 +00:00
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(
Platform.isAndroid ? Icons.info_outline : CupertinoIcons.info,
color: Colors.white,
),
onPressed: () async {
2023-03-20 05:46:51 +00:00
await _displayDetails(widget.file);
safeRefresh(); //to instantly show the new caption if keypad is closed after pressing 'done' - here the caption will be updated before the bottom sheet is closed
await Future.delayed(
const Duration(milliseconds: 500),
); //Waiting for some time till the caption gets updated in db if the user closes the bottom sheet without pressing 'done'
safeRefresh();
2021-10-03 21:58:33 +00:00
},
),
),
),
);
if (widget.file is TrashFile) {
_addTrashOptions(children);
}
if (!widget.showOnlyInfoButton && widget.file is! TrashFile) {
2021-09-15 20:40:08 +00:00
if (widget.file.fileType == FileType.image ||
widget.file.fileType == FileType.livePhoto) {
children.add(
2021-10-03 21:58:33 +00:00
Tooltip(
2022-05-17 11:38:21 +00:00
message: "Edit",
2021-10-03 21:58:33 +00:00
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
2022-07-04 06:02:17 +00:00
icon: const Icon(
Icons.tune_outlined,
color: Colors.white,
),
2021-10-03 21:58:33 +00:00
onPressed: () {
widget.onEditRequested(widget.file);
},
),
2021-09-15 20:40:08 +00:00
),
),
);
}
if (isOwnedByUser) {
children.add(
Tooltip(
2023-04-07 05:41:42 +00:00
message: S.of(context).delete,
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(
Platform.isAndroid
? Icons.delete_outline
: CupertinoIcons.delete,
color: Colors.white,
),
onPressed: () async {
await _showSingleFileDeleteSheet(widget.file);
},
2021-10-03 21:57:09 +00:00
),
),
),
);
}
children.add(
2021-10-03 21:58:33 +00:00
Tooltip(
2023-04-07 05:41:42 +00:00
message: S.of(context).share,
2021-10-03 21:58:33 +00:00
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
key: shareButtonKey,
icon: Icon(
Platform.isAndroid
? Icons.share_outlined
: CupertinoIcons.share,
color: Colors.white,
),
2021-10-03 21:58:33 +00:00
onPressed: () {
share(context, [widget.file], shareButtonKey: shareButtonKey);
2021-10-03 21:58:33 +00:00
},
),
),
),
);
}
2022-08-29 14:43:31 +00:00
final safeAreaBottomPadding = MediaQuery.of(context).padding.bottom * .5;
return ValueListenableBuilder(
valueListenable: widget.enableFullScreenNotifier,
builder: (BuildContext context, bool isFullScreen, _) {
return IgnorePointer(
ignoring: isFullScreen,
child: AnimatedOpacity(
opacity: isFullScreen ? 0 : 1,
duration: const Duration(milliseconds: 150),
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.6),
Colors.black.withOpacity(0.72),
],
stops: const [0, 0.8, 1],
2022-11-05 04:41:21 +00:00
),
),
child: Padding(
padding: EdgeInsets.only(bottom: safeAreaBottomPadding),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
widget.file.caption?.isNotEmpty ?? false
? Padding(
padding: const EdgeInsets.fromLTRB(
16,
2023-09-27 05:58:01 +00:00
12,
16,
0,
),
child: GestureDetector(
onTap: () async {
await _displayDetails(widget.file);
await Future.delayed(
const Duration(milliseconds: 500),
); //Waiting for some time till the caption gets updated in db if the user closes the bottom sheet without pressing 'done'
safeRefresh();
},
child: Text(
widget.file.caption!,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: getEnteTextTheme(context)
2023-09-27 05:58:01 +00:00
.mini
.copyWith(color: textBaseDark),
textAlign: TextAlign.center,
),
),
)
: const SizedBox.shrink(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: children,
),
],
),
),
),
),
2021-09-15 20:40:08 +00:00
),
);
},
);
}
2023-08-24 16:56:24 +00:00
Future<void> _showSingleFileDeleteSheet(EnteFile file) async {
await showSingleFileDeleteSheet(
context,
file,
onFileRemoved: widget.onFileRemoved,
);
}
void _addTrashOptions(List<Widget> children) {
children.add(
Tooltip(
2023-04-07 05:41:42 +00:00
message: S.of(context).restore,
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
2022-07-04 06:02:17 +00:00
icon: const Icon(
Icons.restore_outlined,
color: Colors.white,
),
onPressed: () {
final selectedFiles = SelectedFiles();
selectedFiles.toggleSelection(widget.file);
2023-02-14 10:13:34 +00:00
showCollectionActionSheet(
2022-06-11 08:23:52 +00:00
context,
2023-02-14 10:13:34 +00:00
selectedFiles: selectedFiles,
2023-01-25 04:57:40 +00:00
actionType: CollectionActionType.restoreFiles,
2022-06-11 08:23:52 +00:00
);
},
),
),
),
);
children.add(
Tooltip(
2023-04-07 05:41:42 +00:00
message: S.of(context).delete,
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
2022-07-04 06:02:17 +00:00
icon: const Icon(
Icons.delete_forever_outlined,
color: Colors.white,
),
onPressed: () async {
final trashedFile = <TrashFile>[];
trashedFile.add(widget.file as TrashFile);
if (await deleteFromTrash(context, trashedFile) == true) {
Navigator.pop(context);
}
},
),
),
),
);
}
2023-08-24 16:56:24 +00:00
Future<void> _displayDetails(EnteFile file) async {
2023-03-20 05:46:51 +00:00
await showDetailsSheet(context, file);
}
}