Add server storage overview and retention controls to Settings
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import '../settings_group.dart';
|
||||
import 'storage_controls.dart';
|
||||
import 'storage_models.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
|
||||
class StorageUsage extends StatelessWidget {
|
||||
const StorageUsage({super.key, required this.data});
|
||||
final JsonMap data;
|
||||
@override
|
||||
Widget build(BuildContext context) => SettingsGroup(
|
||||
title: 'Server storage',
|
||||
footer: const Text(
|
||||
'Combined file sizes on the connected server, with shared files counted once. Protected data may prevent reaching a size limit.',
|
||||
),
|
||||
children: [
|
||||
storagePadding(
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${data['partial'] == true ? 'At least ' : ''}${storageBytes(storageInt(data['total_bytes']))} used',
|
||||
style: DefaultTextStyle.of(
|
||||
context,
|
||||
).style.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (_measured(context) case final String measured)
|
||||
Text('Measured $measured'),
|
||||
if (data['partial'] == true)
|
||||
const Text('Measurement is incomplete. See details below.'),
|
||||
],
|
||||
),
|
||||
),
|
||||
for (final category in storageRows(data['categories']))
|
||||
storagePadding(
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
spacing: 16,
|
||||
children: [
|
||||
Text('${category['label'] ?? category['id']}'),
|
||||
Text(
|
||||
'${category['partial'] == true ? 'At least ' : ''}${storageBytes(storageInt(category['bytes']))}',
|
||||
),
|
||||
],
|
||||
),
|
||||
Text('${storageInt(category['files'])} files'),
|
||||
if (category['path'] case final String path when path.isNotEmpty)
|
||||
Text(path, softWrap: true),
|
||||
if (category['error'] case final String error
|
||||
when error.isNotEmpty)
|
||||
Text(error),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (data['warnings'] case final List warnings when warnings.isNotEmpty)
|
||||
storagePadding(Text(warnings.join('\n'))),
|
||||
],
|
||||
);
|
||||
String? _measured(BuildContext context) {
|
||||
final time = DateTime.tryParse('${data['measured_at'] ?? ''}')?.toLocal();
|
||||
if (time == null) return null;
|
||||
final material = Localizations.of<MaterialLocalizations>(
|
||||
context,
|
||||
MaterialLocalizations,
|
||||
);
|
||||
if (material != null) {
|
||||
return '${time.day} ${material.formatMonthYear(time)} · ${material.formatTimeOfDay(TimeOfDay.fromDateTime(time), alwaysUse24HourFormat: true)}';
|
||||
}
|
||||
final local = CupertinoLocalizations.of(context);
|
||||
return '${time.day} ${local.datePickerMonth(time.month)} ${time.year} · ${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user