Skip to content
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

Replaced all encoder/decoder tools dropdown with a toggle switch #169

Merged
merged 4 commits into from
Jan 21, 2022
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 @@ -22,11 +22,11 @@ public class Base64EncoderDecoderToolViewModel : ObservableRecipient, IToolViewM
/// <summary>
/// Whether the tool should encode or decode Base64.
/// </summary>
private static readonly SettingDefinition<string> Conversion
private static readonly SettingDefinition<bool> EncodeMode
= new(
name: $"{nameof(Base64EncoderDecoderToolViewModel)}.{nameof(Conversion)}",
name: $"{nameof(Base64EncoderDecoderToolViewModel)}.{nameof(EncodeMode)}",
isRoaming: true,
defaultValue: DefaultConversion);
defaultValue: true);

/// <summary>
/// Whether the tool should encode/decode in Unicode or ASCII.
Expand All @@ -38,8 +38,6 @@ public class Base64EncoderDecoderToolViewModel : ObservableRecipient, IToolViewM
defaultValue: DefaultEncoding);

private const string DefaultEncoding = "UTF-8";
private const string DefaultConversion = "Encode";
internal const string DecodeConversion = "Decode";

private readonly IMarketingService _marketingService;
private readonly ISettingsProvider _settingsProvider;
Expand Down Expand Up @@ -81,18 +79,18 @@ public class Base64EncoderDecoderToolViewModel : ObservableRecipient, IToolViewM
/// <summary>
/// Gets or sets the conversion mode.
/// </summary>
internal string ConversionMode
internal bool IsEncodeMode
{
get => _settingsProvider.GetSetting(Conversion);
get => _settingsProvider.GetSetting(EncodeMode);
set
{
if (!_setPropertyInProgress)
{
_setPropertyInProgress = true;
ThreadHelper.ThrowIfNotOnUIThread();
if (!string.Equals(_settingsProvider.GetSetting(Conversion), value, StringComparison.Ordinal))
if (_settingsProvider.GetSetting(EncodeMode) != value)
{
_settingsProvider.SetSetting(Conversion, value);
_settingsProvider.SetSetting(EncodeMode, value);
OnPropertyChanged();
}
InputValue = OutputValue;
Expand Down Expand Up @@ -146,7 +144,7 @@ private async Task TreatQueueAsync()
while (_conversionQueue.TryDequeue(out string? text))
{
string conversionResult;
if (string.Equals(ConversionMode, DefaultConversion, StringComparison.Ordinal))
if (IsEncodeMode)
{
conversionResult = await EncodeBase64DataAsync(text).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ public class HtmlEncoderDecoderToolViewModel : ObservableRecipient, IToolViewMod
/// <summary>
/// Whether the tool should encode or decode Html.
/// </summary>
private static readonly SettingDefinition<string> Conversion
private static readonly SettingDefinition<bool> EncodeMode
= new(
name: $"{nameof(HtmlEncoderDecoderToolViewModel)}.{nameof(Conversion)}",
name: $"{nameof(HtmlEncoderDecoderToolViewModel)}.{nameof(EncodeMode)}",
isRoaming: true,
defaultValue: DefaultConversion);

private const string DefaultConversion = "Encode";
internal const string DecodeConversion = "Decode";
defaultValue: true);

private readonly IMarketingService _marketingService;
private readonly ISettingsProvider _settingsProvider;
Expand Down Expand Up @@ -71,20 +68,20 @@ public class HtmlEncoderDecoderToolViewModel : ObservableRecipient, IToolViewMod
/// <summary>
/// Gets or sets the conversion mode.
/// </summary>
internal string ConversionMode
internal bool IsEncodeMode
{
get => _settingsProvider.GetSetting(Conversion);
get => _settingsProvider.GetSetting(EncodeMode);
set
{
if (!_setPropertyInProgress)
{
_setPropertyInProgress = true;
ThreadHelper.ThrowIfNotOnUIThread();
if (!string.Equals(_settingsProvider.GetSetting(Conversion), value, StringComparison.Ordinal))
if (_settingsProvider.GetSetting(EncodeMode) != value)
{
_settingsProvider.SetSetting(Conversion, value);
_settingsProvider.SetSetting(EncodeMode, value);
OnPropertyChanged();
}
}
InputValue = OutputValue;
_setPropertyInProgress = false;
}
Expand Down Expand Up @@ -118,7 +115,7 @@ private async Task TreatQueueAsync()
while (_conversionQueue.TryDequeue(out string? text))
{
string conversionResult;
if (string.Equals(ConversionMode, DefaultConversion, StringComparison.Ordinal))
if (IsEncodeMode)
{
conversionResult = await EncodeHtmlDataAsync(text).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ public class UrlEncoderDecoderToolViewModel : ObservableRecipient, IToolViewMode
/// <summary>
/// Whether the tool should encode or decode Url.
/// </summary>
private static readonly SettingDefinition<string> Conversion
private static readonly SettingDefinition<bool> EncodeMode
= new(
name: $"{nameof(UrlEncoderDecoderToolViewModel)}.{nameof(Conversion)}",
name: $"{nameof(UrlEncoderDecoderToolViewModel)}.{nameof(EncodeMode)}",
isRoaming: true,
defaultValue: DefaultConversion);
defaultValue: true);

private const string DefaultConversion = "Encode";
internal const string DecodeConversion = "Decode";

private readonly IMarketingService _marketingService;
private readonly ISettingsProvider _settingsProvider;
Expand Down Expand Up @@ -70,18 +68,18 @@ public class UrlEncoderDecoderToolViewModel : ObservableRecipient, IToolViewMode
/// <summary>
/// Gets or sets the conversion mode.
/// </summary>
internal string ConversionMode
internal bool IsEncodeMode
{
get => _settingsProvider.GetSetting(Conversion);
get => _settingsProvider.GetSetting(EncodeMode);
set
{
if (!_setPropertyInProgress)
{
_setPropertyInProgress = true;
ThreadHelper.ThrowIfNotOnUIThread();
if (!string.Equals(_settingsProvider.GetSetting(Conversion), value, StringComparison.Ordinal))
if (_settingsProvider.GetSetting(EncodeMode) != value)
{
_settingsProvider.SetSetting(Conversion, value);
_settingsProvider.SetSetting(EncodeMode, value);
OnPropertyChanged();
}
InputValue = OutputValue;
Expand Down Expand Up @@ -117,7 +115,7 @@ private async Task TreatQueueAsync()
while (_conversionQueue.TryDequeue(out string? text))
{
string conversionResult;
if (string.Equals(ConversionMode, DefaultConversion, StringComparison.Ordinal))
if (IsEncodeMode)
{
conversionResult = await EncodeUrlDataAsync(text).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@
<controls:ExpandableSettingControl.Icon>
<FontIcon Glyph="&#xF18D;" />
</controls:ExpandableSettingControl.Icon>
<ComboBox
SelectedValuePath="Tag"
SelectedValue="{x:Bind ViewModel.ConversionMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem Tag="Encode" Content="{x:Bind ViewModel.Strings.ConversionEncode}" />
<ComboBoxItem Tag="Decode" Content="{x:Bind ViewModel.Strings.ConversionDecode}"/>
</ComboBox>
<ToggleSwitch
Style="{StaticResource RightAlignedToggleSwitchStyle}"
OnContent="{x:Bind ViewModel.Strings.ConversionEncode}" OffContent="{x:Bind ViewModel.Strings.ConversionDecode}"
IsOn="{x:Bind ViewModel.IsEncodeMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</controls:ExpandableSettingControl>
<controls:ExpandableSettingControl
x:Name="EncodingSetting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

if (!string.IsNullOrWhiteSpace(parameters.ClipBoardContent))
{
ViewModel.ConversionMode = Base64EncoderDecoderToolViewModel.DecodeConversion;
ViewModel.IsEncodeMode = false;
ViewModel.InputValue = parameters.ClipBoardContent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:DevToys.UI.Controls"
xmlns:ex="using:DevToys.UI.Extensions"
xmlns:ex="using:DevToys.UI.Extensions"
mc:Ignorable="d"
NavigationCacheMode="Required">

Expand All @@ -31,12 +31,10 @@
<controls:ExpandableSettingControl.Icon>
<FontIcon Glyph="&#xF18D;" />
</controls:ExpandableSettingControl.Icon>
<ComboBox
SelectedValuePath="Tag"
SelectedValue="{x:Bind ViewModel.ConversionMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem Tag="Encode" Content="{x:Bind ViewModel.Strings.ConversionEncode}" />
<ComboBoxItem Tag="Decode" Content="{x:Bind ViewModel.Strings.ConversionDecode}"/>
</ComboBox>
<ToggleSwitch
Style="{StaticResource RightAlignedToggleSwitchStyle}"
OnContent="{x:Bind ViewModel.Strings.ConversionEncode}" OffContent="{x:Bind ViewModel.Strings.ConversionDecode}"
IsOn="{x:Bind ViewModel.IsEncodeMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</controls:ExpandableSettingControl>
</StackPanel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

if (!string.IsNullOrWhiteSpace(parameters.ClipBoardContent))
{
ViewModel.ConversionMode = HtmlEncoderDecoderToolViewModel.DecodeConversion;
ViewModel.IsEncodeMode = false;
ViewModel.InputValue = parameters.ClipBoardContent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<EntranceThemeTransition IsStaggeringEnabled="True" FromVerticalOffset="50"/>
</TransitionCollection>
</Grid.ChildrenTransitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
Expand All @@ -31,12 +31,10 @@
<controls:ExpandableSettingControl.Icon>
<FontIcon Glyph="&#xF18D;" />
</controls:ExpandableSettingControl.Icon>
<ComboBox
SelectedValuePath="Tag"
SelectedValue="{x:Bind ViewModel.ConversionMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem Tag="Encode" Content="{x:Bind ViewModel.Strings.ConversionEncode}" />
<ComboBoxItem Tag="Decode" Content="{x:Bind ViewModel.Strings.ConversionDecode}"/>
</ComboBox>
<ToggleSwitch
Style="{StaticResource RightAlignedToggleSwitchStyle}"
OnContent="{x:Bind ViewModel.Strings.ConversionEncode}" OffContent="{x:Bind ViewModel.Strings.ConversionDecode}"
IsOn="{x:Bind ViewModel.IsEncodeMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</controls:ExpandableSettingControl>
</StackPanel>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

if (!string.IsNullOrWhiteSpace(parameters.ClipBoardContent))
{
ViewModel.ConversionMode = UrlEncoderDecoderToolViewModel.DecodeConversion;
ViewModel.IsEncodeMode = false;
ViewModel.InputValue = parameters.ClipBoardContent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task EncoderAsync(string input, string expectedResult)

await ThreadHelper.RunOnUIThreadAsync(() =>
{
viewModel.ConversionMode = "Encode";
viewModel.IsEncodeMode = true;
viewModel.InputValue = input;
});

Expand All @@ -60,7 +60,7 @@ public async Task DecodeAsync(string input, string expectedResult)

await ThreadHelper.RunOnUIThreadAsync(() =>
{
viewModel.ConversionMode = "Decode";
viewModel.IsEncodeMode = false;
viewModel.InputValue = input;
});

Expand Down