2021-10-12 20:01:51 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:photos/core/event_bus.dart';
|
|
|
|
import 'package:photos/db/trash_db.dart';
|
2022-05-11 13:47:06 +00:00
|
|
|
import 'package:photos/ente_theme_data.dart';
|
2021-10-12 20:01:51 +00:00
|
|
|
import 'package:photos/events/files_updated_event.dart';
|
2021-10-28 11:17:00 +00:00
|
|
|
import 'package:photos/events/force_reload_trash_page_event.dart';
|
2022-05-08 04:34:55 +00:00
|
|
|
import 'package:photos/models/galleryType.dart';
|
2021-10-12 20:01:51 +00:00
|
|
|
import 'package:photos/models/selected_files.dart';
|
2022-05-11 09:22:43 +00:00
|
|
|
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';
|
2022-05-04 11:08:06 +00:00
|
|
|
import 'package:photos/ui/gallery_overlay_widget.dart';
|
2022-05-11 13:47:06 +00:00
|
|
|
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;
|
2022-05-08 04:34:55 +00:00
|
|
|
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: [
|
2021-10-28 11:17:00 +00:00
|
|
|
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,
|
2021-10-27 05:49:07 +00:00
|
|
|
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
|
|
|
),
|
2022-05-04 11:08:06 +00:00
|
|
|
body: Stack(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
children: [
|
|
|
|
gallery,
|
2022-05-11 09:22:43 +00:00
|
|
|
BottomShadowWidget(),
|
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(
|
|
|
|
minimum: EdgeInsets.only(bottom: 12),
|
|
|
|
child: BottomButtonsWidget()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-05-05 07:02:00 +00:00
|
|
|
GalleryOverlayWidget(
|
2022-05-12 04:58:11 +00:00
|
|
|
widget.overlayType,
|
|
|
|
widget._selectedFiles,
|
2022-05-04 11:08:06 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2021-10-12 20:01:51 +00:00
|
|
|
);
|
|
|
|
}
|
2021-10-27 05:49:07 +00:00
|
|
|
|
|
|
|
Widget _headerWidget() {
|
2022-05-04 02:37:17 +00:00
|
|
|
return FutureBuilder<int>(
|
|
|
|
future: TrashDB.instance.count(),
|
2021-10-27 06:03:51 +00:00
|
|
|
builder: (context, snapshot) {
|
2022-05-04 02:37:17 +00:00
|
|
|
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-27 05:49:07 +00:00
|
|
|
}
|
2021-10-12 20:01:51 +00:00
|
|
|
}
|
2022-05-11 13:47:06 +00:00
|
|
|
|
2022-05-12 04:58:11 +00:00
|
|
|
// class TrashPage extends StatelessWidget {
|
|
|
|
// final String tagPrefix;
|
|
|
|
// final GalleryType appBarType;
|
|
|
|
// final GalleryType overlayType;
|
|
|
|
// final _selectedFiles = SelectedFiles();
|
|
|
|
|
|
|
|
// TrashPage({
|
|
|
|
// this.tagPrefix = "trash_page",
|
|
|
|
// this.appBarType = GalleryType.trash,
|
|
|
|
// this.overlayType = GalleryType.trash,
|
|
|
|
// Key key,
|
|
|
|
// }) : super(key: key);
|
|
|
|
|
|
|
|
// @override
|
|
|
|
// Widget build(Object context) {
|
|
|
|
// final gallery = Gallery(
|
|
|
|
// 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>(),
|
|
|
|
// ],
|
|
|
|
// tagPrefix: tagPrefix,
|
|
|
|
// selectedFiles: _selectedFiles,
|
|
|
|
// header: _headerWidget(),
|
|
|
|
// initialFiles: null,
|
|
|
|
// );
|
|
|
|
|
|
|
|
// return Scaffold(
|
|
|
|
// appBar: PreferredSize(
|
|
|
|
// preferredSize: Size.fromHeight(50.0),
|
|
|
|
// child: GalleryAppBarWidget(
|
|
|
|
// appBarType,
|
|
|
|
// "Trash",
|
|
|
|
// _selectedFiles,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// body: Stack(
|
|
|
|
// alignment: Alignment.bottomCenter,
|
|
|
|
// children: [
|
|
|
|
// gallery,
|
|
|
|
// BottomShadowWidget(),
|
|
|
|
// BottomButtonsWidget(),
|
|
|
|
// GalleryOverlayWidget(
|
|
|
|
// overlayType,
|
|
|
|
// _selectedFiles,
|
|
|
|
// )
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Widget _headerWidget() {
|
|
|
|
// return FutureBuilder<int>(
|
|
|
|
// future: TrashDB.instance.count(),
|
|
|
|
// builder: (context, snapshot) {
|
|
|
|
// if (snapshot.hasData && snapshot.data > 0) {
|
|
|
|
// return Padding(
|
|
|
|
// padding: EdgeInsets.all(16),
|
|
|
|
// child: Text(
|
|
|
|
// 'Items show the number the days remaining before permanent deletion',
|
|
|
|
// style: Theme.of(context).textTheme.caption.copyWith(fontSize: 16),
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// } else {
|
|
|
|
// return Container();
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2022-05-11 13:47:06 +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(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
InkWell(
|
|
|
|
child: Container(
|
2022-05-11 13:47:06 +00:00
|
|
|
height: 40,
|
|
|
|
decoration: BoxDecoration(
|
2022-05-12 04:58:11 +00:00
|
|
|
color: Color.fromRGBO(255, 101, 101, 0.2),
|
2022-05-11 13:47:06 +00:00
|
|
|
borderRadius: BorderRadius.circular(24)),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
child: Center(
|
2022-05-12 04:58:11 +00:00
|
|
|
child: Text(
|
|
|
|
'Delete All',
|
|
|
|
style: Theme.of(context).textTheme.subtitle2.copyWith(
|
|
|
|
color: Color.fromRGBO(255, 101, 101, 1),
|
|
|
|
),
|
|
|
|
),
|
2022-05-11 13:47:06 +00:00
|
|
|
),
|
2022-05-12 04:58:11 +00:00
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
await emptyTrash(context);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
Container(
|
|
|
|
height: 40,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.defaultTextColor
|
|
|
|
.withOpacity(0.2),
|
|
|
|
borderRadius: BorderRadius.circular(24)),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
child: Center(
|
|
|
|
child: Text('Restore All',
|
|
|
|
style: Theme.of(context).textTheme.subtitle2),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2022-05-11 13:47:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|