Skip to content

Fix: Fixed issue where progress is shown in decimals #11777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public bool EnumerationCompleted
/// <summary>
/// Only used when detailed count isn't available.
/// </summary>
public float? Percentage { get; set; }
public int? Percentage { get; set; }

public FileSystemProgress(
IProgress<FileSystemProgress>? progress,
Expand All @@ -65,11 +65,12 @@ public FileSystemProgress(
TotalSize = totalSize;
}

public void Report(float? percentage = null)
public void Report(int? percentage = null)
{
Percentage = percentage;
if (((EnumerationCompleted && ProcessedItemsCount == ItemsCount && ProcessedSize == TotalSize) ||
(percentage is float f && MathF.Abs(f - 100f) <= float.Epsilon)) &&
if (EnumerationCompleted &&
ProcessedItemsCount == ItemsCount &&
ProcessedSize == TotalSize &&
status is FileSystemStatusCode.InProgress or null)
{
status = FileSystemStatusCode.Success;
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Helpers/RecycleBinHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static async Task EmptyRecycleBin()
var banner = App.OngoingTasksViewModel.PostBanner(
bannerTitle,
"EmptyingRecycleBin".GetLocalizedResource(),
0.0f,
0,
ReturnResult.InProgress,
FileOperationType.Delete);

Expand All @@ -81,14 +81,14 @@ public static async Task EmptyRecycleBin()
App.OngoingTasksViewModel.PostBanner(
bannerTitle,
"BinEmptyingSucceded".GetLocalizedResource(),
100.0f,
100,
ReturnResult.Success,
FileOperationType.Delete);
else
App.OngoingTasksViewModel.PostBanner(
bannerTitle,
"BinEmptyingFailed".GetLocalizedResource(),
100.0f,
100,
ReturnResult.Failed,
FileOperationType.Delete);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Interacts/IStatusCenterActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IOngoingTasksActions
{
event EventHandler<PostedStatusBanner> ProgressBannerPosted;

float MedianOperationProgressValue { get; }
int MedianOperationProgressValue { get; }

int OngoingOperationsCount { get; }

Expand All @@ -27,7 +27,7 @@ public interface IOngoingTasksActions
/// <param name="status"></param>
/// <param name="operation"></param>
/// <returns>A StatusBanner object which may be used to track/update the progress of an operation.</returns>
PostedStatusBanner PostBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation);
PostedStatusBanner PostBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation);

/// <summary>
/// Posts a new banner with expanded height to the Status Center control. This is typically
Expand All @@ -51,7 +51,7 @@ public interface IOngoingTasksActions
/// <param name="operation"></param>
/// <param name="cancellationTokenSource"></param>
/// <returns></returns>
PostedStatusBanner PostOperationBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource);
PostedStatusBanner PostOperationBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource);

/// <summary>
/// Dismisses <paramref name="banner"/> and removes it from the collection
Expand Down
75 changes: 30 additions & 45 deletions src/Files.App/ViewModels/StatusCenterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ namespace Files.App.ViewModels
{
public class OngoingTasksViewModel : ObservableObject, IOngoingTasksActions
{
#region Public Properties
// Public Properties

public ObservableCollection<StatusBanner> StatusBannersSource { get; private set; } = new ObservableCollection<StatusBanner>();

private float medianOperationProgressValue = 0.0f;

public OngoingTasksViewModel()
{
StatusBannersSource.CollectionChanged += (s, e) => OnPropertyChanged(nameof(AnyBannersPresent));
}

public float MedianOperationProgressValue
private int medianOperationProgressValue = 0;
public int MedianOperationProgressValue
{
get => medianOperationProgressValue;
private set => SetProperty(ref medianOperationProgressValue, value);
Expand Down Expand Up @@ -82,17 +76,20 @@ public int InfoBadgeValue
get => OngoingOperationsCount > 0 ? OngoingOperationsCount : -1;
}

#endregion Public Properties

#region Events
// Events

public event EventHandler<PostedStatusBanner> ProgressBannerPosted;

#endregion Events
// Constructors

public OngoingTasksViewModel()
{
StatusBannersSource.CollectionChanged += (s, e) => OnPropertyChanged(nameof(AnyBannersPresent));
}

#region IOngoingTasksActions
// IOngoingTasksActions

public PostedStatusBanner PostBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation)
public PostedStatusBanner PostBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation)
{
StatusBanner banner = new StatusBanner(message, title, initialProgress, status, operation);
PostedStatusBanner postedBanner = new PostedStatusBanner(banner, this);
Expand All @@ -105,7 +102,7 @@ public PostedStatusBanner PostBanner(string title, string message, float initial
return postedBanner;
}

public PostedStatusBanner PostOperationBanner(string title, string message, float initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource)
public PostedStatusBanner PostOperationBanner(string title, string message, int initialProgress, ReturnResult status, FileOperationType operation, CancellationTokenSource cancellationTokenSource)
{
StatusBanner banner = new StatusBanner(message, title, initialProgress, status, operation)
{
Expand Down Expand Up @@ -161,36 +158,31 @@ public void UpdateMedianProgress()
{
if (AnyOperationsOngoing)
{
MedianOperationProgressValue = StatusBannersSource.Where((item) => item.IsProgressing).Average(x => x.Progress);
MedianOperationProgressValue = (int)StatusBannersSource.Where((item) => item.IsProgressing).Average(x => x.Progress);
}
}

#endregion IOngoingTasksActions
}

public class PostedStatusBanner
{
#region Private Members
// Private Members

private readonly IOngoingTasksActions OngoingTasksActions;

private readonly StatusBanner Banner;

private readonly CancellationTokenSource cancellationTokenSource;

#endregion Private Members

#region Public Members
// Public Members

public readonly FileSystemProgress Progress;

public readonly Progress<FileSystemProgress> ProgressEventSource;

public CancellationToken CancellationToken => cancellationTokenSource?.Token ?? default;

#endregion Public Members

#region Constructor
// Constructor

public PostedStatusBanner(StatusBanner banner, IOngoingTasksActions OngoingTasksActions)
{
Expand All @@ -211,9 +203,7 @@ public PostedStatusBanner(StatusBanner banner, IOngoingTasksActions OngoingTasks
Progress = new(ProgressEventSource, status: FileSystemStatusCode.InProgress);
}

#endregion Constructor

#region Private Helpers
// Private Helpers

private void ReportProgressToBanner(FileSystemProgress value)
{
Expand All @@ -226,10 +216,10 @@ private void ReportProgressToBanner(FileSystemProgress value)

Banner.IsProgressing = (value.Status & FileSystemStatusCode.InProgress) != 0;

if (value.Percentage is float f)
if (value.Percentage is int p)
{
Banner.Progress = f;
Banner.FullTitle = $"{Banner.Title} ({Banner.Progress:0.00}%)";
Banner.Progress = p;
Banner.FullTitle = $"{Banner.Title} ({Banner.Progress}%)";

// TODO: Show detailed progress if Size/Count information available
}
Expand All @@ -238,18 +228,18 @@ private void ReportProgressToBanner(FileSystemProgress value)
switch (value.TotalSize, value.ItemsCount)
{
case (not 0, not 0):
Banner.Progress = value.ProcessedSize * 100f / value.TotalSize;
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} ({value.ProcessedSize.ToSizeString()}) / {value.ItemsCount} ({value.TotalSize.ToSizeString()}): {Banner.Progress:0.00}%)";
Banner.Progress = (int)(value.ProcessedSize * 100f / value.TotalSize);
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} ({value.ProcessedSize.ToSizeString()}) / {value.ItemsCount} ({value.TotalSize.ToSizeString()}): {Banner.Progress}%)";
break;

case (not 0, _):
Banner.Progress = value.ProcessedSize * 100f / value.TotalSize;
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedSize.ToSizeString()} / {value.TotalSize.ToSizeString()}: {Banner.Progress:0.00}%)";
Banner.Progress = (int)(value.ProcessedSize * 100 / value.TotalSize);
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedSize.ToSizeString()} / {value.TotalSize.ToSizeString()}: {Banner.Progress}%)";
break;

case (_, not 0):
Banner.Progress = value.ProcessedItemsCount * 100f / value.ItemsCount;
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} / {value.ItemsCount}: {Banner.Progress:0.00}%)";
Banner.Progress = (int)(value.ProcessedItemsCount * 100 / value.ItemsCount);
Banner.FullTitle = $"{Banner.Title} ({value.ProcessedItemsCount} / {value.ItemsCount}: {Banner.Progress}%)";
break;

default:
Expand All @@ -272,9 +262,7 @@ private void ReportProgressToBanner(FileSystemProgress value)
OngoingTasksActions.UpdateMedianProgress();
}

#endregion Private Helpers

#region Public Helpers
// Public Helpers

public void Remove()
{
Expand All @@ -285,8 +273,6 @@ public void RequestCancellation()
{
cancellationTokenSource?.Cancel();
}

#endregion Public Helpers
}

public class StatusBanner : ObservableObject
Expand All @@ -303,9 +289,8 @@ public class StatusBanner : ObservableObject

#region Public Properties

private float progress = 0.0f;

public float Progress
private int progress = 0;
public int Progress
{
get => progress;
set => SetProperty(ref progress, value);
Expand Down