Skip to content

Commit eaed159

Browse files
committed
Implement NetworkStatusChanged callback (fixes #113)
update data only when NetworkConnectivityLevel.InternetAccess is reached
1 parent 178a5a1 commit eaed159

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

FluentWeather/Views/MainPage.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Generic;
1313
using System.Linq;
1414
using System.Threading.Tasks;
15+
using Windows.Networking.Connectivity;
1516
using Windows.UI.Xaml.Media.Animation;
1617
using Windows.UI.Xaml.Media.Imaging;
1718
using FluentWeather.Adapters;
@@ -153,6 +154,16 @@ private void Initialize()
153154
// Initialize the refresh timer
154155
_refreshTimer.Tick += RefreshTimerTickEvent;
155156
UpdateRefreshTimerSettings();
157+
158+
NetworkInformation.NetworkStatusChanged += sender =>
159+
{
160+
var profile = NetworkInformation.GetInternetConnectionProfile();
161+
var level = profile?.GetNetworkConnectivityLevel();
162+
if (level == NetworkConnectivityLevel.InternetAccess)
163+
{
164+
_appViewModel.UpdateUi();
165+
}
166+
};
156167
}
157168

158169
private async void RefreshTimerTickEvent(object sender, object e)

0 commit comments

Comments
 (0)