Skip to content

Commit 642ca77

Browse files
committed
Added the possibility to refresh networks (#671)
1 parent 1b86160 commit 642ca77

File tree

3 files changed

+108
-13
lines changed

3 files changed

+108
-13
lines changed

InternetTest/InternetTest/ViewModels/Components/ConnectWiFiItemViewModel.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ public ConnectWiFiItemViewModel(WiFiNetwork wiFiNetwork, string? currentSsid)
6565
IsConnected = _wiFiNetwork.Ssid == currentSsid;
6666
StrengthIcon = _wiFiNetwork.SignalQuality switch
6767
{
68-
int n when (n is >= 0 and < 25) => "\uF8B3",
69-
int n when (n is >= 25 and < 50) => "\uF8B1",
70-
int n when (n is >= 50 and < 75) => "\uF8AF",
71-
int n when (n is >= 75 and <= 100) => "\uF8AD",
68+
int n when n is >= 0 and < 25 => "\uF8B3",
69+
int n when n is >= 25 and < 50 => "\uF8B1",
70+
int n when n is >= 50 and < 75 => "\uF8AF",
71+
int n when n is >= 75 and <= 100 => "\uF8AD",
7272
_ => "\uF8AD",
7373
};
7474

7575
StrengthColor = _wiFiNetwork.SignalQuality switch
7676
{
77-
int n when (n is >= 0 and < 25) => ThemeHelper.GetSolidColorBrush("Red"),
78-
int n when (n is >= 25 and < 50) => ThemeHelper.GetSolidColorBrush("Orange"),
79-
int n when (n is >= 50 and < 75) => ThemeHelper.GetSolidColorBrush("Accent"),
80-
int n when (n is >= 75 and <= 100) => ThemeHelper.GetSolidColorBrush("Green"),
77+
int n when n is >= 0 and < 25 => ThemeHelper.GetSolidColorBrush("Red"),
78+
int n when n is >= 25 and < 50 => ThemeHelper.GetSolidColorBrush("Orange"),
79+
int n when n is >= 50 and < 75 => ThemeHelper.GetSolidColorBrush("Accent"),
80+
int n when n is >= 75 and <= 100 => ThemeHelper.GetSolidColorBrush("Green"),
8181
_ => ThemeHelper.GetSolidColorBrush("Green"), // Default to green
8282
};
8383

InternetTest/InternetTest/ViewModels/WiFiPageViewModel.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@ public ObservableCollection<NetworkAdapterItemViewModel> Adapters
4242
set { _adapters = value; OnPropertyChanged(nameof(Adapters)); }
4343
}
4444

45-
public ObservableCollection<ConnectWiFiItemViewModel> WiFiNetworks { get; } = [];
45+
public ObservableCollection<ConnectWiFiItemViewModel> WiFiNetworks { get; set; } = [];
4646

4747
private bool _showHidden = false;
4848
public bool ShowHidden { get => _showHidden; set { _showHidden = value; OnPropertyChanged(nameof(ShowHidden)); GetAdapters(); } }
4949

50-
public ICommand RefreshCommand { get; }
50+
private bool _isRefrshing = false;
51+
public bool IsRefreshing { get => _isRefrshing; set { _isRefrshing = value; OnPropertyChanged(nameof(IsRefreshing)); } }
52+
53+
private bool _noNetworks = false;
54+
public bool NoNetworks { get => _noNetworks; set { _noNetworks = value; OnPropertyChanged(nameof(NoNetworks)); } }
55+
56+
public ICommand RefreshCommand => new RelayCommand(o => GetAdapters());
57+
public ICommand RefreshWiFiCommand { get; set; }
5158
public WiFiPageViewModel(Settings settings)
5259
{
5360
_settings = settings;
@@ -57,9 +64,18 @@ public WiFiPageViewModel(Settings settings)
5764
GetAdapters();
5865

5966
string? currentSsid = NetworkHelper.GetCurrentWifiSSID();
60-
6167
WiFiNetworks = [.. WiFiNetwork.GetWiFis().Select(x => new ConnectWiFiItemViewModel(x, currentSsid))];
62-
RefreshCommand = new RelayCommand(o => GetAdapters());
68+
NoNetworks = WiFiNetworks.Count == 0;
69+
70+
RefreshWiFiCommand = new RelayCommand(o =>
71+
{
72+
IsRefreshing = true;
73+
WiFiNetworks.Clear();
74+
string? currentSsid = NetworkHelper.GetCurrentWifiSSID();
75+
WiFiNetwork.GetWiFis().ForEach(x => WiFiNetworks.Add(new ConnectWiFiItemViewModel(x, currentSsid)));
76+
IsRefreshing = false;
77+
NoNetworks = WiFiNetworks.Count == 0;
78+
});
6379
}
6480

6581
internal void GetAdapters()

InternetTest/InternetTest/Views/WiFiPage.xaml

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:components="clr-namespace:InternetTest.Components"
6+
xmlns:converters="clr-namespace:InternetTest.Converters"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:lang="clr-namespace:InternetTest.Properties"
89
xmlns:local="clr-namespace:InternetTest.Views"
@@ -16,6 +17,7 @@
1617
<Grid>
1718
<Grid.Resources>
1819
<BooleanToVisibilityConverter x:Key="BoolToVis" />
20+
<converters:InverseBoolToVisibilityConverter x:Key="InverseBoolToVis" />
1921
</Grid.Resources>
2022
<Grid.RowDefinitions>
2123
<RowDefinition Height="Auto" />
@@ -106,6 +108,10 @@
106108
<RowDefinition Height="Auto" />
107109
<RowDefinition />
108110
</Grid.RowDefinitions>
111+
<Grid.ColumnDefinitions>
112+
<ColumnDefinition />
113+
<ColumnDefinition Width="Auto" />
114+
</Grid.ColumnDefinitions>
109115
<StackPanel>
110116
<StackPanel Orientation="Horizontal">
111117
<TextBlock
@@ -123,7 +129,26 @@
123129
<TextBlock Foreground="{DynamicResource DarkGray}" Text="{x:Static lang:Resources.AvailableNetworksDesc}" />
124130
</StackPanel>
125131

126-
<ItemsControl Grid.Row="1" ItemsSource="{Binding WiFiNetworks}">
132+
<Button
133+
Grid.Column="1"
134+
Padding="5"
135+
VerticalAlignment="Center"
136+
Background="Transparent"
137+
Command="{Binding RefreshWiFiCommand}"
138+
Content="&#xF191;"
139+
Cursor="Hand"
140+
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
141+
Foreground="{DynamicResource Foreground1}">
142+
<Button.ToolTip>
143+
<ToolTip Content="{x:Static lang:Resources.Refresh}" />
144+
</Button.ToolTip>
145+
</Button>
146+
147+
<ItemsControl
148+
Grid.Row="1"
149+
Grid.ColumnSpan="2"
150+
ItemsSource="{Binding WiFiNetworks}"
151+
Visibility="{Binding IsRefreshing, Converter={StaticResource InverseBoolToVis}}">
127152
<ItemsControl.ItemsPanel>
128153
<ItemsPanelTemplate>
129154
<StackPanel />
@@ -135,6 +160,60 @@
135160
</DataTemplate>
136161
</ItemsControl.ItemTemplate>
137162
</ItemsControl>
163+
<StackPanel
164+
x:Name="ScanningPanel"
165+
Grid.Row="2"
166+
HorizontalAlignment="Center"
167+
VerticalAlignment="Center"
168+
Visibility="{Binding IsRefreshing, Converter={StaticResource BoolToVis}}">
169+
<TextBlock
170+
HorizontalAlignment="Center"
171+
FontFamily="../Fonts/#FluentSystemIcons-Regular"
172+
FontSize="48"
173+
Foreground="{DynamicResource Accent}"
174+
RenderTransformOrigin="0.5,0.5"
175+
Text="&#xF709;">
176+
<TextBlock.RenderTransform>
177+
<RotateTransform x:Name="SpinTransform" Angle="0" />
178+
</TextBlock.RenderTransform>
179+
180+
<TextBlock.Triggers>
181+
<EventTrigger RoutedEvent="TextBlock.Loaded">
182+
<BeginStoryboard>
183+
<Storyboard>
184+
<DoubleAnimation
185+
RepeatBehavior="Forever"
186+
Storyboard.TargetName="SpinTransform"
187+
Storyboard.TargetProperty="Angle"
188+
From="0"
189+
To="360"
190+
Duration="0:0:1" />
191+
</Storyboard>
192+
</BeginStoryboard>
193+
</EventTrigger>
194+
</TextBlock.Triggers>
195+
</TextBlock>
196+
<TextBlock
197+
HorizontalAlignment="Center"
198+
Text="{x:Static lang:Resources.ScanningInProgress}"
199+
TextWrapping="Wrap" />
200+
</StackPanel>
201+
<StackPanel
202+
x:Name="NoNetworksPanel"
203+
Grid.Row="2"
204+
HorizontalAlignment="Center"
205+
VerticalAlignment="Center"
206+
Visibility="{Binding NoNetworks, Converter={StaticResource BoolToVis}}">
207+
<TextBlock
208+
HorizontalAlignment="Center"
209+
FontFamily="../Fonts/#FluentSystemIcons-Regular"
210+
FontSize="48"
211+
Text="&#xFB69;" />
212+
<TextBlock
213+
HorizontalAlignment="Center"
214+
Text="{x:Static lang:Resources.NoNetworks}"
215+
TextWrapping="Wrap" />
216+
</StackPanel>
138217
</Grid>
139218

140219
</Border>

0 commit comments

Comments
 (0)