Skip to content

Commit

Permalink
#315: code in view model to test out to see if it detects when airpla…
Browse files Browse the repository at this point in the history
…ne mode is on.
  • Loading branch information
jameljoseph committed Dec 13, 2023
1 parent 3879cca commit fb1cb9e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
18 changes: 18 additions & 0 deletions GSCFieldApp/ViewModels/MapPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,6 +127,8 @@ public class MapPageViewModel : ViewModelBase
//Testing
private bool initMap = false;

private ConnectionProfile connectionProfile;

public MapPageViewModel()
{

Expand Down Expand Up @@ -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
//{
Expand Down Expand Up @@ -1527,6 +1532,19 @@ public async Task NoLocationRoutine()
/// <summary>
/// When no location is available probably due to flight mode. Display this message.
/// </summary>

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
Expand Down
31 changes: 17 additions & 14 deletions GSCFieldApp/Views/MapPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit fb1cb9e

Please sign in to comment.