ente/lib/ui/free_space_page.dart

188 lines
5.8 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/services/sync_service.dart';
import 'package:photos/ui/common_elements.dart';
import 'package:photos/ui/loading_widget.dart';
import 'package:photos/utils/data_util.dart';
import 'package:photos/utils/delete_file_util.dart';
import 'package:photos/utils/dialog_util.dart';
class FreeSpacePage extends StatefulWidget {
FreeSpacePage({Key key}) : super(key: key);
@override
_FreeSpacePageState createState() => _FreeSpacePageState();
}
class _FreeSpacePageState extends State<FreeSpacePage> {
Future<BackupStatus> _future;
@override
void initState() {
super.initState();
_future = SyncService.instance.getBackupStatus();
}
@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() {
return FutureBuilder<BackupStatus>(
future: _future,
builder: (_, snapshot) {
if (snapshot.hasData) {
final status = snapshot.data;
Logger("FreeSpacePage").info(
"Number of uploaded files: " + status.localIDs.length.toString());
Logger("FreeSpacePage")
.info("Space consumed: " + status.size.toString());
return _getWidget(status);
} else if (snapshot.hasError) {
return Center(child: Text("oops, something went wrong"));
} else {
return loadWidget;
}
},
);
}
Widget _getWidget(BackupStatus status) {
final count = status.localIDs.length;
final formattedCount = NumberFormat().format(count);
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",
2021-06-28 10:12:21 +00:00
style: TextStyle(
2021-06-28 11:19:52 +00:00
fontSize: 14,
2021-06-28 10:12:21 +00:00
height: 1.3,
2021-06-28 11:19:52 +00:00
color: Colors.white.withOpacity(0.8),
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") +
" can be deleted from this device to free up space",
2021-06-28 10:12:21 +00:00
style: TextStyle(
2021-06-28 11:19:52 +00:00
fontSize: 14,
2021-06-28 10:12:21 +00:00
height: 1.3,
2021-06-28 11:19:52 +00:00
color: Colors.white.withOpacity(0.8),
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",
2021-06-28 10:12:21 +00:00
style: TextStyle(
2021-06-28 11:19:52 +00:00
fontSize: 14,
2021-06-28 10:12:21 +00:00
height: 1.3,
2021-06-28 11:19:52 +00:00
color: Colors.white.withOpacity(0.8),
2021-06-28 10:12:21 +00:00
),
),
),
],
),
),
Padding(padding: EdgeInsets.all(32)),
Container(
width: double.infinity,
height: 64,
padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
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 {
final dialog = createProgressDialog(
context,
"deleting " +
status.localIDs.length.toString() +
" backed up files...");
await dialog.show();
await deleteLocalFiles(status.localIDs);
await dialog.hide();
Navigator.of(context).pop(status);
2021-06-28 11:19:52 +00:00
}
2021-06-28 10:12:21 +00:00
}