Fixed issue where location permissions was called infinite times on decline.

This commit is contained in:
Tobias Reski 2021-11-09 14:22:53 +01:00
parent 8aa3089f32
commit 34590fbc7d
3 changed files with 89 additions and 45 deletions

View file

@ -322,9 +322,9 @@ namespace TINK.ViewModel.Map
&& !GeolocationService.IsSimulation
&& 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(
AppResources.MessageTitleHint,
@ -420,19 +420,8 @@ namespace TINK.ViewModel.Map
// Move and scale before getting stations and bikes which takes some time.
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();
@ -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>
public static void MoveAndScale(
Action<MapSpan> moveToRegionDelegate,