Version 3.0.353

This commit is contained in:
Anja 2022-12-07 16:54:52 +01:00
parent 5ea2e3b0ca
commit 85321580df
57 changed files with 1421 additions and 888 deletions

View file

@ -244,15 +244,12 @@ namespace TINK.ViewModel.BikesAtStation
// Check location permissions.
if (bikesAtStation.GetLockIt().Count > 0
&& RuntimePlatform == Device.Android)
&& RuntimePlatform == Device.Android
)
{
var status = await PermissionsService.CheckStatusAsync();
if (status != Status.Granted)
{
var permissionResult = await PermissionsService.RequestAsync();
if (permissionResult != Status.Granted)
{
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationPermissionOpenDialog,
@ -270,10 +267,11 @@ namespace TINK.ViewModel.BikesAtStation
IsIdle = true;
return;
}
// Open permissions dialog.
PermissionsService.OpenAppSettings();
}
else if (dialogResult)
{
// Open permissions dialog.
PermissionsService.OpenAppSettings();
}
}
if (Geolocation.IsGeolcationEnabled == false)

View file

@ -191,28 +191,32 @@ namespace TINK.ViewModel.Contact
}
//Add blue dot for showing current location of user
Location currentLocation = null;
try
var status = await PermissionsService.CheckStatusAsync();
if (status == Status.Granted)
{
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
if (currentLocation != null)
{
var currentLocationPin = new Pin()
Location currentLocation = null;
try
{
Position = new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
Label = "currentLocationPin",
Type = PinType.Place,
Tag = "NotClickable",
Icon = BitmapDescriptorFactory.FromBundle(currentLocationPinName)
};
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
Pins.Add(currentLocationPin);
if (currentLocation != null)
{
var currentLocationPin = new Pin()
{
Position = new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
Label = "currentLocationPin",
Type = PinType.Place,
Tag = "NotClickable",
Icon = BitmapDescriptorFactory.FromBundle(currentLocationPinName)
};
Pins.Add(currentLocationPin);
}
}
}
@ -313,17 +317,15 @@ namespace TINK.ViewModel.Contact
if (Pins.Count <= 0)
{
ActionText = AppResources.ActivityTextRequestingLocationPermissions;
// Check location permission
var status = await PermissionsService.CheckStatusAsync();
if (TinkApp.CenterMapToCurrentLocation
&& !GeolocationService.IsSimulation
&& status != Status.Granted)
// Move and scale before getting stations and bikes which takes some time.
if (TinkApp.CenterMapToCurrentLocation)
{
var permissionResult = await PermissionsService.RequestAsync();
ActionText = AppResources.ActivityTextRequestingLocationPermissions;
if (permissionResult != Status.Granted)
// Check location permission
var status = await PermissionsService.CheckStatusAsync();
if (!GeolocationService.IsSimulation
&& status != Status.Granted)
{
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
@ -341,23 +343,25 @@ namespace TINK.ViewModel.Contact
return;
}
}
}
if (status == Status.Granted)
{
ActionText = AppResources.ActivityTextCenterMap;
// 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<SelectStationPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
Location currentLocation = null;
try
{
currentLocation = TinkApp.CenterMapToCurrentLocation
? await GeolocationService.GetAsync()
: null;
}
catch (Exception ex)
{
Log.ForContext<SelectStationPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.Uris.ActiveUri, currentLocation);
MoveAndScale(m_oMoveToRegionDelegate, TinkApp.Uris.ActiveUri, currentLocation);
}
}
}
ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;

View file

@ -235,36 +235,63 @@ namespace TINK.ViewModel.FindBike
ActionText = AppResources.ActivityTextCheckBluetoothState;
if (bikeCollection.FirstOrDefault(x => x is BikeInfo btBike) != null
&& RuntimePlatform == Device.Android)
//&& RuntimePlatform == Device.Android
)
{
// Check location permission
var status = await PermissionsService.CheckStatusAsync();
if (status != Status.Granted)
{
var permissionResult = await PermissionsService.RequestAsync();
if (permissionResult != Status.Granted)
if (RuntimePlatform == Device.Android)
{
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationPermissionOpenDialog,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
var permissionResult = await PermissionsService.RequestAsync();
if (!dialogResult)
if (permissionResult != Status.Granted)
{
// User decided not to give access to locations permissions.
BikeCollection.Update(bikeCollection, Stations);
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationPermissionOpenDialog,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
await StartUpdateTask(() => UpdateTask());
if (!dialogResult)
{
// User decided not to give access to locations permissions.
BikeCollection.Update(bikeCollection, Stations);
ActionText = "";
IsIdle = true;
return;
await StartUpdateTask(() => UpdateTask());
ActionText = "";
IsIdle = true;
return;
}
// Open permissions dialog.
PermissionsService.OpenAppSettings();
}
}
else
{
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageBikesManagementLocationPermissionOpenDialog,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
// Open permissions dialog.
PermissionsService.OpenAppSettings();
if (!dialogResult)
{
// User decided not to give access to locations permissions.
BikeCollection.Update(bikeCollection, Stations);
await StartUpdateTask(() => UpdateTask());
ActionText = "";
IsIdle = true;
return;
}
// Open permissions dialog.
PermissionsService.OpenAppSettings();
}
}

View file

@ -27,6 +27,7 @@ using TINK.Repository;
using TINK.Services.Geolocation;
using TINK.Model.State;
#if !TRYNOTBACKSTYLE
#endif
@ -55,6 +56,8 @@ namespace TINK.ViewModel.Map
/// </summary>
private ILocationPermission PermissionsService { get; }
private IGeolocation Geolocation { get; }
/// <summary>
/// Service to manage bluetooth stack.
/// </summary>
@ -227,28 +230,32 @@ namespace TINK.ViewModel.Map
}
//Add blue dot for showing current location of user
Location currentLocation = null;
try
var status = await PermissionsService.CheckStatusAsync();
if (status == Status.Granted)
{
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
if (currentLocation != null)
{
var currentLocationPin = new Pin()
Location currentLocation = null;
try
{
Position = new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
Label = "currentLocationPin",
Type = PinType.Place,
Tag = "NotClickable",
Icon = BitmapDescriptorFactory.FromBundle(currentLocationPinName)
};
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
Pins.Add(currentLocationPin);
if (currentLocation != null)
{
var currentLocationPin = new Pin()
{
Position = new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
Label = "currentLocationPin",
Type = PinType.Place,
Tag = "NotClickable",
Icon = BitmapDescriptorFactory.FromBundle(currentLocationPinName)
};
Pins.Add(currentLocationPin);
}
}
}
@ -343,7 +350,14 @@ namespace TINK.ViewModel.Map
{
try
{
//Request Location Permission on iOS
if(DeviceInfo.Platform == DevicePlatform.iOS)
{
var status = await PermissionsService.RequestAsync();
}
IsRunning = true;
IsNavBarVisible = false;
// Process map page.
Polling = TinkApp.Polling;
@ -354,9 +368,6 @@ namespace TINK.ViewModel.Map
// Update map page filter
ActiveFilterMap = TinkApp.GroupFilterMapPage;
ActionText = AppResources.ActivityTextRequestingLocationPermissions;
var status = await RequestLocationPermission();
ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;
IsConnected = TinkApp.GetIsConnected();
var resultStationsAndBikes = await TinkApp.GetConnector(IsConnected).Query.GetBikesAndStationsAsync();
@ -394,11 +405,15 @@ namespace TINK.ViewModel.Map
// Get map display area
Model.Map.IMapSpan mapSpan = null;
if (TinkApp.CenterMapToCurrentLocation && status == Status.Granted)
if (TinkApp.CenterMapToCurrentLocation)
{
// Get from smart device
mapSpan = await GetFromLocationService(status);
}
var status = await PermissionsService.CheckStatusAsync();
if (status == Status.Granted)
{
// Get from smart device
mapSpan = await GetFromLocationService(status);
}
}
if (mapSpan == null)
{
@ -433,6 +448,7 @@ namespace TINK.ViewModel.Map
Exception = resultStationsAndBikes.Exception;
ActionText = "";
IsRunning = false;
IsNavBarVisible = true;
IsMapPageEnabled = true;
}
catch (Exception l_oException)
@ -440,6 +456,7 @@ namespace TINK.ViewModel.Map
Log.ForContext<MapPageViewModel>().Error($"An error occurred showing bike stations page.\r\n{l_oException.Message}");
IsRunning = false;
IsNavBarVisible = true;
await ViewService.DisplayAlert(
"Fehler",
@ -552,19 +569,15 @@ namespace TINK.ViewModel.Map
{
// Check location permission
var status = await PermissionsService.CheckStatusAsync();
if (TinkApp.CenterMapToCurrentLocation
&& !GeolocationService.IsSimulation
if (!GeolocationService.IsSimulation
// && DeviceInfo.Platform == DevicePlatform.Android
&& status != Status.Granted)
{
status = await PermissionsService.RequestAsync();
if (status != Status.Granted)
{
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageCenterMapLocationPermissionOpenDialog,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
var dialogResult = await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageCenterMapLocationPermissionOpenDialog,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
if (dialogResult)
{
@ -572,9 +585,9 @@ namespace TINK.ViewModel.Map
PermissionsService.OpenAppSettings();
ActionText = "";
IsRunning = false;
IsNavBarVisible = true;
IsMapPageEnabled = true;
}
}
}
return status;
}
@ -598,7 +611,7 @@ namespace TINK.ViewModel.Map
{
// Start task which periodically updates pins.
return new PollingUpdateTaskManager(
async () =>
() =>
{
try
{
@ -660,6 +673,7 @@ namespace TINK.ViewModel.Map
null);
Log.ForContext<MapPageViewModel>().Verbose("Leaving update cycle.");
return;
}
});
@ -845,6 +859,21 @@ namespace TINK.ViewModel.Map
}
}
private bool isNavBarVisible = true;
public bool IsNavBarVisible
{
get => isNavBarVisible;
set
{
if (value == isNavBarVisible)
return;
Log.ForContext<MapPageViewModel>().Debug($"Switch value of {nameof(isNavBarVisible)} to {value}.");
isNavBarVisible = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsNavBarVisible)));
}
}
/// <summary> Holds information whether app is connected to web or not. </summary>
private bool? isConnected = null;
@ -895,6 +924,9 @@ namespace TINK.ViewModel.Map
{
try
{
IsRunning = true;
ActionText = AppResources.ActivityTextCenterMap;
IsMapPageEnabled = false;
Log.ForContext<MapPageViewModel>().Information($"Request to center to current position.");
@ -913,127 +945,92 @@ namespace TINK.ViewModel.Map
TinkApp.UpdateConnector();
// Check location permission
//ActionText = AppResources.ActivityTextRequestingLocationPermissions;
var status = await PermissionsService.CheckStatusAsync();
if (!GeolocationService.IsSimulation
&& status != Status.Granted)
var status = await RequestLocationPermission();
if (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.");
// Move and scale.
Location currentLocation = null;
try
{
// Update bikes at station or my bikes depending on context.
await m_oViewUpdateManager.StartUpdateAyncPeridically(Polling);
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception)
catch (Exception ex)
{
// Excpetions are handled insde update task;
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
IsConnected = TinkApp.GetIsConnected();
var resultStationsAndBikes = await TinkApp.GetConnector(IsConnected).Query.GetBikesAndStationsAsync();
// Set pins to their positions on map.
ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;
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
{
await ViewService.DisplayAlert(
AppResources.MessageTitleHint,
AppResources.MessageErrorLocationIsOff,
AppResources.MessageAnswerOk);
}
}
else
{
ActionText = AppResources.ActivityTextErrorQueryLocationWhenAny;
}
IsRunning = false;
IsMapPageEnabled = true;
Log.ForContext<MapPageViewModel>().Information($"Center to current Position done.");
ActionText = "";
ActionText = String.Empty;
}
catch (Exception l_oException)
{
Log.ForContext<MapPageViewModel>().Error("An error occurred while centering to current position.");
ActionText = "";
IsRunning = false;
ActionText = String.Empty;
await ViewService.DisplayAlert(
"Fehler",
AppResources.MessageMapPageErrorSwitch,
String.Format(AppResources.MessageMapPageErrorSwitch, l_oException.Message),
String.Format(AppResources.MessageErrorQueryLocationMessage, l_oException.Message),
AppResources.MessageAnswerOk);
IsMapPageEnabled = true;
IsRunning = false;
}
}
@ -1080,6 +1077,7 @@ namespace TINK.ViewModel.Map
{
IsMapPageEnabled = false;
IsRunning = true;
IsNavBarVisible = false;
Log.ForContext<MapPageViewModel>().Information($"Request to toggle to \"{selectedFilter}\".");
@ -1101,76 +1099,42 @@ namespace TINK.ViewModel.Map
Pins.Clear();
// Check location permission
//ActionText = AppResources.ActivityTextRequestingLocationPermissions;
//// Move and scale before getting stations and bikes which takes some time.
//if (TinkApp.CenterMapToCurrentLocation)
//{
// // Check location permission
// //ActionText = AppResources.ActivityTextRequestingLocationPermissions;
// var status = await RequestLocationPermission();
// if (status == Status.Granted)
// {
// //ActionText = AppResources.ActivityTextCenterMap;
var status = await PermissionsService.CheckStatusAsync();
if (TinkApp.CenterMapToCurrentLocation
&& !GeolocationService.IsSimulation
&& status != Status.Granted)
{
status = await PermissionsService.RequestAsync();
// Location currentLocation = null;
// try
// {
// currentLocation = await GeolocationService.GetAsync();
// }
// catch (Exception ex)
// {
// Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
// }
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;
}
}
// if (currentLocation != null)
// {
// TinkApp.UserMapSpan = MapSpan.FromCenterAndRadius(
// new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
// TinkApp.ActiveMapSpan.Radius);
// 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;
}
}
// TinkApp.Save();
// Move and scale before getting stations and bikes which takes some time.
if (TinkApp.CenterMapToCurrentLocation)
{
//ActionText = AppResources.ActivityTextCenterMap;
Location currentLocation = null;
try
{
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
if (currentLocation != null)
{
TinkApp.UserMapSpan = MapSpan.FromCenterAndRadius(
new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude),
TinkApp.ActiveMapSpan.Radius);
TinkApp.Save();
//MoveAndScale(m_oMoveToRegionDelegate, TinkApp.ActiveMapSpan);
}
}
// //MoveAndScale(m_oMoveToRegionDelegate, TinkApp.ActiveMapSpan);
// }
// else
// {
// ActionText = AppResources.ActivityTextErrorQueryLocationWhenAny;
// }
// }
//}
// Update stations
ActionText = AppResources.ActivityTextMapLoadingStationsAndBikes;
@ -1204,6 +1168,7 @@ namespace TINK.ViewModel.Map
ActionText = "";
IsRunning = false;
IsNavBarVisible = true;
IsMapPageEnabled = true;
Log.ForContext<MapPageViewModel>().Information($"Toggle to \"{selectedFilter}\" done.");
}
@ -1212,6 +1177,7 @@ namespace TINK.ViewModel.Map
Log.ForContext<MapPageViewModel>().Error("An error occurred switching view Cargobike/ Citybike.{}");
ActionText = "";
IsRunning = false;
IsNavBarVisible = true;
await ViewService.DisplayAlert(
"Fehler",