ente/lib/ui/free_space_page.dart

158 lines
4.9 KiB
Dart
Raw Normal View History

2021-06-28 10:12:21 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
import 'package:photos/models/backup_status.dart';
import 'package:photos/ui/common_elements.dart';
import 'package:photos/utils/data_util.dart';
import 'package:photos/utils/delete_file_util.dart';
class FreeSpacePage extends StatefulWidget {
final BackupStatus status;
FreeSpacePage(this.status, {Key key}) : super(key: key);
2021-06-28 10:12:21 +00:00
@override
_FreeSpacePageState createState() => _FreeSpacePageState();
}
class _FreeSpacePageState extends State<FreeSpacePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Hero(
tag: "free_up_space",
child: Material(
type: MaterialType.transparency,
child: Text(
"free up space",
style: TextStyle(
fontSize: 18,
),
),
),
),
),
2021-06-28 11:20:48 +00:00
body: _getBody(),
2021-06-28 10:12:21 +00:00
);
}
Widget _getBody() {
Logger("FreeSpacePage").info("Number of uploaded files: " +
widget.status.localIDs.length.toString());
Logger("FreeSpacePage")
.info("Space consumed: " + widget.status.size.toString());
return _getWidget(widget.status);
2021-06-28 10:12:21 +00:00
}
Widget _getWidget(BackupStatus status) {
final count = status.localIDs.length;
final formattedCount = NumberFormat().format(count);
2022-03-05 20:52:00 +00:00
final informationTextStyle = TextStyle(
fontSize: 14,
height: 1.3,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
);
2021-06-28 10:12:21 +00:00
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/backed_up_gallery.png",
height: 160,
),
Padding(padding: EdgeInsets.all(24)),
Padding(
padding: const EdgeInsets.only(left: 36, right: 40),
child: Row(
children: [
Icon(
Icons.cloud_done_outlined,
color: Color.fromRGBO(45, 194, 98, 1.0),
),
Padding(padding: EdgeInsets.all(10)),
Expanded(
child: Text(
count == 1
? formattedCount.toString() +
2021-06-28 11:19:52 +00:00
" file on this device has been backed up safely"
2021-06-28 10:12:21 +00:00
: formattedCount.toString() +
2021-06-28 11:19:52 +00:00
" files on this device have been backed up safely",
2022-03-05 20:52:00 +00:00
style: informationTextStyle,
2021-06-28 10:12:21 +00:00
),
),
],
),
),
Padding(padding: EdgeInsets.all(12)),
Padding(
padding: const EdgeInsets.only(left: 36, right: 40),
child: Row(
children: [
Icon(
Icons.delete_outline,
color: Color.fromRGBO(45, 194, 98, 1.0),
),
Padding(padding: EdgeInsets.all(10)),
Expanded(
child: Text(
2021-06-28 14:35:43 +00:00
(count == 1 ? "it" : "they") +
2021-06-28 16:11:02 +00:00
" can be deleted from this device to free up " +
formatBytes(status.size),
2022-03-05 20:52:00 +00:00
style: informationTextStyle,
2021-06-28 10:12:21 +00:00
),
),
],
),
),
Padding(padding: EdgeInsets.all(12)),
Padding(
padding: const EdgeInsets.only(left: 36, right: 40),
child: Row(
children: [
Icon(
Icons.devices,
color: Color.fromRGBO(45, 194, 98, 1.0),
),
Padding(padding: EdgeInsets.all(10)),
Expanded(
child: Text(
2021-06-28 14:35:43 +00:00
"you can still access " +
(count == 1 ? "it" : "them") +
" on ente as long as you have an active subscription",
2022-03-05 20:52:00 +00:00
style: informationTextStyle,
2021-06-28 10:12:21 +00:00
),
),
],
),
),
Padding(padding: EdgeInsets.all(32)),
Container(
width: double.infinity,
2021-08-09 07:06:11 +00:00
constraints: BoxConstraints(
minHeight: 64,
),
2021-06-28 15:52:21 +00:00
padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
2021-06-28 10:12:21 +00:00
child: button(
2021-06-28 12:54:57 +00:00
"free up " + formatBytes(status.size),
2021-06-28 10:12:21 +00:00
onPressed: () async {
await _freeStorage(status);
2021-06-28 10:12:21 +00:00
},
fontSize: 18,
),
),
],
),
);
}
2021-06-28 11:19:52 +00:00
Future<void> _freeStorage(BackupStatus status) async {
2021-06-28 16:32:29 +00:00
final result = await deleteLocalFiles(context, status.localIDs);
if (result) {
Navigator.of(context).pop(true);
}
2021-06-28 11:19:52 +00:00
}
2021-06-28 10:12:21 +00:00
}