NRCan / GSC-Field-Application

Geological Survey Canada on site data collection for geologists.
Other
9 stars 1 forks source link

let user know if airplane mode is on #315

Closed jameljoseph closed 7 months ago

jameljoseph commented 9 months ago

So if by chance the user has airplane mode on, we should let them know with a popup box

jameljoseph commented 9 months ago

I put some code in to check. Seems to work on my end.

ghuotvez commented 9 months ago

Nice addition, I'll try to test that out.

I did have the same thing implemented in the first version, but then with some windows updates, it started to pop the airplane mode message for no reasons. So I removed it to make things more simple. https://github.com/NRCan/GSC-Field-Application/issues/167

ghuotvez commented 9 months ago

@jameljoseph so, it does work but only when the app is opened while airplane mode is on. If airplane mode is toggled on while the app is running, we can still take a station or navigate to the map page without much trouble.

Last time it was implemented I did set the warning to pop right in the method that tracks the event regarding the location. Here's where the code used to be: https://github.com/NRCan/GSC-Field-Application/commit/9022805af2741c8a8cd6330d10e4b4cd033cb93a#diff-f4dbb8457dc93ffa105061b852d7d6513adb0eebc96775af014f533e9592159cR326

So when user tried to get a location and no data was hit, the code assumed it was on airplane mode or something like that. I like the way you'Re getting to it with the connection method instead. It's probably more stable that way. We just need to move your code to the old place I think.

And here is the code to get the pop-up yellow like all the other warning messages in the app. You need to set the style of the dialog before opening it: https://github.com/NRCan/GSC-Field-Application/blob/f8f7b5b45109d78902492e2a0f86448452d9e8dd/GSCFieldApp/ViewModels/MapPageViewModel.cs#L1480

jameljoseph commented 9 months ago

Yeah it is just meant as a warning when they open the app to let them know.

I will check the style and change it to all the other pop ups.

ghuotvez commented 9 months ago

Yeah it's just a warning, but shouldn't we have it auto-detect more often then not? We did have a geologist that fat fingered airplane mode while on an outcrop and had to call via satellite to get some help before we found what was the problem.

jameljoseph commented 9 months ago

I can set it up so that it detects it every second. I was working with code that would detect it every second but figured it might cause issues because it would be constantly checking and might use up some extra resources

ghuotvez commented 9 months ago

Yeah, you're right on that, every second is overkill. Just when user takes a station at least, there could be a quick check? That would also take less resource then adding your code to the location event that tracks the GPS changes, that also might too much.

jameljoseph commented 9 months ago

Ok so I am looking at MapPageViewModel and see there is a task to validate the geolocation access where there is lots of methods like PoorLocationRoutineTap , NoLocationRoutine..... being called depending on certain criteria like accuracy is poor, location is turned off... Do you want me to just move my code inside the NoLocationRoutine method?

jameljoseph commented 9 months ago

I see inside NoLocationRoutine method you have:

public async Task NoLocationRoutine() { //// Language localization using Resource.resw //var local = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();

        ContentDialog noLocationDialog = new ContentDialog()
        {
            Title = local.GetString("MapPageDialogLocationTitle"),
            Content = local.GetString("MapPageDialogTextLocationStatus"),
            PrimaryButtonText = local.GetString("MapPageDialogTextYes"),
            SecondaryButtonText = local.GetString("MapPageDialogTextNo"),
        };

        noLocationDialog.Style = (Style)Application.Current.Resources["WarningDialog"];

        try
        {
            ContentDialogResult cdr = await Services.ContentDialogMaker.CreateContentDialogAsync(noLocationDialog, true).Result;

            if (cdr == ContentDialogResult.Primary)
            {
                bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
            }
        }
        catch (Exception)
        {
            Debug.WriteLine("Warning dialog for location allocation failed.");
        }

    }
jameljoseph commented 9 months ago

Oh I just see nolocationflightmode() in the page you sent me

ghuotvez commented 9 months ago

Yeah that's what I was talking about. We used to pop the warning from this method, but the check wasn't s good as yours so I had to remove it. Either we get your code in the nolocationflightmode or when user takes a station. As long as we don't check it too often or only once.

jameljoseph commented 9 months ago

I see you commented out a call to run NoLocationFlightMode on line 361 so just below I put a call in to run CheckAirplaneMode:

//await Task.Delay(3000); //Let enough time to pass so GPS actually gets a proper fix
//await NoLocationFlightMode();
connectionProfile = NetworkInformation.GetInternetConnectionProfile();
 CheckAirplaneMode();

I put the method just above the NoLocationFlightMode method you created around line 1536.

I would check it now but im watching the awards and I don't want to toggle airplane mode on and off. Is this what you meant? I built it and there were no errors and ran it with airplane mode off and it worked fine.

ghuotvez commented 9 months ago

Awesome, we'll test it out at this place a bit later. That might be good enough.

ghuotvez commented 9 months ago

Just did a quick test on a tablet, and the app crashes as soon as I put airplane mode while having the app opened.

Afterward, when I want to take a station and the tablet is on airplane mode it also crashes the app.

jameljoseph commented 8 months ago

Oh boy it never crashed on me!! I will work on it more