Version 3.0.352

This commit is contained in:
Anja 2022-11-25 09:55:23 +01:00
parent 40b96f0350
commit 5ea2e3b0ca
48 changed files with 601 additions and 255 deletions

View file

@ -478,16 +478,16 @@ namespace TINK.ViewModel.Map
{
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();
// 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.
@ -598,7 +598,7 @@ namespace TINK.ViewModel.Map
{
// Start task which periodically updates pins.
return new PollingUpdateTaskManager(
() =>
async () =>
{
try
{
@ -893,26 +893,148 @@ namespace TINK.ViewModel.Map
/// <summary> User request to center to currentLocation. </summary>
public async Task CenterToCurrentLocation()
{
Location currentLocation = null;
try
{
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
IsMapPageEnabled = false;
if (currentLocation != null)
{
TinkApp.UserMapSpan = MapSpan.FromCenterAndRadius(
new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
TinkApp.ActiveMapSpan.Radius);
Log.ForContext<MapPageViewModel>().Information($"Request to center to current position.");
// Stop polling.
//ActionText = AppResources.ActivityTextOneMomentPlease;
await m_oViewUpdateManager.StopUpdatePeridically();
// Clear error info.
Exception = null;
ActiveFilterMap = tinkKonradToggleViewModel.FilterDictionary;
TinkApp.GroupFilterMapPage = ActiveFilterMap;
TinkApp.Save();
}
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.ActiveMapSpan);
TinkApp.UpdateConnector();
// Check location permission
//ActionText = AppResources.ActivityTextRequestingLocationPermissions;
var status = await PermissionsService.CheckStatusAsync();
if (!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;
}
}
// Do not use property .State to get bluetooth state due
// to issue https://hausource.visualstudio.com/TINK/_workitems/edit/116 /
// see https://github.com/xabre/xamarin-bluetooth-le/issues/112#issuecomment-380994887
if (await BluetoothService.GetBluetoothState() != Plugin.BLE.Abstractions.Contracts.BluetoothState.On)
{
await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementBluetoothActivation,
AppResources.MessageAnswerOk);
ActionText = "";
IsRunning = false;
IsMapPageEnabled = true;
return;
}
}
// Move and scale before getting stations and bikes which takes some time.
Location currentLocation = null;
try
{
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
if (currentLocation != null)
{
IsRunning = true;
ActionText = AppResources.ActivityTextCenterMap;
TinkApp.UserMapSpan = MapSpan.FromCenterAndRadius(
new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
TinkApp.ActiveMapSpan.Radius);
TinkApp.Save();
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.ActiveMapSpan);
//Pins.Clear();
//// Update stations
//ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;
//IsConnected = TinkApp.GetIsConnected();
//var resultStationsAndBikes = await TinkApp.GetConnector(IsConnected).Query.GetBikesAndStationsAsync();
//// Set pins to their positions on map.
//InitializePins(resultStationsAndBikes.Response.StationsAll);
//Log.ForContext<MapPageViewModel>().Verbose("Update of pins done...");
//// Update pin colors.
//Log.ForContext<MapPageViewModel>().Verbose("Starting update pins color...");
//var l_oColors = GetStationColors(
// Pins.Select(x => x.Tag.ToString()).ToList(),
// resultStationsAndBikes.Response.Bikes);
//// Update pins color form count of bikes located at station.
//UpdatePinsColor(l_oColors);
//Log.ForContext<MapPageViewModel>().Verbose("Update pins color done.");
try
{
// Update bikes at station or my bikes depending on context.
await m_oViewUpdateManager.StartUpdateAyncPeridically(Polling);
}
catch (Exception)
{
// Excpetions are handled insde update task;
}
}
else
{
ActionText = AppResources.ActivityTextErrorQueryLocationWhenAny;
}
IsRunning = false;
IsMapPageEnabled = true;
Log.ForContext<MapPageViewModel>().Information($"Center to current Position done.");
ActionText = "";
}
catch (Exception l_oException)
{
Log.ForContext<MapPageViewModel>().Error("An error occurred while centering to current position.");
ActionText = "";
IsRunning = false;
await ViewService.DisplayAlert(
"Fehler",
AppResources.MessageMapPageErrorSwitch,
String.Format(AppResources.MessageMapPageErrorSwitch, l_oException.Message),
AppResources.MessageAnswerOk);
IsMapPageEnabled = true;
}
}
/// <summary> Command object to bind login button to view model.</summary>
@ -980,7 +1102,7 @@ namespace TINK.ViewModel.Map
Pins.Clear();
// Check location permission
ActionText = AppResources.ActivityTextRequestingLocationPermissions;
//ActionText = AppResources.ActivityTextRequestingLocationPermissions;
var status = await PermissionsService.CheckStatusAsync();
if (TinkApp.CenterMapToCurrentLocation
@ -1024,10 +1146,10 @@ namespace TINK.ViewModel.Map
}
// Move and scale before getting stations and bikes which takes some time.
ActionText = AppResources.ActivityTextCenterMap;
if (TinkApp.CenterMapToCurrentLocation)
{
//ActionText = AppResources.ActivityTextCenterMap;
Location currentLocation = null;
try
{
@ -1045,12 +1167,12 @@ namespace TINK.ViewModel.Map
TinkApp.ActiveMapSpan.Radius);
TinkApp.Save();
//MoveAndScale(m_oMoveToRegionDelegate, TinkApp.ActiveMapSpan);
}
}
// Update stations
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.ActiveMapSpan);
ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;
IsConnected = TinkApp.GetIsConnected();
var resultStationsAndBikes = await TinkApp.GetConnector(IsConnected).Query.GetBikesAndStationsAsync();