From fb1cb9e15e46b82aa821f1e4a9684988d2874433 Mon Sep 17 00:00:00 2001 From: Jamel Joseph Date: Wed, 13 Dec 2023 11:04:45 -0800 Subject: [PATCH] #315: code in view model to test out to see if it detects when airplane mode is on. --- GSCFieldApp/ViewModels/MapPageViewModel.cs | 18 +++++++++++++ GSCFieldApp/Views/MapPage.xaml.cs | 31 ++++++++++++---------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/GSCFieldApp/ViewModels/MapPageViewModel.cs b/GSCFieldApp/ViewModels/MapPageViewModel.cs index 3b894dcd..4feac822 100644 --- a/GSCFieldApp/ViewModels/MapPageViewModel.cs +++ b/GSCFieldApp/ViewModels/MapPageViewModel.cs @@ -27,6 +27,7 @@ using Template10.Mvvm; using Windows.ApplicationModel.Resources; using Windows.Devices.Geolocation; +using Windows.Networking.Connectivity; using Windows.Storage; using Windows.System; using Windows.UI.Core; @@ -126,6 +127,8 @@ public class MapPageViewModel : ViewModelBase //Testing private bool initMap = false; + private ConnectionProfile connectionProfile; + public MapPageViewModel() { @@ -356,6 +359,8 @@ public async void Geolocal_StatusChangedAsync(Geolocator sender, Windows.Devices //await Task.Delay(3000); //Let enough time to pass so GPS actually gets a proper fix //await NoLocationFlightMode(); + connectionProfile = NetworkInformation.GetInternetConnectionProfile(); + CheckAirplaneMode(); //try //{ @@ -1527,6 +1532,19 @@ public async Task NoLocationRoutine() /// /// When no location is available probably due to flight mode. Display this message. /// + + private async void CheckAirplaneMode() + { + var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); + + if (connectionProfile == null) + { + // Possible airplane mode + var messageDialog = new Windows.UI.Popups.MessageDialog("Airplane Mode or No Network Connection Found"); + messageDialog.Commands.Add(new Windows.UI.Popups.UICommand("OK")); + await messageDialog.ShowAsync(); + } + } public async Task NoLocationFlightMode() { // Language localization using Resource.resw diff --git a/GSCFieldApp/Views/MapPage.xaml.cs b/GSCFieldApp/Views/MapPage.xaml.cs index 193ba3e2..3a26dc4b 100644 --- a/GSCFieldApp/Views/MapPage.xaml.cs +++ b/GSCFieldApp/Views/MapPage.xaml.cs @@ -28,8 +28,11 @@ public sealed partial class MapPage : Page public Map esriMap; public bool mapsLoaded = false; //private DispatcherTimer timer; + readonly DataLocalSettings localSetting = new DataLocalSettings(); - private ConnectionProfile connectionProfile; + //This put in the view model + //private ConnectionProfile connectionProfile; + //UI headers enable/disable colors private readonly string resourceNameGridColor = "MapViewGridColor"; @@ -48,9 +51,9 @@ public MapPage() NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled; //Window.Current.Activated += CurrentWindow_Activated; - // Subscribe to the NetworkStatusChanged event - connectionProfile = NetworkInformation.GetInternetConnectionProfile(); - CheckAirplaneMode(); + // These were put in the view model + //connectionProfile = NetworkInformation.GetInternetConnectionProfile(); + //CheckAirplaneMode(); this.Loaded -= MapPage_Loaded; @@ -354,18 +357,18 @@ public void SetBackgroundGrid() } } - private async void CheckAirplaneMode() - { - var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); + //private async void CheckAirplaneMode() + //{ + //var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); - if (connectionProfile == null) - { + //if (connectionProfile == null) + //{ // Possible airplane mode - var messageDialog = new Windows.UI.Popups.MessageDialog("Airplane Mode or No Network Connection Found"); - messageDialog.Commands.Add(new Windows.UI.Popups.UICommand("OK")); - await messageDialog.ShowAsync(); - } - } + //var messageDialog = new Windows.UI.Popups.MessageDialog("Airplane Mode or No Network Connection Found"); + //messageDialog.Commands.Add(new Windows.UI.Popups.UICommand("OK")); + //await messageDialog.ShowAsync(); + //} + //} #endregion