2021-06-28 10:12:21 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
2023-04-07 06:27:22 +00:00
|
|
|
import "package:photos/generated/l10n.dart";
|
2021-06-28 10:12:21 +00:00
|
|
|
import 'package:photos/models/backup_status.dart';
|
2022-07-03 10:09:01 +00:00
|
|
|
import 'package:photos/ui/common/gradient_button.dart';
|
2021-06-28 10:12:21 +00:00
|
|
|
import 'package:photos/utils/data_util.dart';
|
|
|
|
import 'package:photos/utils/delete_file_util.dart';
|
|
|
|
|
|
|
|
class FreeSpacePage extends StatefulWidget {
|
2021-06-28 14:47:06 +00:00
|
|
|
final BackupStatus status;
|
2022-11-24 11:09:05 +00:00
|
|
|
final bool clearSpaceForFolder;
|
2021-06-28 14:47:06 +00:00
|
|
|
|
2022-11-24 11:09:05 +00:00
|
|
|
const FreeSpacePage(
|
|
|
|
this.status, {
|
2022-12-30 12:10:17 +00:00
|
|
|
Key? key,
|
2022-11-24 11:09:05 +00:00
|
|
|
this.clearSpaceForFolder = false,
|
|
|
|
}) : super(key: key);
|
2021-06-28 10:12:21 +00:00
|
|
|
|
|
|
|
@override
|
2022-07-03 09:45:00 +00:00
|
|
|
State<FreeSpacePage> createState() => _FreeSpacePageState();
|
2021-06-28 10:12:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _FreeSpacePageState extends State<FreeSpacePage> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-06-07 11:50:36 +00:00
|
|
|
elevation: 0,
|
2023-04-07 06:27:22 +00:00
|
|
|
title: Text(S.of(context).freeUpSpace),
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2021-06-28 11:20:48 +00:00
|
|
|
body: _getBody(),
|
2021-06-28 10:12:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getBody() {
|
2022-06-11 08:23:52 +00:00
|
|
|
Logger("FreeSpacePage").info(
|
|
|
|
"Number of uploaded files: " + widget.status.localIDs.length.toString(),
|
|
|
|
);
|
2022-07-03 09:49:33 +00:00
|
|
|
Logger("FreeSpacePage")
|
|
|
|
.info("Space consumed: " + widget.status.size.toString());
|
2022-06-12 16:03:31 +00:00
|
|
|
return SingleChildScrollView(
|
|
|
|
child: _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-11-24 11:09:05 +00:00
|
|
|
final String textMessage = widget.clearSpaceForFolder
|
2023-04-07 06:27:22 +00:00
|
|
|
? S.of(context).filesBackedUpInAlbum(count, formattedCount)
|
|
|
|
: S.of(context).filesBackedUpFromDevice(count, formattedCount);
|
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),
|
2022-06-09 09:47:34 +00:00
|
|
|
fontWeight: FontWeight.w500,
|
2022-03-05 20:52:00 +00:00
|
|
|
);
|
2023-05-30 07:49:36 +00:00
|
|
|
final isLightMode = Theme.of(context).brightness == Brightness.light;
|
2022-06-09 09:47:34 +00:00
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2022-09-05 05:15:14 +00:00
|
|
|
const SizedBox(height: 24),
|
2022-06-09 09:47:34 +00:00
|
|
|
Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
children: [
|
|
|
|
isLightMode
|
|
|
|
? Image.asset(
|
2022-06-24 15:29:24 +00:00
|
|
|
'assets/loading_photos_background.png',
|
2022-06-09 09:47:34 +00:00
|
|
|
color: Colors.white.withOpacity(0.4),
|
|
|
|
colorBlendMode: BlendMode.modulate,
|
|
|
|
)
|
2022-09-05 05:15:14 +00:00
|
|
|
: Image.asset(
|
|
|
|
'assets/loading_photos_background_dark.png',
|
|
|
|
color: Colors.white.withOpacity(0.25),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 16),
|
|
|
|
child: Image.asset(
|
|
|
|
"assets/gallery_locked.png",
|
|
|
|
height: 160,
|
|
|
|
),
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2022-06-09 09:47:34 +00:00
|
|
|
],
|
|
|
|
),
|
2022-09-05 05:15:14 +00:00
|
|
|
const SizedBox(height: 24),
|
2022-06-09 09:47:34 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 36, right: 40),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2022-07-04 06:02:17 +00:00
|
|
|
const Icon(
|
2022-06-09 09:47:34 +00:00
|
|
|
Icons.cloud_done_outlined,
|
|
|
|
color: Color.fromRGBO(45, 194, 98, 1.0),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(padding: EdgeInsets.all(10)),
|
2022-06-09 09:47:34 +00:00
|
|
|
Expanded(
|
|
|
|
child: Text(
|
2022-11-24 11:09:05 +00:00
|
|
|
textMessage,
|
2022-06-09 09:47:34 +00:00
|
|
|
style: informationTextStyle,
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2022-06-09 09:47:34 +00:00
|
|
|
),
|
|
|
|
],
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2022-06-09 09:47:34 +00:00
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(padding: EdgeInsets.all(12)),
|
2022-06-09 09:47:34 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 36, right: 40),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2022-07-04 06:02:17 +00:00
|
|
|
const Icon(
|
2022-06-09 09:47:34 +00:00
|
|
|
Icons.delete_outline,
|
|
|
|
color: Color.fromRGBO(45, 194, 98, 1.0),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(padding: EdgeInsets.all(10)),
|
2022-06-09 09:47:34 +00:00
|
|
|
Expanded(
|
|
|
|
child: Text(
|
2023-04-07 06:27:22 +00:00
|
|
|
S
|
|
|
|
.of(context)
|
|
|
|
.freeUpSpaceSaving(count, formatBytes(status.size)),
|
2022-06-09 09:47:34 +00:00
|
|
|
style: informationTextStyle,
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2022-06-09 09:47:34 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(padding: EdgeInsets.all(12)),
|
2022-06-09 09:47:34 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 36, right: 40),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
2022-07-04 06:02:17 +00:00
|
|
|
const Icon(
|
2022-06-09 09:47:34 +00:00
|
|
|
Icons.devices,
|
|
|
|
color: Color.fromRGBO(45, 194, 98, 1.0),
|
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(padding: EdgeInsets.all(10)),
|
2022-06-09 09:47:34 +00:00
|
|
|
Expanded(
|
|
|
|
child: Text(
|
2023-04-07 06:27:22 +00:00
|
|
|
S.of(context).freeUpAccessPostDelete(count),
|
2022-06-09 09:47:34 +00:00
|
|
|
style: informationTextStyle,
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2022-06-09 09:47:34 +00:00
|
|
|
),
|
|
|
|
],
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2022-06-09 09:47:34 +00:00
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(padding: EdgeInsets.all(24)),
|
2022-06-09 09:47:34 +00:00
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
2022-07-04 06:02:17 +00:00
|
|
|
constraints: const BoxConstraints(
|
2022-06-09 09:47:34 +00:00
|
|
|
minHeight: 64,
|
|
|
|
),
|
|
|
|
padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
|
|
|
|
child: GradientButton(
|
|
|
|
onTap: () async {
|
|
|
|
await _freeStorage(status);
|
|
|
|
},
|
2023-04-07 06:27:22 +00:00
|
|
|
text: S.of(context).freeUpAmount(formatBytes(status.size)),
|
2021-06-28 10:12:21 +00:00
|
|
|
),
|
2022-06-09 09:47:34 +00:00
|
|
|
),
|
2022-07-04 06:02:17 +00:00
|
|
|
const Padding(padding: EdgeInsets.all(24)),
|
2022-06-09 09:47:34 +00:00
|
|
|
],
|
2021-06-28 10:12:21 +00:00
|
|
|
);
|
|
|
|
}
|
2021-06-28 11:19:52 +00:00
|
|
|
|
2021-06-28 14:30:48 +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
|
|
|
}
|