Merge branch 'feature/GPS-location-xamarin' into dev
This commit is contained in:
commit
6a4088d3b5
@ -1,7 +1,11 @@
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using System;
|
||||
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;
|
||||
|
||||
@ -36,6 +40,7 @@ namespace eShopOnContainers
|
||||
return navigationService.InitializeAsync();
|
||||
}
|
||||
|
||||
|
||||
protected override async void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
@ -44,6 +49,18 @@ namespace eShopOnContainers
|
||||
{
|
||||
await InitNavigation();
|
||||
}
|
||||
|
||||
if (!Settings.UseFakeLocation)
|
||||
{
|
||||
await GetRealLocation();
|
||||
}
|
||||
|
||||
if (!Settings.UseMocks && !string.IsNullOrEmpty(Settings.UserId))
|
||||
{
|
||||
await SendCurrentLocation();
|
||||
}
|
||||
|
||||
base.OnResume();
|
||||
}
|
||||
|
||||
protected override void OnSleep()
|
||||
@ -51,9 +68,29 @@ namespace eShopOnContainers
|
||||
// Handle when your app sleeps
|
||||
}
|
||||
|
||||
protected override void OnResume()
|
||||
private async Task GetRealLocation()
|
||||
{
|
||||
// Handle when your app resumes
|
||||
var locator = CrossGeolocator.Current;
|
||||
locator.AllowsBackgroundUpdates = true;
|
||||
locator.DesiredAccuracy = 50;
|
||||
|
||||
var position = await locator.GetPositionAsync(20000);
|
||||
|
||||
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<ILocationService>();
|
||||
await locationService.UpdateUserLocation(location,
|
||||
Settings.AuthAccessToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -26,8 +26,8 @@ namespace eShopOnContainers.Core.Helpers
|
||||
private const string IdUseMocks = "use_mocks";
|
||||
private const string IdUrlBase = "url_base";
|
||||
private const string IdUseFakeLocation = "use_fake_location";
|
||||
private const string IdFakeLatitude = "fake_latitude";
|
||||
private const string IdFakeLongitude = "fake_longitude";
|
||||
private const string IdLatitude = "latitude";
|
||||
private const string IdLongitude = "flongitude";
|
||||
private static readonly string AccessTokenDefault = string.Empty;
|
||||
private static readonly string IdTokenDefault = string.Empty;
|
||||
private static readonly bool UseMocksDefault = true;
|
||||
@ -40,91 +40,49 @@ namespace eShopOnContainers.Core.Helpers
|
||||
|
||||
public static string UserId
|
||||
{
|
||||
get { return AppSettings.GetValueOrDefault<string>(IdUserId); }
|
||||
set { AppSettings.AddOrUpdateValue<string>(IdUserId, value); }
|
||||
get => AppSettings.GetValueOrDefault<string>(IdUserId);
|
||||
set => AppSettings.AddOrUpdateValue<string>(IdUserId, value);
|
||||
}
|
||||
|
||||
public static string AuthAccessToken
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault<string>(AccessToken, AccessTokenDefault);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue<string>(AccessToken, value);
|
||||
}
|
||||
get => AppSettings.GetValueOrDefault<string>(AccessToken, AccessTokenDefault);
|
||||
set => AppSettings.AddOrUpdateValue<string>(AccessToken, value);
|
||||
}
|
||||
|
||||
public static string AuthIdToken
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault<string>(IdToken, IdTokenDefault);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue<string>(IdToken, value);
|
||||
}
|
||||
get => AppSettings.GetValueOrDefault<string>(IdToken, IdTokenDefault);
|
||||
set => AppSettings.AddOrUpdateValue<string>(IdToken, value);
|
||||
}
|
||||
|
||||
public static bool UseMocks
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault<bool>(IdUseMocks, UseMocksDefault);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue<bool>(IdUseMocks, value);
|
||||
}
|
||||
get => AppSettings.GetValueOrDefault<bool>(IdUseMocks, UseMocksDefault);
|
||||
set => AppSettings.AddOrUpdateValue<bool>(IdUseMocks, value);
|
||||
}
|
||||
|
||||
public static string UrlBase
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault<string>(IdUrlBase, UrlBaseDefault);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue<string>(IdUrlBase, value);
|
||||
}
|
||||
get => AppSettings.GetValueOrDefault<string>(IdUrlBase, UrlBaseDefault);
|
||||
set => AppSettings.AddOrUpdateValue<string>(IdUrlBase, value);
|
||||
}
|
||||
|
||||
public static bool UseFakeLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault<bool>(IdUseFakeLocation, UseFakeLocationDefault);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue<bool>(IdUseFakeLocation, value);
|
||||
}
|
||||
get => AppSettings.GetValueOrDefault<bool>(IdUseFakeLocation, UseFakeLocationDefault);
|
||||
set => AppSettings.AddOrUpdateValue<bool>(IdUseFakeLocation, value);
|
||||
}
|
||||
|
||||
public static double FakeLatitude
|
||||
public static double Latitude
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault<double>(IdFakeLatitude, FakeLatitudeValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue<double>(IdFakeLatitude, value);
|
||||
}
|
||||
get => AppSettings.GetValueOrDefault<double>(IdLatitude, FakeLatitudeValue);
|
||||
set => AppSettings.AddOrUpdateValue<double>(IdLatitude, value);
|
||||
}
|
||||
public static double FakeLongitude
|
||||
public static double Longitude
|
||||
{
|
||||
get
|
||||
{
|
||||
return AppSettings.GetValueOrDefault<double>(IdFakeLongitude, FakeLongitudeValue);
|
||||
}
|
||||
set
|
||||
{
|
||||
AppSettings.AddOrUpdateValue<double>(IdFakeLongitude, value);
|
||||
}
|
||||
get => AppSettings.GetValueOrDefault<double>(IdLongitude, FakeLongitudeValue);
|
||||
set => AppSettings.AddOrUpdateValue<double>(IdLongitude, value);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,8 +27,8 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
{
|
||||
UseAzureServices = !Settings.UseMocks;
|
||||
_useFakeLocation = Settings.UseFakeLocation;
|
||||
_latitude = Settings.FakeLatitude;
|
||||
_longitude = Settings.FakeLongitude;
|
||||
_latitude = Settings.Latitude;
|
||||
_longitude = Settings.Longitude;
|
||||
_locationService = locationService;
|
||||
}
|
||||
|
||||
@ -154,8 +154,8 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
UpdateInfoFakeLocation();
|
||||
|
||||
Endpoint = Settings.UrlBase;
|
||||
_latitude = Settings.FakeLatitude;
|
||||
_longitude = Settings.FakeLongitude;
|
||||
_latitude = Settings.Latitude;
|
||||
_longitude = Settings.Longitude;
|
||||
_useFakeLocation = Settings.UseFakeLocation;
|
||||
return base.InitializeAsync(navigationData);
|
||||
}
|
||||
@ -191,14 +191,17 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
|
||||
private async Task ToggleSendLocationAsync()
|
||||
{
|
||||
Location locationRequest = new Location
|
||||
if (!Settings.UseMocks)
|
||||
{
|
||||
Latitude = _latitude,
|
||||
Longitude = _longitude
|
||||
};
|
||||
var authToken = Settings.AuthAccessToken;
|
||||
var locationRequest = new Location
|
||||
{
|
||||
Latitude = _latitude,
|
||||
Longitude = _longitude
|
||||
};
|
||||
var authToken = Settings.AuthAccessToken;
|
||||
|
||||
await _locationService.UpdateUserLocation(locationRequest, authToken);
|
||||
await _locationService.UpdateUserLocation(locationRequest, authToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateInfo()
|
||||
@ -238,13 +241,13 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
private void UpdateLatitude(double latitude)
|
||||
{
|
||||
// Update fake latitude (save to local storage)
|
||||
Settings.FakeLatitude = latitude;
|
||||
Settings.Latitude = latitude;
|
||||
}
|
||||
|
||||
private void UpdateLongitude(double longitude)
|
||||
{
|
||||
// Update fake longitude (save to local storage)
|
||||
Settings.FakeLongitude = longitude;
|
||||
Settings.Longitude = longitude;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"SlideOverKit": "2.1.4",
|
||||
"Splat": "1.6.2",
|
||||
"Xam.Plugin.Geolocator": "3.0.4",
|
||||
"Xam.Plugins.Settings": "2.6.0.12-beta",
|
||||
"Xamarin.FFImageLoading": "2.2.9",
|
||||
"Xamarin.FFImageLoading.Forms": "2.2.9",
|
||||
|
@ -9,6 +9,7 @@ using Android.Content;
|
||||
using Android.Runtime;
|
||||
using FFImageLoading;
|
||||
using System;
|
||||
using Plugin.Permissions;
|
||||
|
||||
namespace eShopOnContainers.Droid.Activities
|
||||
{
|
||||
@ -56,6 +57,11 @@ namespace eShopOnContainers.Droid.Activities
|
||||
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
|
||||
base.OnTrimMemory(level);
|
||||
}
|
||||
|
||||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
|
||||
{
|
||||
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
|
||||
using Android.App;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Plugin.CurrentActivity;
|
||||
|
||||
namespace eShopOnContainers.Droid
|
||||
{
|
||||
//You can specify additional application information in this attribute
|
||||
[Application]
|
||||
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
|
||||
{
|
||||
public MainApplication(IntPtr handle, JniHandleOwnership transer)
|
||||
:base(handle, transer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
RegisterActivityLifecycleCallbacks(this);
|
||||
//A great place to initialize Xamarin.Insights and Dependency Services!
|
||||
}
|
||||
|
||||
public override void OnTerminate()
|
||||
{
|
||||
base.OnTerminate();
|
||||
UnregisterActivityLifecycleCallbacks(this);
|
||||
}
|
||||
|
||||
public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
|
||||
{
|
||||
CrossCurrentActivity.Current.Activity = activity;
|
||||
}
|
||||
|
||||
public void OnActivityDestroyed(Activity activity)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnActivityPaused(Activity activity)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnActivityResumed(Activity activity)
|
||||
{
|
||||
CrossCurrentActivity.Current.Activity = activity;
|
||||
}
|
||||
|
||||
public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnActivityStarted(Activity activity)
|
||||
{
|
||||
CrossCurrentActivity.Current.Activity = activity;
|
||||
}
|
||||
|
||||
public void OnActivityStopped(Activity activity)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -2,5 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<application android:label="eShopOnContainers" android:icon="@drawable/icon" android:largeHeap="true"></application>
|
||||
</manifest>
|
@ -2,6 +2,14 @@
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Primitives" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
|
||||
|
@ -100,6 +100,21 @@
|
||||
<HintPath>..\..\..\..\packages\modernhttpclient.2.4.2\lib\MonoAndroid\OkHttp.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.CurrentActivity, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.Geolocator, Version=3.0.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Xam.Plugin.Geolocator.3.0.4\lib\MonoAndroid10\Plugin.Geolocator.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.Geolocator.Abstractions, Version=3.0.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Xam.Plugin.Geolocator.3.0.4\lib\MonoAndroid10\Plugin.Geolocator.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.Permissions, Version=1.1.6.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Plugin.Permissions.1.1.7\lib\MonoAndroid10\Plugin.Permissions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.Permissions.Abstractions, Version=1.1.6.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Plugin.Permissions.1.1.7\lib\MonoAndroid10\Plugin.Permissions.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Plugin.Settings, Version=2.6.0.12, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Xam.Plugins.Settings.2.6.0.12-beta\lib\MonoAndroid10\Plugin.Settings.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -207,6 +222,7 @@
|
||||
<Compile Include="Effects\EntryLineColorEffect.cs" />
|
||||
<Compile Include="Extensions\ViewExtensions.cs" />
|
||||
<Compile Include="Helpers\Settings.cs" />
|
||||
<Compile Include="MainApplication.cs" />
|
||||
<Compile Include="Renderers\BadgeView.cs" />
|
||||
<Compile Include="Renderers\CustomNavigationPageRenderer.cs" />
|
||||
<Compile Include="Renderers\CustomTabbedPageRenderer.cs" />
|
||||
|
@ -14,6 +14,8 @@
|
||||
<package id="modernhttpclient" version="2.4.2" targetFramework="monoandroid70" />
|
||||
<package id="NETStandard.Library" version="1.6.0" targetFramework="monoandroid60" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="monoandroid60" />
|
||||
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid60" />
|
||||
<package id="Plugin.Permissions" version="1.1.7" targetFramework="monoandroid60" />
|
||||
<package id="SlideOverKit" version="2.1.4" targetFramework="monoandroid70" />
|
||||
<package id="Splat" version="1.6.2" targetFramework="monoandroid70" />
|
||||
<package id="System.AppContext" version="4.1.0" targetFramework="monoandroid60" />
|
||||
@ -61,6 +63,7 @@
|
||||
<package id="System.Threading.Timer" version="4.0.1" targetFramework="monoandroid60" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.0.11" targetFramework="monoandroid70" />
|
||||
<package id="System.Xml.XDocument" version="4.0.11" targetFramework="monoandroid70" />
|
||||
<package id="Xam.Plugin.Geolocator" version="3.0.4" targetFramework="monoandroid60" />
|
||||
<package id="Xam.Plugins.Settings" version="2.6.0.12-beta" targetFramework="monoandroid70" />
|
||||
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid70" />
|
||||
<package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid70" />
|
||||
|
@ -25,5 +25,6 @@
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
<Capability Name="privateNetworkClientServer" />
|
||||
<DeviceCapability Name="location" />
|
||||
</Capabilities>
|
||||
</Package>
|
Loading…
x
Reference in New Issue
Block a user