mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-01-22 12:34:26 +01:00
Fixed issue where location permissions was called infinite times on decline.
This commit is contained in:
parent
8aa3089f32
commit
34590fbc7d
3 changed files with 89 additions and 45 deletions
|
@ -282,7 +282,7 @@ namespace TINK
|
||||||
if (_PermissionsService != null)
|
if (_PermissionsService != null)
|
||||||
return _PermissionsService;
|
return _PermissionsService;
|
||||||
|
|
||||||
_PermissionsService = new Services.Permissions.Plugin.Permissions();
|
_PermissionsService = new Services.Permissions.Essentials.Permissions();
|
||||||
return _PermissionsService;
|
return _PermissionsService;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,9 @@ namespace TINK.View.Map
|
||||||
/// <summary> View model to notify about whether page appears or hides. </summary>
|
/// <summary> View model to notify about whether page appears or hides. </summary>
|
||||||
private MapPageViewModel MapPageViewModel { get; set; }
|
private MapPageViewModel MapPageViewModel { get; set; }
|
||||||
|
|
||||||
|
/// <summary> Initialization status to ensure initialization logic is not called multiple times. </summary>
|
||||||
|
private bool viewInitialized = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs map page instance.
|
/// Constructs map page instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -125,30 +128,22 @@ namespace TINK.View.Map
|
||||||
public INavigationMasterDetail NavigationMasterDetail { private get; set; }
|
public INavigationMasterDetail NavigationMasterDetail { private get; set; }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when page is shown.
|
/// Invoked when page is shown.
|
||||||
/// Starts update process.
|
/// Starts update process.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected async override void OnAppearing()
|
protected async override void OnAppearing()
|
||||||
{
|
{
|
||||||
|
// Don't repeat the initialization if it has been completed already.
|
||||||
|
if (viewInitialized) return;
|
||||||
|
|
||||||
// Pass reference to member Navigation to show bikes at station x dialog.
|
// Pass reference to member Navigation to show bikes at station x dialog.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Log.ForContext<MapPage>().Verbose("Constructing map page view model.");
|
MapPageViewModel = createMapPageViewModel();
|
||||||
|
}
|
||||||
#if TRYNOTBACKSTYLE
|
catch (Exception exception)
|
||||||
MapPageViewModel = new MapPageViewModel();
|
|
||||||
#else
|
|
||||||
MapPageViewModel = new MapPageViewModel(
|
|
||||||
App.ModelRoot,
|
|
||||||
App.PermissionsService,
|
|
||||||
App.BluetoothService,
|
|
||||||
App.GeolocationServicesContainer.Active,
|
|
||||||
(mapspan) => MyMap.MoveToRegion(mapspan),
|
|
||||||
this,
|
|
||||||
Navigation);
|
|
||||||
#endif
|
|
||||||
} catch (Exception exception)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
Log.ForContext<MapPage>().Error("Constructing map page view model failed. {Exception}", exception);
|
Log.ForContext<MapPage>().Error("Constructing map page view model failed. {Exception}", exception);
|
||||||
|
@ -171,15 +166,7 @@ namespace TINK.View.Map
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Device.RuntimePlatform == Device.iOS)
|
applyCustomiOSStyling();
|
||||||
{
|
|
||||||
TINKButton.BackgroundColor = Color.LightGray;
|
|
||||||
TINKButton.BorderColor = Color.Black;
|
|
||||||
TINKButton.Margin = new Thickness(10, 10, 10, 10);
|
|
||||||
KonradButton.BackgroundColor = Color.LightGray;
|
|
||||||
KonradButton.BorderColor = Color.Black;
|
|
||||||
KonradButton.Margin = new Thickness(10, 10, 10, 10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -201,11 +188,7 @@ namespace TINK.View.Map
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Pre move and scanle maps to avoid initial display of map in Rome.
|
// Pre move and scanle maps to avoid initial display of map in Rome.
|
||||||
Log.ForContext<MapPage>().Verbose("Moving and scaling map.");
|
premoveAndScaleMap();
|
||||||
MapPageViewModel.MoveAndScale(
|
|
||||||
(mapSpan) => MyMap.MoveToRegion(mapSpan),
|
|
||||||
App.ModelRoot.Uris.ActiveUri,
|
|
||||||
App.ModelRoot.GroupFilterMapPage);
|
|
||||||
}
|
}
|
||||||
catch(Exception exception)
|
catch(Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -223,6 +206,54 @@ namespace TINK.View.Map
|
||||||
Log.ForContext<MapPage>().Error("Invoking OnAppearing on map page view model failed. {Exception}", exception);
|
Log.ForContext<MapPage>().Error("Invoking OnAppearing on map page view model failed. {Exception}", exception);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
viewInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Premoves the Map to a certain location.
|
||||||
|
/// </summary>
|
||||||
|
private void premoveAndScaleMap()
|
||||||
|
{
|
||||||
|
Log.ForContext<MapPage>().Verbose("Moving and scaling map.");
|
||||||
|
MapPageViewModel.MoveAndScale(
|
||||||
|
(mapSpan) => MyMap.MoveToRegion(mapSpan),
|
||||||
|
App.ModelRoot.Uris.ActiveUri,
|
||||||
|
App.ModelRoot.GroupFilterMapPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the Map Page's view model.
|
||||||
|
/// </summary>
|
||||||
|
private MapPageViewModel createMapPageViewModel()
|
||||||
|
{
|
||||||
|
Log.ForContext<MapPage>().Verbose("Constructing map page view model.");
|
||||||
|
return new MapPageViewModel(
|
||||||
|
App.ModelRoot,
|
||||||
|
App.PermissionsService,
|
||||||
|
App.BluetoothService,
|
||||||
|
App.GeolocationServicesContainer.Active,
|
||||||
|
(mapspan) => MyMap.MoveToRegion(mapspan),
|
||||||
|
this,
|
||||||
|
Navigation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies iOS specific styling to branded Buttons.
|
||||||
|
/// </summary>
|
||||||
|
private void applyCustomiOSStyling()
|
||||||
|
{
|
||||||
|
if (Device.RuntimePlatform == Device.iOS)
|
||||||
|
{
|
||||||
|
TINKButton.BackgroundColor = Color.LightGray;
|
||||||
|
TINKButton.BorderColor = Color.Black;
|
||||||
|
TINKButton.Margin = new Thickness(10, 10, 10, 10);
|
||||||
|
KonradButton.BackgroundColor = Color.LightGray;
|
||||||
|
KonradButton.BorderColor = Color.Black;
|
||||||
|
KonradButton.Margin = new Thickness(10, 10, 10, 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -236,7 +267,7 @@ namespace TINK.View.Map
|
||||||
// View model might be null.
|
// View model might be null.
|
||||||
await MapPageViewModel?.OnDisappearing();
|
await MapPageViewModel?.OnDisappearing();
|
||||||
}
|
}
|
||||||
|
viewInitialized = false;
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,9 +322,9 @@ namespace TINK.ViewModel.Map
|
||||||
&& !GeolocationService.IsSimulation
|
&& !GeolocationService.IsSimulation
|
||||||
&& status != Status.Granted)
|
&& status != Status.Granted)
|
||||||
{
|
{
|
||||||
var permissionResult = await PermissionsService.RequestAsync();
|
status = await PermissionsService.RequestAsync();
|
||||||
|
|
||||||
if (permissionResult != Status.Granted)
|
if (status != Status.Granted)
|
||||||
{
|
{
|
||||||
var dialogResult = await ViewService.DisplayAlert(
|
var dialogResult = await ViewService.DisplayAlert(
|
||||||
AppResources.MessageTitleHint,
|
AppResources.MessageTitleHint,
|
||||||
|
@ -420,19 +420,8 @@ namespace TINK.ViewModel.Map
|
||||||
|
|
||||||
// Move and scale before getting stations and bikes which takes some time.
|
// Move and scale before getting stations and bikes which takes some time.
|
||||||
ActionText = AppResources.ActivityTextCenterMap;
|
ActionText = AppResources.ActivityTextCenterMap;
|
||||||
Location currentLocation = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
currentLocation = TinkApp.CenterMapToCurrentLocation
|
|
||||||
? await GeolocationService.GetAsync()
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.Uris.ActiveUri, ActiveFilterMap, currentLocation);
|
moveMapToCurrentPositionOfUser();
|
||||||
|
|
||||||
m_oViewUpdateManager = CreateUpdateTask();
|
m_oViewUpdateManager = CreateUpdateTask();
|
||||||
|
|
||||||
|
@ -468,6 +457,30 @@ namespace TINK.ViewModel.Map
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the map to the current position of the user.
|
||||||
|
/// If location permission hasn't been granted, the position is not adjusted.
|
||||||
|
/// </summary>
|
||||||
|
private async void moveMapToCurrentPositionOfUser()
|
||||||
|
{
|
||||||
|
var status = await PermissionsService.CheckStatusAsync();
|
||||||
|
if (status != Status.Granted) return;
|
||||||
|
Location currentLocation = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
currentLocation = TinkApp.CenterMapToCurrentLocation
|
||||||
|
? await GeolocationService.GetAsync()
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.Uris.ActiveUri, ActiveFilterMap, currentLocation);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Moves map and scales visible region depending on active filter. </summary>
|
/// <summary> Moves map and scales visible region depending on active filter. </summary>
|
||||||
public static void MoveAndScale(
|
public static void MoveAndScale(
|
||||||
Action<MapSpan> moveToRegionDelegate,
|
Action<MapSpan> moveToRegionDelegate,
|
||||||
|
|
Loading…
Add table
Reference in a new issue