Skip to content

Commit

Permalink
Merge pull request #571 from JanuarySnow/hide_remaining_time_when_paused
Browse files Browse the repository at this point in the history
Hide remaining time in UI when paused
  • Loading branch information
Al12rs authored Aug 24, 2023
2 parents b34be79 + f95ee7e commit 61de8b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected virtual void UpdateWindowInfo()
// Calculate Remaining Time.
var throughput = Tasks.Sum(x => x.Throughput);
var remainingBytes = totalSizeBytes - totalDownloadedBytes;
SecondsRemaining = (int)(remainingBytes / Math.Max(throughput, 1));
SecondsRemaining = throughput < 1.0 ? 0 : (int)(remainingBytes / Math.Max(throughput, 1));
}

private void UpdateWindowInfoInternal(object? sender, object? state) => UpdateWindowInfo();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reactive.Disposables;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia.ReactiveUI;
using DynamicData.Binding;
Expand Down Expand Up @@ -78,7 +78,16 @@ public InProgressView()
.Subscribe(_ =>
{
var vm = ViewModel!;
BoldMinutesRemainingTextBlock.Text = StringFormatters.ToTimeRemainingShort(vm.SecondsRemaining);
if (vm.SecondsRemaining == 0)
{
BoldMinutesRemainingTextBlock.Text = "";
MinutesRemainingTextBlock.Text = "";
}
else
{
BoldMinutesRemainingTextBlock.Text = StringFormatters.ToTimeRemainingShort(vm.SecondsRemaining);
MinutesRemainingTextBlock.Text = "Remaining";
}
})
.DisposeWith(d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,18 @@ await OnUi(() =>
{
ViewModel.ClearDownloads();
ViewModel.IsRunning.Should().BeFalse();
// Check the total completion is correct with 0 elements.
var originalTimeRemaining = StringFormatters.ToTimeRemainingShort(ViewModel.SecondsRemaining);
View.BoldMinutesRemainingTextBlock.Text.Should().Be(originalTimeRemaining);
// If 0 seconds remaining, then no download is occuring, and the text block is empty string
if (ViewModel.SecondsRemaining == 0)
{
View.BoldMinutesRemainingTextBlock.Text.Should().Be("");
}
else
{
View.BoldMinutesRemainingTextBlock.Text.Should().Be(originalTimeRemaining);
}
// Check the total completion is correct with 1 element.
ViewModel.AddDownload(new DownloadTaskDesignViewModel()
Expand Down

0 comments on commit 61de8b0

Please sign in to comment.