From d75f48035fe35875514640ca0683b319b6b834ae Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Wed, 21 Jun 2017 11:04:42 +0200 Subject: [PATCH] Clean up and add location permissions in windows phone project --- .../eShopOnContainers.Core/App.xaml.cs | 30 +++++++++++++++---- .../Package.appxmanifest | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs index 8f965004f..b1b24d758 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Core/App.xaml.cs @@ -3,6 +3,8 @@ using eShopOnContainers.Core.Helpers; using eShopOnContainers.Services; using eShopOnContainers.Core.ViewModels.Base; using System.Threading.Tasks; +using eShopOnContainers.Core.Models.Location; +using eShopOnContainers.Core.Services.Location; using Plugin.Geolocator; using Xamarin.Forms; using Xamarin.Forms.Xaml; @@ -52,6 +54,13 @@ namespace eShopOnContainers { await GetRealLocation(); } + + if (!Settings.UseMocks && !string.IsNullOrEmpty(Settings.UserId)) + { + await SendCurrentLocation(); + } + + base.OnResume(); } protected override void OnSleep() @@ -59,14 +68,10 @@ namespace eShopOnContainers // Handle when your app sleeps } - protected override void OnResume() - { - // Handle when your app resumes - } - private async Task GetRealLocation() { var locator = CrossGeolocator.Current; + locator.AllowsBackgroundUpdates = true; locator.DesiredAccuracy = 50; var position = await locator.GetPositionAsync(20000); @@ -74,5 +79,18 @@ namespace eShopOnContainers Settings.Latitude = position.Latitude; Settings.Longitude = position.Longitude; } + + private async Task SendCurrentLocation() + { + var location = new Location + { + Latitude = Settings.Latitude, + Longitude = Settings.Longitude + }; + + var locationService = ViewModelLocator.Resolve(); + await locationService.UpdateUserLocation(location, + Settings.AuthAccessToken); + } } -} +} \ No newline at end of file diff --git a/src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest b/src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest index 81e4ad8a9..9f70dad6b 100644 --- a/src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest +++ b/src/Mobile/eShopOnContainers/eShopOnContainers.Windows/Package.appxmanifest @@ -25,5 +25,6 @@ + \ No newline at end of file