ente/lib/ui/trash_page.dart

175 lines
5.1 KiB
Dart
Raw Normal View History

2022-05-12 12:12:38 +00:00
import 'dart:ui';
2021-10-12 20:01:51 +00:00
import 'package:flutter/material.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/db/trash_db.dart';
import 'package:photos/events/files_updated_event.dart';
import 'package:photos/events/force_reload_trash_page_event.dart';
import 'package:photos/models/galleryType.dart';
2021-10-12 20:01:51 +00:00
import 'package:photos/models/selected_files.dart';
import 'package:photos/ui/common/bottomShadow.dart';
2021-10-30 05:51:23 +00:00
import 'package:photos/ui/gallery.dart';
import 'package:photos/ui/gallery_app_bar_widget.dart';
import 'package:photos/ui/gallery_overlay_widget.dart';
import 'package:photos/utils/delete_file_util.dart';
2021-10-12 20:01:51 +00:00
2022-05-12 04:58:11 +00:00
class TrashPage extends StatefulWidget {
2021-10-12 20:01:51 +00:00
final String tagPrefix;
final GalleryType appBarType;
final GalleryType overlayType;
2021-10-12 20:01:51 +00:00
final _selectedFiles = SelectedFiles();
2022-05-12 04:58:11 +00:00
TrashPage(
{this.tagPrefix = "trash_page",
this.appBarType = GalleryType.trash,
this.overlayType = GalleryType.trash,
Key key})
: super(key: key);
2021-10-12 20:01:51 +00:00
2022-05-12 04:58:11 +00:00
@override
State<TrashPage> createState() => _TrashPageState();
}
class _TrashPageState extends State<TrashPage> {
Function() _selectedFilesListener;
@override
void initState() {
_selectedFilesListener = () {
setState(() {});
};
widget._selectedFiles.addListener(_selectedFilesListener);
super.initState();
}
@override
void dispose() {
widget._selectedFiles.removeListener(_selectedFilesListener);
super.dispose();
}
2021-10-12 20:01:51 +00:00
@override
Widget build(Object context) {
2022-05-12 04:58:11 +00:00
bool filesAreSelected = widget._selectedFiles.files.isNotEmpty;
2021-10-12 20:01:51 +00:00
final gallery = Gallery(
2021-10-26 13:26:30 +00:00
asyncLoader: (creationStartTime, creationEndTime, {limit, asc}) {
return TrashDB.instance.getTrashedFiles(
creationStartTime, creationEndTime,
limit: limit, asc: asc);
},
reloadEvent: Bus.instance.on<FilesUpdatedEvent>().where(
(event) =>
event.updatedFiles.firstWhere(
(element) => element.uploadedFileID != null,
orElse: () => null) !=
null,
),
forceReloadEvents: [
Bus.instance.on<ForceReloadTrashPageEvent>(),
2021-10-26 13:26:30 +00:00
],
2022-05-12 04:58:11 +00:00
tagPrefix: widget.tagPrefix,
selectedFiles: widget._selectedFiles,
header: _headerWidget(),
2021-10-26 13:26:30 +00:00
initialFiles: null,
);
2021-10-20 13:43:11 +00:00
2021-10-12 20:01:51 +00:00
return Scaffold(
2021-10-20 13:43:11 +00:00
appBar: PreferredSize(
preferredSize: Size.fromHeight(50.0),
child: GalleryAppBarWidget(
2022-05-12 04:58:11 +00:00
widget.appBarType,
2022-05-03 10:17:13 +00:00
"Trash",
2022-05-12 04:58:11 +00:00
widget._selectedFiles,
2021-10-12 20:01:51 +00:00
),
2021-10-20 13:43:11 +00:00
),
body: Stack(
alignment: Alignment.bottomCenter,
children: [
gallery,
2022-05-12 12:12:38 +00:00
BottomShadowWidget(
offsetDy: 20,
),
2022-05-12 04:58:11 +00:00
AnimatedContainer(
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut,
height: filesAreSelected ? 0 : 80,
child: AnimatedOpacity(
duration: Duration(milliseconds: 100),
opacity: filesAreSelected ? 0.0 : 1.0,
curve: Curves.easeIn,
child: IgnorePointer(
ignoring: filesAreSelected,
child: SafeArea(
2022-05-12 12:12:38 +00:00
minimum: EdgeInsets.only(bottom: 6),
2022-05-12 04:58:11 +00:00
child: BottomButtonsWidget()),
),
),
),
GalleryOverlayWidget(
2022-05-12 04:58:11 +00:00
widget.overlayType,
widget._selectedFiles,
)
],
),
2021-10-12 20:01:51 +00:00
);
}
Widget _headerWidget() {
return FutureBuilder<int>(
future: TrashDB.instance.count(),
2021-10-27 06:03:51 +00:00
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data > 0) {
2021-10-27 06:03:51 +00:00
return Padding(
2021-10-27 06:05:22 +00:00
padding: EdgeInsets.all(16),
2021-10-27 06:03:51 +00:00
child: Text(
2022-05-03 10:17:13 +00:00
'Items show the number the days remaining before permanent deletion',
style: Theme.of(context).textTheme.caption.copyWith(fontSize: 16),
2021-10-27 06:03:51 +00:00
),
);
} else {
return Container();
}
},
);
}
2021-10-12 20:01:51 +00:00
}
class BottomButtonsWidget extends StatelessWidget {
const BottomButtonsWidget({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-05-12 04:58:11 +00:00
return Row(
2022-05-12 12:12:38 +00:00
crossAxisAlignment: CrossAxisAlignment.end,
2022-05-12 04:58:11 +00:00
mainAxisAlignment: MainAxisAlignment.center,
children: [
2022-05-12 12:12:38 +00:00
ClipRRect(
borderRadius: BorderRadius.circular(24),
child: InkWell(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
child: Container(
height: 40,
decoration: BoxDecoration(
color: Color.fromRGBO(255, 101, 101, 0.2),
),
padding: EdgeInsets.symmetric(horizontal: 24),
child: Center(
child: Text(
'Delete All',
style: Theme.of(context).textTheme.subtitle2.copyWith(
color: Color.fromRGBO(255, 101, 101, 1),
),
),
),
2022-05-12 04:58:11 +00:00
),
),
2022-05-12 12:12:38 +00:00
onTap: () async {
await emptyTrash(context);
},
2022-05-12 04:58:11 +00:00
),
),
],
);
}
}