mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-02-02 14:16:58 +00:00
Make DiskSize a constant constructor and fix slider on Volume resize screen
This commit is contained in:
parent
8d2fbb5100
commit
6f5ffa0f80
|
@ -89,8 +89,7 @@ class ApiProviderVolumeCubit
|
|||
final ServerVolume? volume =
|
||||
await providerApi!.getVolumeProvider().createVolume();
|
||||
|
||||
final diskVolume = DiskVolume();
|
||||
diskVolume.providerVolume = volume;
|
||||
final diskVolume = DiskVolume(providerVolume: volume);
|
||||
await attachVolume(diskVolume);
|
||||
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
|
||||
class DiskSize {
|
||||
DiskSize({final this.byte = 0});
|
||||
const DiskSize({final this.byte = 0});
|
||||
|
||||
int byte;
|
||||
final int byte;
|
||||
|
||||
double get kibibyte => byte / 1024.0;
|
||||
double get mebibyte => byte / 1024.0 / 1024.0;
|
||||
|
|
|
@ -51,7 +51,7 @@ class Service {
|
|||
isMovable: false,
|
||||
status: ServiceStatus.off,
|
||||
storageUsage: ServiceStorageUsage(
|
||||
used: DiskSize(byte: 0),
|
||||
used: const DiskSize(byte: 0),
|
||||
volume: '',
|
||||
),
|
||||
svgIcon: '',
|
||||
|
|
|
@ -3,21 +3,65 @@ import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
|||
import 'package:selfprivacy/logic/models/json/server_disk_volume.dart';
|
||||
|
||||
class DiskVolume {
|
||||
DiskSize sizeUsed = DiskSize();
|
||||
DiskSize sizeTotal = DiskSize();
|
||||
String name = '';
|
||||
bool root = false;
|
||||
bool isResizable = true;
|
||||
DiskVolume({
|
||||
this.name = '',
|
||||
this.sizeTotal = const DiskSize(byte: 0),
|
||||
this.sizeUsed = const DiskSize(byte: 0),
|
||||
this.root = false,
|
||||
this.isResizable = false,
|
||||
this.serverDiskVolume,
|
||||
this.providerVolume,
|
||||
});
|
||||
|
||||
DiskVolume.fromServerDiscVolume(
|
||||
final ServerDiskVolume volume,
|
||||
final ServerVolume? providerVolume,
|
||||
) : this(
|
||||
name: volume.name,
|
||||
sizeTotal: DiskSize(
|
||||
byte:
|
||||
volume.totalSpace == 'None' ? 0 : int.parse(volume.totalSpace),
|
||||
),
|
||||
sizeUsed: DiskSize(
|
||||
byte: volume.usedSpace == 'None' ? 0 : int.parse(volume.usedSpace),
|
||||
),
|
||||
root: volume.root,
|
||||
isResizable: providerVolume != null,
|
||||
serverDiskVolume: volume,
|
||||
providerVolume: providerVolume,
|
||||
);
|
||||
|
||||
/// Get the display name of the volume
|
||||
///
|
||||
/// If it is sda1 and root the name is "System disk"
|
||||
/// If there is a mapping to providerVolume, the name is "Expandable volume"
|
||||
/// Otherwise the name is the name of the volume
|
||||
String get displayName {
|
||||
if (root) {
|
||||
return 'System disk';
|
||||
} else if (providerVolume != null) {
|
||||
return 'Expandable volume';
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
DiskSize sizeUsed;
|
||||
DiskSize sizeTotal;
|
||||
String name;
|
||||
bool root;
|
||||
bool isResizable;
|
||||
ServerDiskVolume? serverDiskVolume;
|
||||
ServerVolume? providerVolume;
|
||||
|
||||
/// from 0.0 to 1.0
|
||||
double get percentage => sizeTotal.byte == 0 ? 0 : sizeUsed.byte / sizeTotal.byte;
|
||||
bool get isDiskOkay => percentage < 0.8 && sizeTotal.gibibyte - sizeUsed.gibibyte > 2.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 {
|
||||
|
||||
DiskStatus.fromVolumes(
|
||||
final List<ServerDiskVolume> serverVolumes,
|
||||
final List<ServerVolume> providerVolumes,
|
||||
|
@ -25,32 +69,25 @@ class DiskStatus {
|
|||
diskVolumes = serverVolumes.map((
|
||||
final ServerDiskVolume volume,
|
||||
) {
|
||||
final DiskVolume diskVolume = DiskVolume();
|
||||
diskVolume.sizeUsed = DiskSize(
|
||||
byte: volume.usedSpace == 'None' ? 0 : int.parse(volume.usedSpace),
|
||||
);
|
||||
diskVolume.sizeTotal = DiskSize(
|
||||
byte: volume.totalSpace == 'None' ? 0 : int.parse(volume.totalSpace),
|
||||
);
|
||||
diskVolume.serverDiskVolume = volume;
|
||||
ServerVolume? providerVolume;
|
||||
|
||||
for (final ServerVolume providerVolume in providerVolumes) {
|
||||
if (providerVolume.linuxDevice == null ||
|
||||
for (final ServerVolume iterableProviderVolume in providerVolumes) {
|
||||
if (iterableProviderVolume.linuxDevice == null ||
|
||||
volume.model == null ||
|
||||
volume.serial == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String deviceId = providerVolume.linuxDevice!.split('/').last;
|
||||
final String deviceId = iterableProviderVolume.linuxDevice!.split('/').last;
|
||||
if (deviceId.contains(volume.model!) &&
|
||||
deviceId.contains(volume.serial!)) {
|
||||
diskVolume.providerVolume = providerVolume;
|
||||
providerVolume = iterableProviderVolume;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
diskVolume.name = volume.name;
|
||||
diskVolume.root = volume.root;
|
||||
final DiskVolume diskVolume = DiskVolume.fromServerDiscVolume(volume, providerVolume);
|
||||
|
||||
|
||||
return diskVolume;
|
||||
}).toList();
|
||||
|
|
|
@ -22,13 +22,20 @@ class ExtendingVolumePage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _ExtendingVolumePageState extends State<ExtendingVolumePage> {
|
||||
@override
|
||||
void initState() {
|
||||
minSize = widget.diskVolumeToResize.sizeTotal;
|
||||
_currentSliderGbValue = minSize.gibibyte;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
bool _isError = false;
|
||||
|
||||
double _currentSliderGbValue = -1;
|
||||
late double _currentSliderGbValue;
|
||||
double _euroPerGb = 1.0;
|
||||
|
||||
final DiskSize maxSize = DiskSize(byte: 500000000000);
|
||||
DiskSize minSize = DiskSize();
|
||||
final DiskSize maxSize = const DiskSize(byte: 500000000000);
|
||||
late DiskSize minSize;
|
||||
|
||||
final TextEditingController _sizeController = TextEditingController();
|
||||
final TextEditingController _priceController = TextEditingController();
|
||||
|
@ -52,6 +59,9 @@ class _ExtendingVolumePageState extends State<ExtendingVolumePage> {
|
|||
'providers.storage.extending_volume_description'.tr(),
|
||||
children: const [
|
||||
SizedBox(height: 16),
|
||||
Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue