Skip to content

Commit 1956171

Browse files
committed
feat: bytes -> MB.
1 parent 5562455 commit 1956171

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Client.Avalonia/ViewModels/MainWindowViewModel.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public MainWindowViewModel()
4040
_random = new Random();
4141
}
4242

43+
#region Buttons
44+
4345
private bool CanStart => !IsCompleted;
4446

4547
[RelayCommand(CanExecute = nameof(CanStart))]
@@ -77,6 +79,9 @@ private void Restart()
7779
Start();
7880
}
7981

82+
#endregion
83+
84+
8085
private void UpdateProgress(object? sender, EventArgs e)
8186
{
8287
var received = Statistics.BytesReceived;
@@ -95,7 +100,7 @@ private void UpdateProgress(object? sender, EventArgs e)
95100
Statistics.ProgressPercentage = (double)received / total * 100;
96101

97102
var currentSpeed = increment / _timer.Interval.TotalSeconds;
98-
Statistics.Speed = $"{currentSpeed / 1024 / 1024:F1} MB/s";
103+
Statistics.Speed = $"{currentSpeed / 1024 / 1024:F2} MB/s";
99104

100105
var remainingBytes = total - received;
101106
Statistics.Remaining = TimeSpan.FromSeconds(remainingBytes / currentSpeed);
@@ -123,12 +128,15 @@ [ObservableProperty] [Description("下载速度")]
123128
[ObservableProperty] [Description("剩余下载时间")]
124129
private TimeSpan _remaining;
125130

126-
[ObservableProperty] [Description("已下载大小")]
131+
[ObservableProperty] [Description("总大小")] [NotifyPropertyChangedFor(nameof(TotalBytesToReceiveInMB))]
127132
private long _totalBytesToReceive;
128133

129-
[ObservableProperty] [Description("总大小")]
134+
[ObservableProperty] [Description("已下载大小")] [NotifyPropertyChangedFor(nameof(BytesReceivedInMB))]
130135
private long _bytesReceived;
131136

132137
[ObservableProperty] [Description("进度百分比")]
133138
private double _progressPercentage;
139+
140+
public double BytesReceivedInMB => (double)BytesReceived / 1024 / 1024;
141+
public double TotalBytesToReceiveInMB => (double)TotalBytesToReceive / 1024 / 1024;
134142
}

src/Client.Avalonia/Views/MainWindow.axaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<Design.DataContext>
2727
<vm:MainWindowViewModel />
2828
</Design.DataContext>
29-
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="10" MinWidth="500">
29+
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="10" MinWidth="550">
3030
<Image
3131
Margin="30"
3232
Source="../Assets/GeneralUpdate.png" Width="150" Height="150" />
@@ -47,10 +47,10 @@
4747
<SelectableTextBlock
4848
HorizontalAlignment="Center">
4949
<Run Text="已下载:" />
50-
<Run Text="{Binding Statistics.BytesReceived, StringFormat='\{0:N0}'}" />
50+
<Run Text="{Binding Statistics.BytesReceivedInMB, StringFormat='\{0:F2}'}" />
5151
<Run Text="/" />
52-
<Run Text="{Binding Statistics.TotalBytesToReceive, StringFormat='\{0:N0}'}" />
53-
<Run Text="bytes" />
52+
<Run Text="{Binding Statistics.TotalBytesToReceiveInMB, StringFormat='\{0:F2}'}" />
53+
<Run Text="MB" />
5454
</SelectableTextBlock>
5555

5656
<SelectableTextBlock

0 commit comments

Comments
 (0)