Skip to content

Commit

Permalink
Merge '~ProgressBarValue' classes
Browse files Browse the repository at this point in the history
Meld 'BindableProgressBarValue' class into 'AdaptiveProgressBarValue' class
The difference between them is subtle and is platform specific. So, melding
the changes from one class into the other shouldn't be an issue.

Although this is a Breaking Change, it doesn't change any functional behavior.
It's refactored to be a drop-in replacement. So, just a global text replace is enough.
  • Loading branch information
Nirmal4G committed Jun 26, 2021
1 parent 09eb161 commit 092ef04
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

#if WINRT
using System.Collections.Generic;
using BindableProgressBarValue = Microsoft.Toolkit.Uwp.Notifications.AdaptiveProgressBarValue;
using BindableString = System.String;
#else
using BindableProgressBarValue = Microsoft.Toolkit.Uwp.Notifications.BindableProgressBarValue;
using BindableString = Microsoft.Toolkit.Uwp.Notifications.BindableString;
#endif

Expand All @@ -38,7 +36,7 @@ public sealed class AdaptiveProgressBar : IToastBindingGenericChild
/// <summary>
/// Gets or sets the value of the progress bar. Supports data binding. Defaults to 0.
/// </summary>
public BindableProgressBarValue Value { get; set; } = AdaptiveProgressBarValue.FromValue(0);
public AdaptiveProgressBarValue Value { get; set; } = AdaptiveProgressBarValue.FromValue(0);

/// <summary>
/// Gets or sets an optional string to be displayed instead of the default percentage string. If this isn't provided, something like "70%" will be displayed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ private AdaptiveProgressBarValue()
{
}

#if !WINRT
/// <summary>
/// Initializes a new instance of the <see cref="AdaptiveProgressBarValue"/> class.
/// A new binding for a double value, with the required binding value name. Do NOT include surrounding {} brackets.
/// </summary>
/// <param name="bindingName">The name that maps to your binding data value.</param>
public AdaptiveProgressBarValue(string bindingName)
{
BindingName = bindingName;
}
#endif

internal string ToXmlString()
{
if (IsIndeterminate)
Expand Down Expand Up @@ -92,5 +104,25 @@ public static AdaptiveProgressBarValue FromBinding(string bindingName)
BindingName = bindingName
};
}

#if !WINRT
/// <summary>
/// Creates an <see cref="AdaptiveProgressBarValue"/> that has the raw double value.
/// </summary>
/// <param name="value">The raw value</param>
public static implicit operator AdaptiveProgressBarValue(double value)
{
return FromValue(value);
}

/// <summary>
/// Creates an <see cref="AdaptiveProgressBarValue"/> that has the raw double value.
/// </summary>
/// <param name="bindingName">The raw value</param>
public static implicit operator AdaptiveProgressBarValue(string bindingName)
{
return FromBinding(bindingName);
}
#endif
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static NotificationData CreateProgressBarData(ToastContent toast, int ind
data.Values[bindableTitle.BindingName] = title;
}

if (progressBar.Value is BindableProgressBarValue bindableProgressValue && value != default)
if (progressBar.Value is AdaptiveProgressBarValue bindableProgressValue && value != default)
{
data.Values[bindableProgressValue.BindingName] = value.ToString();
}
Expand Down Expand Up @@ -420,7 +420,7 @@ public ToastContentBuilder AddProgressBar(string title = default, double? value
}
else if (value == null)
{
progressBar.Value = new BindableProgressBarValue($"progressValue_{index}");
progressBar.Value = new AdaptiveProgressBarValue($"progressValue_{index}");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private async void ButtonProgressToast_Click(object sender, RoutedEventArgs e)
.AddText("Sending image to conversation...")
.AddVisualChild(new AdaptiveProgressBar()
{
Value = new BindableProgressBarValue("progress"),
Value = new AdaptiveProgressBarValue("progress"),
Status = "Sending..."
})
.Show(toast =>
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/UnitTests.Notifications.Shared/Test_Toast_Xml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ public void Test_Toast_ProgressBar_Value()
{ AdaptiveProgressBarBindableProperty.Value, "progressValue" }
},
#else
Value = new BindableProgressBarValue("progressValue"),
Value = new AdaptiveProgressBarValue("progressValue"),
#endif
Status = "Downloading..."
});
Expand Down Expand Up @@ -2003,7 +2003,7 @@ public void Test_Toast_ProgressBar()
{ AdaptiveProgressBarBindableProperty.Status, "progressStatus" }
}
#else
Value = new BindableProgressBarValue("progressValue"),
Value = new AdaptiveProgressBarValue("progressValue"),
Title = new BindableString("progressTitle"),
ValueStringOverride = new BindableString("progressValueOverride"),
Status = new BindableString("progressStatus")
Expand Down

0 comments on commit 092ef04

Please sign in to comment.