mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-19 11:37:28 +02:00
Manually merged.
This commit is contained in:
parent
d5832e010e
commit
c7c9f252af
112 changed files with 1127 additions and 352 deletions
|
@ -314,17 +314,84 @@ namespace TINK.ViewModel.Map
|
|||
ActiveFilterMap = TinkApp.GroupFilterMapPage;
|
||||
|
||||
ActionText = AppResources.ActivityTextRequestingLocationPermissions;
|
||||
Status status = await RequestLocationPermission();
|
||||
|
||||
// Check location permission
|
||||
var status = await PermissionsService.CheckStatusAsync();
|
||||
if (TinkApp.CenterMapToCurrentLocation
|
||||
&& !GeolocationService.IsSimulation
|
||||
&& status != Status.Granted)
|
||||
{
|
||||
var permissionResult = await PermissionsService.RequestAsync();
|
||||
|
||||
if (permissionResult != Status.Granted)
|
||||
{
|
||||
var dialogResult = await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageCenterMapLocationPermissionOpenDialog,
|
||||
AppResources.MessageAnswerYes,
|
||||
AppResources.MessageAnswerNo);
|
||||
|
||||
if (dialogResult)
|
||||
{
|
||||
// User decided to give access to locations permissions.
|
||||
PermissionsService.OpenAppSettings();
|
||||
ActionText = "";
|
||||
IsRunning = false;
|
||||
IsMapPageEnabled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;
|
||||
IsConnected = TinkApp.GetIsConnected();
|
||||
var resultStationsAndBikes = await TinkApp.GetConnector(IsConnected).Query.GetBikesAndStationsAsync();
|
||||
|
||||
TinkApp.Stations = resultStationsAndBikes.Response.StationsAll;
|
||||
|
||||
if (Pins.Count > 0 && Pins.Count != resultStationsAndBikes.Response.StationsAll.Count)
|
||||
{
|
||||
// Either
|
||||
// - user logged in/ logged out which might lead to more/ less stations beeing available
|
||||
// - new stations were added/ existing ones remove
|
||||
Pins.Clear();
|
||||
}
|
||||
|
||||
// Check if there are alreay any pins to the map
|
||||
// i.e detecte first call of member OnAppearing after construction
|
||||
if (Pins.Count <= 0)
|
||||
{
|
||||
Log.ForContext<MapPageViewModel>().Debug($"{(ActiveFilterMap.GetGroup().Any() ? $"Active map filter is {string.Join(",", ActiveFilterMap.GetGroup())}." : "Map filter is off.")}");
|
||||
|
||||
// Map was not yet initialized.
|
||||
// Get stations from Copri
|
||||
Log.ForContext<MapPageViewModel>().Verbose("No pins detected on page.");
|
||||
if (resultStationsAndBikes.Response.StationsAll.CopriVersion < CopriCallsStatic.UnsupportedVersionLower)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageWaring,
|
||||
string.Format(AppResources.MessageCopriVersionIsOutdated, ContactPageViewModel.GetAppName(TinkApp.Uris.ActiveUri)),
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
Log.ForContext<MapPageViewModel>().Error($"Outdated version of app detected. Version expected is {resultStationsAndBikes.Response.StationsAll.CopriVersion}.");
|
||||
}
|
||||
|
||||
if (resultStationsAndBikes.Response.StationsAll.CopriVersion >= CopriCallsStatic.UnsupportedVersionUpper)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageWaring,
|
||||
string.Format(AppResources.MessageAppVersionIsOutdated, ContactPageViewModel.GetAppName(TinkApp.Uris.ActiveUri)),
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
Result<StationsAndBikesContainer> resultStationsAndBikes = await TinkApp.GetConnector(IsConnected).Query.GetBikesAndStationsAsync();
|
||||
|
||||
TinkApp.Stations = resultStationsAndBikes.Response.StationsAll;
|
||||
|
||||
await SetStationsOnMap(resultStationsAndBikes.Response.StationsAll);
|
||||
await HandleAuthCookieNotDefinedException(resultStationsAndBikes.Exception);
|
||||
// COPRI reports an auth cookie error.
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageWaring,
|
||||
AppResources.MessageMapPageErrorAuthcookieUndefined,
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
|
||||
// Update pin colors.
|
||||
|
@ -337,6 +404,31 @@ namespace TINK.ViewModel.Map
|
|||
// Update pins color form count of bikes located at station.
|
||||
UpdatePinsColor(colors);
|
||||
|
||||
// Move and scale before getting stations and bikes which takes some time.
|
||||
ActionText = AppResources.ActivityTextCenterMap;
|
||||
if (TinkApp.CenterMapToCurrentLocation)
|
||||
{
|
||||
Location currentLocation = null;
|
||||
try
|
||||
{
|
||||
currentLocation = await GeolocationService.GetAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
|
||||
}
|
||||
|
||||
TinkApp.MapSpan = MapSpan.FromCenterAndRadius(
|
||||
new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
|
||||
TinkApp.MapSpan.Radius);
|
||||
|
||||
TinkApp.Save();
|
||||
}
|
||||
|
||||
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.MapSpan);
|
||||
|
||||
m_oViewUpdateManager = CreateUpdateTask();
|
||||
|
||||
Log.ForContext<MapPageViewModel>().Verbose("Update pins color done.");
|
||||
|
||||
// Move and scale before getting stations and bikes which takes some time.
|
||||
|
@ -375,144 +467,6 @@ namespace TINK.ViewModel.Map
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the auth cookie is not defined.
|
||||
/// </summary>
|
||||
private async Task HandleAuthCookieNotDefinedException(Exception exception)
|
||||
{
|
||||
if (exception?.GetType() == typeof(AuthcookieNotDefinedException))
|
||||
{
|
||||
Log.ForContext<MapPageViewModel>().Error("Map page is shown (probable for the first time after startup of app) and COPRI auth cookie is not defined. {@l_oException}", exception);
|
||||
|
||||
// COPRI reports an auth cookie error.
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageWaring,
|
||||
AppResources.MessageMapPageErrorAuthcookieUndefined,
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
await TinkApp.GetConnector(IsConnected).Command.DoLogout();
|
||||
TinkApp.ActiveUser.Logout();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the available stations on the map.
|
||||
/// </summary>
|
||||
private async Task SetStationsOnMap(StationDictionary stations)
|
||||
{
|
||||
if (Pins.Count > 0 && Pins.Count != stations.Count)
|
||||
{
|
||||
// Either
|
||||
// - user logged in/ logged out which might lead to more/ less stations beeing available
|
||||
// - new stations were added/ existing ones remove
|
||||
Pins.Clear();
|
||||
}
|
||||
|
||||
// Check if there are alreay any pins to the map
|
||||
// i.e detecte first call of member OnAppearing after construction
|
||||
if (Pins.Count <= 0)
|
||||
{
|
||||
Log.ForContext<MapPageViewModel>().Debug($"{(ActiveFilterMap.GetGroup().Any() ? $"Active map filter is {string.Join(",", ActiveFilterMap.GetGroup())}." : "Map filter is off.")}");
|
||||
|
||||
// Map was not yet initialized.
|
||||
// Get stations from Copri
|
||||
Log.ForContext<MapPageViewModel>().Verbose("No pins detected on page.");
|
||||
if (stations.CopriVersion < CopriCallsStatic.UnsupportedVersionLower)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageWaring,
|
||||
string.Format(AppResources.MessageCopriVersionIsOutdated, ContactPageViewModel.GetAppName(TinkApp.Uris.ActiveUri)),
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
Log.ForContext<MapPageViewModel>().Error($"Outdated version of app detected. Version expected is {stations.CopriVersion}.");
|
||||
}
|
||||
|
||||
if (stations.CopriVersion >= CopriCallsStatic.UnsupportedVersionUpper)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageWaring,
|
||||
string.Format(AppResources.MessageAppVersionIsOutdated, ContactPageViewModel.GetAppName(TinkApp.Uris.ActiveUri)),
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
Log.ForContext<MapPageViewModel>().Error($"Outdated version of app detected. Version expected is {stations.CopriVersion}.");
|
||||
}
|
||||
|
||||
// Set pins to their positions on map.
|
||||
InitializePins(stations);
|
||||
|
||||
Log.ForContext<MapPageViewModel>().Verbose("Update of pins done.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <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 Task MoveMapToCurrentPositionOfUser(Status status)
|
||||
{
|
||||
if (status == Status.Granted)
|
||||
{
|
||||
ActionText = AppResources.ActivityTextCenterMap;
|
||||
if (TinkApp.CenterMapToCurrentLocation)
|
||||
{
|
||||
Location currentLocation = null;
|
||||
try
|
||||
{
|
||||
currentLocation = await GeolocationService.GetAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
|
||||
}
|
||||
|
||||
TinkApp.MapSpan = MapSpan.FromCenterAndRadius(
|
||||
new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
|
||||
TinkApp.MapSpan.Radius);
|
||||
|
||||
TinkApp.Save();
|
||||
}
|
||||
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.MapSpan);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests the location permission from the user.
|
||||
/// If the user declines, a dialog prompot is shown, telling the user to toggle the permission in the device settings.
|
||||
/// </summary>
|
||||
/// <returns>The permission status.</returns>
|
||||
private async Task<Status> RequestLocationPermission()
|
||||
{
|
||||
// Check location permission
|
||||
var status = await PermissionsService.CheckStatusAsync();
|
||||
if (TinkApp.CenterMapToCurrentLocation
|
||||
&& !GeolocationService.IsSimulation
|
||||
&& status != Status.Granted)
|
||||
{
|
||||
status = await PermissionsService.RequestAsync();
|
||||
|
||||
if (status != Status.Granted)
|
||||
{
|
||||
var dialogResult = await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageCenterMapLocationPermissionOpenDialog,
|
||||
AppResources.MessageAnswerYes,
|
||||
AppResources.MessageAnswerNo);
|
||||
|
||||
if (dialogResult)
|
||||
{
|
||||
// User decided to give access to locations permissions.
|
||||
PermissionsService.OpenAppSettings();
|
||||
ActionText = "";
|
||||
IsRunning = false;
|
||||
IsMapPageEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/// <summary> Moves map and scales visible region depending on active filter. </summary>
|
||||
public static void MoveAndScale(
|
||||
Action<MapSpan> moveToRegionDelegate,
|
||||
|
@ -878,7 +832,7 @@ namespace TINK.ViewModel.Map
|
|||
if (permissionResult != Status.Granted)
|
||||
{
|
||||
var dialogResult = await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageBikesManagementLocationPermission,
|
||||
"Ja",
|
||||
"Nein");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue