ente/lib/ui/fading_bottom_bar.dart

211 lines
5.6 KiB
Dart
Raw Normal View History

import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/models/file.dart';
import 'package:photos/models/file_type.dart';
import 'package:photos/models/magic_metadata.dart';
import 'package:photos/models/trash_file.dart';
2021-07-06 23:43:39 +00:00
import 'package:photos/ui/file_info_dialog.dart';
import 'package:photos/utils/archive_util.dart';
import 'package:photos/utils/share_util.dart';
import 'package:photos/utils/toast_util.dart';
class FadingBottomBar extends StatefulWidget {
final File file;
final Function(File) onEditRequested;
2021-09-15 20:40:08 +00:00
final bool showOnlyInfoButton;
FadingBottomBar(
2021-07-11 08:01:47 +00:00
this.file,
2021-09-15 20:40:08 +00:00
this.onEditRequested,
this.showOnlyInfoButton, {
Key key,
}) : super(key: key);
@override
FadingBottomBarState createState() => FadingBottomBarState();
}
class FadingBottomBarState extends State<FadingBottomBar> {
bool _shouldHide = false;
@override
Widget build(BuildContext context) {
return _getBottomBar();
}
void hide() {
setState(() {
_shouldHide = true;
});
}
void show() {
setState(() {
_shouldHide = false;
});
}
void safeRefresh() {
if (mounted) {
setState(() {});
}
}
Widget _getBottomBar() {
List<Widget> children = [];
children.add(
2021-10-03 21:58:33 +00:00
Tooltip(
message: "info",
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(
Platform.isAndroid ? Icons.info_outline : CupertinoIcons.info),
onPressed: () {
_displayInfo(widget.file);
},
),
),
),
);
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(
message: "edit",
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(Icons.tune_outlined),
onPressed: () {
widget.onEditRequested(widget.file);
},
),
2021-09-15 20:40:08 +00:00
),
),
);
}
if (widget.file.uploadedFileID != null &&
widget.file.ownerID == Configuration.instance.getUserID()) {
bool isArchived =
widget.file.magicMetadata.visibility == kVisibilityArchive;
children.add(
Tooltip(
message: isArchived ? "unarchive" : "archive",
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(
Platform.isAndroid
? (isArchived
? Icons.unarchive_outlined
: Icons.archive_outlined)
: (isArchived
? CupertinoIcons.archivebox_fill
: CupertinoIcons.archivebox)),
onPressed: () async {
await changeVisibility(
context,
[widget.file],
isArchived ? kVisibilityVisible : kVisibilityArchive,
);
safeRefresh();
},
2021-10-03 21:57:09 +00:00
),
),
),
);
}
children.add(
2021-10-03 21:58:33 +00:00
Tooltip(
message: "share",
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(Platform.isAndroid
? Icons.share_outlined
: CupertinoIcons.share),
onPressed: () {
share(context, [widget.file]);
},
),
),
),
);
}
return AnimatedOpacity(
child: Align(
2021-09-15 20:40:08 +00:00
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.5),
Colors.black.withOpacity(0.64),
],
stops: const [0, 0.8, 1],
),
),
2021-09-15 20:40:08 +00:00
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: children,
),
),
),
opacity: _shouldHide ? 0 : 1,
duration: Duration(milliseconds: 150),
);
}
void _addTrashOptions(List<Widget> children) {
children.add(
Tooltip(
message: "restore",
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(Icons.restore_outlined),
onPressed: () {
showToast("coming soon");
},
),
),
),
);
children.add(
Tooltip(
message: "delete",
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12),
child: IconButton(
icon: Icon(Icons.delete_forever_outlined),
onPressed: () {
showToast("coming soon");
},
),
),
),
);
}
Future<void> _displayInfo(File file) async {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
2021-07-07 01:01:14 +00:00
return FileInfoWidget(file);
},
);
}
}