Skip to content

Commit

Permalink
Added possibility to set the default zoom level for Maps providers (#626
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lpeyr committed Nov 30, 2024
1 parent 1d9b358 commit 546b567
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 32 deletions.
7 changes: 7 additions & 0 deletions InternetTest/InternetTest/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public Settings()
TraceRouteMaxTimeOut = 5000;
MainWindowSize = (950, 600);
LaunchIpLocationOnStart = true;
DownDetectorWebsites = [];
DefaultTimeInterval = 10;
HideDisabledAdapters = false;
MapZoomLevel = 12;
}

public Themes Theme { get; set; }
Expand All @@ -77,6 +81,7 @@ public Settings()
public List<string>? DownDetectorWebsites { get; set; }
public int? DefaultTimeInterval { get; set; }
public bool? HideDisabledAdapters { get; set; }
public int? MapZoomLevel { get; set; }
}

public static class SettingsManager
Expand Down Expand Up @@ -120,6 +125,7 @@ public static Settings Load()
settings.DownDetectorWebsites ??= [];
settings.DefaultTimeInterval ??= 10;
settings.HideDisabledAdapters ??= false;
settings.MapZoomLevel ??= 12;

return settings;
}
Expand Down Expand Up @@ -184,6 +190,7 @@ public static void Import(string path)
settings.DownDetectorWebsites ??= [];
settings.DefaultTimeInterval ??= 10;
settings.HideDisabledAdapters ??= false;
settings.MapZoomLevel ??= 12;

Global.Settings = settings;

Expand Down
97 changes: 65 additions & 32 deletions InternetTest/InternetTest/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,13 @@
</Border>
</StackPanel>
</Expander>
<Border
<Expander
Margin="10 10 10 0"
Background="{DynamicResource CardBackground}"
CornerRadius="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<StackPanel Margin="15 15 10 15" Orientation="Horizontal">
Foreground="{DynamicResource Foreground1}"
Style="{DynamicResource ExpanderStyle1}">
<Expander.Header>
<StackPanel Margin="10 15" Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
Expand All @@ -357,30 +352,68 @@
Text="{x:Static lang:Resources.MapProviderDescription}"
TextWrapping="Wrap" />
</StackPanel>
</StackPanel>

<ComboBox
x:Name="MapProviderComboBox"
Grid.Column="2"
Margin="0 0 10 0"
Padding="5"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="Transparent"
BorderBrush="{DynamicResource Accent}"
BorderThickness="2"
Foreground="{DynamicResource Foreground1}"
SelectionChanged="MapProviderComboBox_SelectionChanged"
Style="{DynamicResource ComboBoxStyle1}">
<ComboBoxItem Content="OpenStreetMap" />
<ComboBoxItem Content="Bing Maps" />
<ComboBoxItem Content="Google Maps" />
<ComboBoxItem Content="HERE WeGo" />
<ComboBoxItem Content="Yandex" />
</ComboBox>
</StackPanel>
</Expander.Header>
<StackPanel Margin="10 0">
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="0 0 10 0"
VerticalAlignment="Center"
FontSize="13"
Text="{x:Static lang:Resources.MapProvider}" />
<ComboBox
x:Name="MapProviderComboBox"
Grid.Column="2"
Margin="0 0 10 0"
Padding="5"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="Transparent"
BorderBrush="{DynamicResource Accent}"
BorderThickness="2"
Foreground="{DynamicResource Foreground1}"
SelectionChanged="MapProviderComboBox_SelectionChanged"
Style="{DynamicResource ComboBoxStyle1}">
<ComboBoxItem Content="OpenStreetMap" />
<ComboBoxItem Content="Bing Maps" />
<ComboBoxItem Content="Google Maps" />
<ComboBoxItem Content="HERE WeGo" />
<ComboBoxItem Content="Yandex" />
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="0 0 10 0"
VerticalAlignment="Center"
FontSize="13"
Text="{x:Static lang:Resources.ZoomLevel}" />
<Border
Margin="10 3 10 3"
Padding="3"
Background="{DynamicResource CardBackground}"
CornerRadius="5">
<Border.Effect>
<DropShadowEffect
BlurRadius="15"
Opacity="0.2"
ShadowDepth="0"
Color="{DynamicResource AccentColor}" />
</Border.Effect>
<TextBox
x:Name="ZoomLevelTxt"
MinWidth="50"
Padding="3"
Background="Transparent"
BorderThickness="0"
Foreground="{DynamicResource Foreground1}"
PreviewTextInput="TextBox_PreviewTextInput"
TextChanged="ZoomLevelTxt_TextChanged" />
</Border>
</StackPanel>
</StackPanel>

</Grid>
</Border>
</Expander>
<Expander
Margin="10 10 10 0"
Background="{DynamicResource CardBackground}"
Expand Down
8 changes: 8 additions & 0 deletions InternetTest/InternetTest/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private async void InitUI()

// Select the map provider
MapProviderComboBox.SelectedIndex = (int)Global.Settings.MapProvider;
ZoomLevelTxt.Text = Global.Settings.MapZoomLevel.ToString();

// Notfication section
UpdateNotifChk.IsChecked = Global.Settings.ShowNotficationWhenUpdateAvailable;
Expand Down Expand Up @@ -478,4 +479,11 @@ private void GitHubBtn_Click(object sender, RoutedEventArgs e)
{
Process.Start("explorer.exe", "https://github.com/Leo-Corporation/InternetTest/");
}

private void ZoomLevelTxt_TextChanged(object sender, TextChangedEventArgs e)
{
if (string.IsNullOrEmpty(ZoomLevelTxt.Text)) return;
Global.Settings.MapZoomLevel = int.Parse(ZoomLevelTxt.Text);
SettingsManager.Save();
}
}

0 comments on commit 546b567

Please sign in to comment.