mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 17:26:35 +00:00
Refactor disk_size.dart and disk_status.dart to use getters
This commit is contained in:
parent
979e8ee37a
commit
58479256c5
|
@ -5,20 +5,20 @@ class DiskSize {
|
||||||
|
|
||||||
int byte;
|
int byte;
|
||||||
|
|
||||||
double asKb() => byte / 1024.0;
|
double get kibibyte => byte / 1024.0;
|
||||||
double asMb() => byte / 1024.0 / 1024.0;
|
double get mebibyte => byte / 1024.0 / 1024.0;
|
||||||
double asGb() => byte / 1024.0 / 1024.0 / 1024.0;
|
double get gibibyte => byte / 1024.0 / 1024.0 / 1024.0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
if (byte < 1024) {
|
if (byte < 1024) {
|
||||||
return '${byte.toStringAsFixed(0)} ${tr('bytes')}';
|
return '${byte.toStringAsFixed(0)} ${tr('bytes')}';
|
||||||
} else if (byte < 1024 * 1024) {
|
} else if (byte < 1024 * 1024) {
|
||||||
return 'providers.storage.kb'.tr(args: [asKb().toStringAsFixed(1)]);
|
return 'providers.storage.kb'.tr(args: [kibibyte.toStringAsFixed(1)]);
|
||||||
} else if (byte < 1024 * 1024 * 1024) {
|
} else if (byte < 1024 * 1024 * 1024) {
|
||||||
return 'providers.storage.mb'.tr(args: [asMb().toStringAsFixed(1)]);
|
return 'providers.storage.mb'.tr(args: [mebibyte.toStringAsFixed(1)]);
|
||||||
} else {
|
} else {
|
||||||
return 'providers.storage.gb'.tr(args: [asGb().toStringAsFixed(1)]);
|
return 'providers.storage.gb'.tr(args: [gibibyte.toStringAsFixed(1)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,25 +12,16 @@ class DiskVolume {
|
||||||
ServerVolume? providerVolume;
|
ServerVolume? providerVolume;
|
||||||
|
|
||||||
/// from 0.0 to 1.0
|
/// from 0.0 to 1.0
|
||||||
double percentage = 0.0;
|
double get percentage => sizeTotal.byte == 0 ? 0 : sizeUsed.byte / sizeTotal.byte;
|
||||||
|
bool get isDiskOkay => percentage < 0.8 && sizeTotal.gibibyte - sizeUsed.gibibyte > 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiskStatus {
|
class DiskStatus {
|
||||||
DiskStatus() {
|
|
||||||
isDiskOkay = false;
|
|
||||||
diskVolumes = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
DiskStatus.fromVolumes(
|
DiskStatus.fromVolumes(
|
||||||
final List<ServerDiskVolume> serverVolumes,
|
final List<ServerDiskVolume> serverVolumes,
|
||||||
final List<ServerVolume> providerVolumes,
|
final List<ServerVolume> providerVolumes,
|
||||||
) {
|
) {
|
||||||
isDiskOkay = true;
|
|
||||||
|
|
||||||
if (providerVolumes.isEmpty || serverVolumes.isEmpty) {
|
|
||||||
isDiskOkay = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
diskVolumes = serverVolumes.map((
|
diskVolumes = serverVolumes.map((
|
||||||
final ServerDiskVolume volume,
|
final ServerDiskVolume volume,
|
||||||
) {
|
) {
|
||||||
|
@ -60,18 +51,15 @@ class DiskStatus {
|
||||||
|
|
||||||
diskVolume.name = volume.name;
|
diskVolume.name = volume.name;
|
||||||
diskVolume.root = volume.root;
|
diskVolume.root = volume.root;
|
||||||
diskVolume.percentage =
|
|
||||||
volume.usedSpace != 'None' && volume.totalSpace != 'None'
|
|
||||||
? 1.0 / diskVolume.sizeTotal.byte * diskVolume.sizeUsed.byte
|
|
||||||
: 0.0;
|
|
||||||
if (diskVolume.percentage >= 0.8 ||
|
|
||||||
diskVolume.sizeTotal.asGb() - diskVolume.sizeUsed.asGb() <= 2.0) {
|
|
||||||
isDiskOkay = false;
|
|
||||||
}
|
|
||||||
return diskVolume;
|
return diskVolume;
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
DiskStatus() {
|
||||||
|
diskVolumes = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isDiskOkay => diskVolumes.every((final volume) => volume.isDiskOkay);
|
||||||
|
|
||||||
bool isDiskOkay = false;
|
|
||||||
List<DiskVolume> diskVolumes = [];
|
List<DiskVolume> diskVolumes = [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ class _ExtendingVolumePageState extends State<ExtendingVolumePage> {
|
||||||
final TextEditingController _priceController = TextEditingController();
|
final TextEditingController _priceController = TextEditingController();
|
||||||
|
|
||||||
void _updateErrorStatuses() {
|
void _updateErrorStatuses() {
|
||||||
_isError = minSize.asGb() > _currentSliderGbValue;
|
_isError = minSize.gibibyte > _currentSliderGbValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -62,7 +62,7 @@ class _ExtendingVolumePageState extends State<ExtendingVolumePage> {
|
||||||
.toStringAsFixed(2);
|
.toStringAsFixed(2);
|
||||||
minSize = widget.diskVolumeToResize.sizeTotal;
|
minSize = widget.diskVolumeToResize.sizeTotal;
|
||||||
if (_currentSliderGbValue < 0) {
|
if (_currentSliderGbValue < 0) {
|
||||||
_currentSliderGbValue = minSize.asGb();
|
_currentSliderGbValue = minSize.gibibyte;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BrandHeroScreen(
|
return BrandHeroScreen(
|
||||||
|
@ -111,9 +111,9 @@ class _ExtendingVolumePageState extends State<ExtendingVolumePage> {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Slider(
|
Slider(
|
||||||
min: minSize.asGb(),
|
min: minSize.gibibyte,
|
||||||
value: _currentSliderGbValue,
|
value: _currentSliderGbValue,
|
||||||
max: maxSize.asGb(),
|
max: maxSize.gibibyte,
|
||||||
onChanged: (final double value) {
|
onChanged: (final double value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentSliderGbValue = value;
|
_currentSliderGbValue = value;
|
||||||
|
|
Loading…
Reference in a new issue