Version 3.0.354

This commit is contained in:
Anja 2022-12-13 10:53:08 +01:00
parent 85321580df
commit 8b460bfebf
51 changed files with 363 additions and 570 deletions

View file

@ -201,7 +201,7 @@ namespace TINK.ViewModel.Map
/// <summary>
/// One time setup: Sets pins into map and connects to events.
/// </summary>
public async void InitializePins(StationDictionary stations)
public void InitializePins(StationDictionary stations)
{
// Add pins to stations.
Log.ForContext<MapPageViewModel>().Debug($"Request to draw {stations.Count} pins.");
@ -228,39 +228,8 @@ namespace TINK.ViewModel.Map
Pins.Add(pin);
}
//Add blue dot for showing current location of user
var status = await PermissionsService.CheckStatusAsync();
if (status == Status.Granted)
{
Location currentLocation = null;
try
{
currentLocation = await GeolocationService.GetAsync();
}
catch (Exception ex)
{
Log.ForContext<MapPageViewModel>().Error("Getting location failed. {Exception}", ex);
}
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);
}
}
}
public string currentLocationPinName = $"Location_Pin{(DeviceInfo.Platform == DevicePlatform.Android ? ".png" : string.Empty)}";
/// <summary> Update all stations from TINK. </summary>
/// <param name="stationsColorList">List of colors to apply.</param>
private void UpdatePinsColor(IList<Color> stationsColorList)
@ -270,12 +239,6 @@ namespace TINK.ViewModel.Map
// Update colors of pins.
for (int pinIndex = 0; pinIndex < stationsColorList.Count; pinIndex++)
{
if (Pins[pinIndex].Tag.ToString() == "NotClickable")
{
Pins[pinIndex].Icon = BitmapDescriptorFactory.FromBundle(currentLocationPinName);
}
else
{
var indexPartPrefix = int.TryParse(Pins[pinIndex].Tag.ToString(), out int stationId)
&& stationId <= CUSTOM_ICONS_COUNT
? $"{stationId}" // there is a station marker with index letter for given station id
@ -294,7 +257,6 @@ namespace TINK.ViewModel.Map
Pins[pinIndex].Label = stationId.ToString();
Pins[pinIndex].Icon = BitmapDescriptorFactory.DefaultMarker(stationsColorList[pinIndex]);
}
}
Pins[pinIndex].IsVisible = true;
}
@ -334,11 +296,6 @@ namespace TINK.ViewModel.Map
return "Red";
}
if (color == Color.Black)
{
return "NotClickable";
}
return color.ToString();
}
@ -694,9 +651,6 @@ namespace TINK.ViewModel.Map
/// <param name="selectedStationId">Id of station user clicked on.</param>
public async void OnStationClicked(string selectedStationId)
{
//Make shure currentLocationPin can not be clicked
if (selectedStationId != "NotClickable")
{
try
{
Log.ForContext<MapPageViewModel>().Information($"User taped station {selectedStationId}.");
@ -732,11 +686,6 @@ namespace TINK.ViewModel.Map
"OK");
}
#endif
}
else
{
return;
}
}
/// <summary>
@ -765,30 +714,23 @@ namespace TINK.ViewModel.Map
var colors = new List<Color>();
foreach (var stationId in stationsId)
{
if (stationId != "NotClickable")
// Get color of given station.
var bikesAtStation = bikesAll.Where(x => x.StationId == stationId).ToList();
if (bikesAtStation.FirstOrDefault(x => x.State.Value.IsOccupied()) != null)
{
// Get color of given station.
var bikesAtStation = bikesAll.Where(x => x.StationId == stationId).ToList();
if (bikesAtStation.FirstOrDefault(x => x.State.Value.IsOccupied()) != null)
{
// There is at least one requested or booked bike
colors.Add(Color.LightBlue);
continue;
}
if (bikesAtStation.ToList().Count > 0)
{
// There is at least one bike available
colors.Add(Color.Green);
continue;
}
colors.Add(Color.Red);
// There is at least one requested or booked bike
colors.Add(Color.LightBlue);
continue;
}
else
if (bikesAtStation.ToList().Count > 0)
{
colors.Add(Color.Black);
// There is at least one bike available
colors.Add(Color.Green);
continue;
}
colors.Add(Color.Red);
}
return colors;
@ -924,7 +866,6 @@ namespace TINK.ViewModel.Map
{
try
{
IsRunning = true;
ActionText = AppResources.ActivityTextCenterMap;
IsMapPageEnabled = false;
@ -961,7 +902,6 @@ namespace TINK.ViewModel.Map
if (currentLocation != null)
{
IsRunning = true;
ActionText = AppResources.ActivityTextCenterMap;
TinkApp.UserMapSpan = MapSpan.FromCenterAndRadius(
@ -972,28 +912,6 @@ namespace TINK.ViewModel.Map
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.
@ -1013,7 +931,6 @@ namespace TINK.ViewModel.Map
}
}
IsRunning = false;
IsMapPageEnabled = true;
Log.ForContext<MapPageViewModel>().Information($"Center to current Position done.");
ActionText = String.Empty;
@ -1030,7 +947,6 @@ namespace TINK.ViewModel.Map
AppResources.MessageAnswerOk);
IsMapPageEnabled = true;
IsRunning = false;
}
}