2022-05-12 12:12:38 +00:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2022-12-30 12:10:17 +00:00
|
|
|
import 'package:collection/collection.dart' show IterableExtension;
|
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';
|
2021-10-28 11:17:00 +00:00
|
|
|
import 'package:photos/events/force_reload_trash_page_event.dart';
|
2022-07-03 10:09:01 +00:00
|
|
|
import 'package:photos/models/gallery_type.dart';
|
2021-10-12 20:01:51 +00:00
|
|
|
import 'package:photos/models/selected_files.dart';
|
2022-07-03 10:09:01 +00:00
|
|
|
import 'package:photos/ui/common/bottom_shadow.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/viewer/gallery/gallery.dart';
|
|
|
|
import 'package:photos/ui/viewer/gallery/gallery_app_bar_widget.dart';
|
|
|
|
import 'package:photos/ui/viewer/gallery/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-06-11 08:23:52 +00:00
|
|
|
TrashPage({
|
|
|
|
this.tagPrefix = "trash_page",
|
|
|
|
this.appBarType = GalleryType.trash,
|
|
|
|
this.overlayType = GalleryType.trash,
|
2022-12-30 12:10:17 +00:00
|
|
|
Key? key,
|
2022-06-11 08:23:52 +00:00
|
|
|
}) : 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> {
|
2022-12-30 12:10:17 +00:00
|
|
|
late Function() _selectedFilesListener;
|
2022-05-12 04:58:11 +00:00
|
|
|
@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-08-29 14:43:31 +00:00
|
|
|
final bool filesAreSelected = widget._selectedFiles.files.isNotEmpty;
|
2022-05-12 04:58:11 +00:00
|
|
|
|
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(
|
2022-06-11 08:23:52 +00:00
|
|
|
creationStartTime,
|
|
|
|
creationEndTime,
|
|
|
|
limit: limit,
|
|
|
|
asc: asc,
|
|
|
|
);
|
2021-10-26 13:26:30 +00:00
|
|
|
},
|
|
|
|
reloadEvent: Bus.instance.on<FilesUpdatedEvent>().where(
|
|
|
|
(event) =>
|
2022-12-30 12:10:17 +00:00
|
|
|
event.updatedFiles.firstWhereOrNull(
|
2022-06-11 08:23:52 +00:00
|
|
|
(element) => element.uploadedFileID != null,
|
|
|
|
) !=
|
2021-10-26 13:26:30 +00:00
|
|
|
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(
|
2022-07-04 06:02:17 +00:00
|
|
|
preferredSize: const Size.fromHeight(50.0),
|
2021-10-20 13:43:11 +00:00
|
|
|
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-07-04 06:02:17 +00:00
|
|
|
const BottomShadowWidget(
|
2022-05-12 12:12:38 +00:00
|
|
|
offsetDy: 20,
|
|
|
|
),
|
2022-05-12 04:58:11 +00:00
|
|
|
AnimatedContainer(
|
2022-07-04 06:02:17 +00:00
|
|
|
duration: const Duration(milliseconds: 300),
|
2022-05-12 04:58:11 +00:00
|
|
|
curve: Curves.easeInOut,
|
|
|
|
height: filesAreSelected ? 0 : 80,
|
|
|
|
child: AnimatedOpacity(
|
2022-07-04 06:02:17 +00:00
|
|
|
duration: const Duration(milliseconds: 100),
|
2022-05-12 04:58:11 +00:00
|
|
|
opacity: filesAreSelected ? 0.0 : 1.0,
|
|
|
|
curve: Curves.easeIn,
|
|
|
|
child: IgnorePointer(
|
|
|
|
ignoring: filesAreSelected,
|
2022-07-04 06:02:17 +00:00
|
|
|
child: const SafeArea(
|
2022-06-11 08:23:52 +00:00
|
|
|
minimum: EdgeInsets.only(bottom: 6),
|
|
|
|
child: BottomButtonsWidget(),
|
|
|
|
),
|
2022-05-12 04:58:11 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
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-12-30 12:10:17 +00:00
|
|
|
if (snapshot.hasData && snapshot.data! > 0) {
|
2021-10-27 06:03:51 +00:00
|
|
|
return Padding(
|
2022-07-04 06:02:17 +00:00
|
|
|
padding: const 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',
|
2023-01-07 12:45:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
class BottomButtonsWidget extends StatelessWidget {
|
2022-12-30 12:10:17 +00:00
|
|
|
const BottomButtonsWidget({Key? key}) : super(key: key);
|
2022-05-11 13:47:06 +00:00
|
|
|
|
|
|
|
@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,
|
2022-07-04 06:02:17 +00:00
|
|
|
decoration: const BoxDecoration(
|
2022-05-12 12:12:38 +00:00
|
|
|
color: Color.fromRGBO(255, 101, 101, 0.2),
|
|
|
|
),
|
|
|
|
child: Center(
|
2022-06-09 16:19:13 +00:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
2022-06-11 08:23:52 +00:00
|
|
|
vertical: 8.0,
|
|
|
|
horizontal: 16,
|
|
|
|
),
|
2022-06-09 16:19:13 +00:00
|
|
|
child: Text(
|
|
|
|
'Delete All',
|
2022-12-30 12:10:17 +00:00
|
|
|
style: Theme.of(context).textTheme.subtitle2!.copyWith(
|
2022-07-04 06:02:17 +00:00
|
|
|
color: const Color.fromRGBO(255, 101, 101, 1),
|
2022-06-09 16:19:13 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-12 12:12:38 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-12 04:58:11 +00:00
|
|
|
),
|
2022-05-11 13:47:06 +00:00
|
|
|
),
|
2022-05-12 12:12:38 +00:00
|
|
|
onTap: () async {
|
|
|
|
await emptyTrash(context);
|
|
|
|
},
|
2022-05-12 04:58:11 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-05-11 13:47:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|