mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 05:47:28 +02:00
Version 3.0.338
This commit is contained in:
parent
573fe77e12
commit
0468955d49
751 changed files with 62747 additions and 60672 deletions
|
@ -5,55 +5,55 @@ using TINK.ViewModel.Bikes.Bike;
|
|||
|
||||
namespace TINK.ViewModel
|
||||
{
|
||||
public class BikeAtStationInUseStateInfoProvider : IInUseStateInfoProvider
|
||||
{
|
||||
/// <summary> Gets reserved into display text. </summary>
|
||||
/// <todo>Log unexpeced states.</todo>
|
||||
/// <returns>Display text</returns>
|
||||
public string GetReservedInfo(
|
||||
TimeSpan? remainingTime,
|
||||
string station = null,
|
||||
string code = null)
|
||||
{
|
||||
if (remainingTime == null)
|
||||
{
|
||||
// Remaining time not available.
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
// Reservation code not available
|
||||
return string.Format(AppResources.StatusTextReservationExpiredMaximumReservationTime, StateRequestedInfo.MaximumReserveTime.Minutes);
|
||||
}
|
||||
public class BikeAtStationInUseStateInfoProvider : IInUseStateInfoProvider
|
||||
{
|
||||
/// <summary> Gets reserved into display text. </summary>
|
||||
/// <todo>Log unexpeced states.</todo>
|
||||
/// <returns>Display text</returns>
|
||||
public string GetReservedInfo(
|
||||
TimeSpan? remainingTime,
|
||||
string station = null,
|
||||
string code = null)
|
||||
{
|
||||
if (remainingTime == null)
|
||||
{
|
||||
// Remaining time not available.
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
// Reservation code not available
|
||||
return string.Format(AppResources.StatusTextReservationExpiredMaximumReservationTime, StateRequestedInfo.MaximumReserveTime.Minutes);
|
||||
}
|
||||
|
||||
return string.Format(AppResources.StatusTextReservationExpiredCodeMaxReservationTime, code, StateRequestedInfo.MaximumReserveTime.Minutes);
|
||||
}
|
||||
return string.Format(AppResources.StatusTextReservationExpiredCodeMaxReservationTime, code, StateRequestedInfo.MaximumReserveTime.Minutes);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
return string.Format(AppResources.StatusTextReservationExpiredCodeRemaining, code, remainingTime.Value.Minutes);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
return string.Format(AppResources.StatusTextReservationExpiredCodeRemaining, code, remainingTime.Value.Minutes);
|
||||
}
|
||||
|
||||
return string.Format(AppResources.StatusTextReservationExpiredRemaining, remainingTime.Value.Minutes);
|
||||
}
|
||||
return string.Format(AppResources.StatusTextReservationExpiredRemaining, remainingTime.Value.Minutes);
|
||||
}
|
||||
|
||||
/// <summary> Gets booked into display text. </summary>
|
||||
/// <todo>Log unexpeced states.</todo>
|
||||
/// <returns>Display text</returns>
|
||||
public string GetBookedInfo(
|
||||
DateTime? from,
|
||||
string station = null,
|
||||
string code = null)
|
||||
{
|
||||
if (from == null)
|
||||
{
|
||||
return AppResources.StatusTextBooked;
|
||||
}
|
||||
/// <summary> Gets booked into display text. </summary>
|
||||
/// <todo>Log unexpeced states.</todo>
|
||||
/// <returns>Display text</returns>
|
||||
public string GetBookedInfo(
|
||||
DateTime? from,
|
||||
string station = null,
|
||||
string code = null)
|
||||
{
|
||||
if (from == null)
|
||||
{
|
||||
return AppResources.StatusTextBooked;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
return string.Format(AppResources.StatusTextBookedCodeSince, code, from.Value.ToString(BikeViewModelBase.TIMEFORMAT));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
return string.Format(AppResources.StatusTextBookedCodeSince, code, from.Value.ToString(BikeViewModelBase.TIMEFORMAT));
|
||||
}
|
||||
|
||||
return string.Format(AppResources.StatusTextBookedSince, from.Value.ToString(BikeViewModelBase.TIMEFORMAT));
|
||||
}
|
||||
}
|
||||
return string.Format(AppResources.StatusTextBookedSince, from.Value.ToString(BikeViewModelBase.TIMEFORMAT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,358 +26,358 @@ using Xamarin.Forms;
|
|||
|
||||
namespace TINK.ViewModel.BikesAtStation
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages one or more bikes which are located at a single station.
|
||||
/// </summary>
|
||||
public class BikesAtStationPageViewModel : BikesViewModel, INotifyCollectionChanged, INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the selected station;
|
||||
/// </summary>
|
||||
private IStation Station { get; }
|
||||
/// <summary>
|
||||
/// Manages one or more bikes which are located at a single station.
|
||||
/// </summary>
|
||||
public class BikesAtStationPageViewModel : BikesViewModel, INotifyCollectionChanged, INotifyPropertyChanged
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the selected station;
|
||||
/// </summary>
|
||||
private IStation Station { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs bike collection view model.
|
||||
/// </summary>
|
||||
/// <param name="user">Mail address of active user.</param>
|
||||
/// <param name="permissions">Holds object to query location permisions.</param>
|
||||
/// <param name="bluetoothLE">Holds object to query bluetooth state.</param>
|
||||
/// <param name="runtimPlatform">Specifies on which platform code is run.</param>
|
||||
/// <param name="isConnectedDelegate">Returns if mobile is connected to web or not.</param>
|
||||
/// <param name="connectorFactory">Connects system to copri.</param>
|
||||
/// <param name="lockService">Service to control lock retrieve info.</param>
|
||||
/// <param name="polling"> Holds whether to poll or not and the periode leght is polling is on. </param>
|
||||
/// <param name="openUrlInExternalBrowser">Action to open an external browser.</param>
|
||||
/// <param name="postAction">Executes actions on GUI thread.</param>
|
||||
/// <param name="smartDevice">Provides info about the smart device (phone, tablet, ...).</param>
|
||||
/// <param name="viewService">Interface to actuate methodes on GUI.</param>
|
||||
public BikesAtStationPageViewModel(
|
||||
User user,
|
||||
ILocationPermission permissions,
|
||||
IBluetoothLE bluetoothLE,
|
||||
string runtimPlatform,
|
||||
IStation selectedStation,
|
||||
Func<bool> isConnectedDelegate,
|
||||
Func<bool, IConnector> connectorFactory,
|
||||
IGeolocation geolocation,
|
||||
ILocksService lockService,
|
||||
PollingParameters polling,
|
||||
Action<string> openUrlInExternalBrowser,
|
||||
Action<SendOrPostCallback, object> postAction,
|
||||
ISmartDevice smartDevice,
|
||||
IViewService viewService) : base(user, permissions, bluetoothLE, runtimPlatform, isConnectedDelegate, connectorFactory, geolocation, lockService, polling, postAction, smartDevice, viewService, openUrlInExternalBrowser, () => new BikeAtStationInUseStateInfoProvider())
|
||||
{
|
||||
Station = selectedStation ?? new NullStation();
|
||||
/// <summary>
|
||||
/// Constructs bike collection view model.
|
||||
/// </summary>
|
||||
/// <param name="user">Mail address of active user.</param>
|
||||
/// <param name="permissions">Holds object to query location permisions.</param>
|
||||
/// <param name="bluetoothLE">Holds object to query bluetooth state.</param>
|
||||
/// <param name="runtimPlatform">Specifies on which platform code is run.</param>
|
||||
/// <param name="isConnectedDelegate">Returns if mobile is connected to web or not.</param>
|
||||
/// <param name="connectorFactory">Connects system to copri.</param>
|
||||
/// <param name="lockService">Service to control lock retrieve info.</param>
|
||||
/// <param name="polling"> Holds whether to poll or not and the periode leght is polling is on. </param>
|
||||
/// <param name="openUrlInExternalBrowser">Action to open an external browser.</param>
|
||||
/// <param name="postAction">Executes actions on GUI thread.</param>
|
||||
/// <param name="smartDevice">Provides info about the smart device (phone, tablet, ...).</param>
|
||||
/// <param name="viewService">Interface to actuate methodes on GUI.</param>
|
||||
public BikesAtStationPageViewModel(
|
||||
User user,
|
||||
ILocationPermission permissions,
|
||||
IBluetoothLE bluetoothLE,
|
||||
string runtimPlatform,
|
||||
IStation selectedStation,
|
||||
Func<bool> isConnectedDelegate,
|
||||
Func<bool, IConnector> connectorFactory,
|
||||
IGeolocation geolocation,
|
||||
ILocksService lockService,
|
||||
PollingParameters polling,
|
||||
Action<string> openUrlInExternalBrowser,
|
||||
Action<SendOrPostCallback, object> postAction,
|
||||
ISmartDevice smartDevice,
|
||||
IViewService viewService) : base(user, permissions, bluetoothLE, runtimPlatform, isConnectedDelegate, connectorFactory, geolocation, lockService, polling, postAction, smartDevice, viewService, openUrlInExternalBrowser, () => new BikeAtStationInUseStateInfoProvider())
|
||||
{
|
||||
Station = selectedStation ?? new NullStation();
|
||||
|
||||
Title = Station.StationName;
|
||||
Title = Station.StationName;
|
||||
|
||||
StationDetailText = Station.Id != null
|
||||
? string.Format(AppResources.MarkingBikesAtStationStationId, Station.Id)
|
||||
: string.Empty;
|
||||
StationDetailText = Station.Id != null
|
||||
? string.Format(AppResources.MarkingBikesAtStationStationId, Station.Id)
|
||||
: string.Empty;
|
||||
|
||||
CollectionChanged += (sender, eventargs) =>
|
||||
{
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsNoBikesAtStationVisible)));
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(NoBikesAtStationText)));
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsLoginRequiredHintVisible)));
|
||||
};
|
||||
}
|
||||
CollectionChanged += (sender, eventargs) =>
|
||||
{
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsNoBikesAtStationVisible)));
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(NoBikesAtStationText)));
|
||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsLoginRequiredHintVisible)));
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of the station which is displayed as title of the page.
|
||||
/// </summary>
|
||||
public string Title
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
/// <summary>
|
||||
/// Name of the station which is displayed as title of the page.
|
||||
/// </summary>
|
||||
public string Title
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Informs about need to log in before requesting an bike.
|
||||
/// </summary>
|
||||
public bool IsLoginRequiredHintVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return Count > 0
|
||||
&& !ActiveUser.IsLoggedIn;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Informs about need to log in before requesting an bike.
|
||||
/// </summary>
|
||||
public bool IsLoginRequiredHintVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return Count > 0
|
||||
&& !ActiveUser.IsLoggedIn;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Informs about need to log in before requesting an bike.
|
||||
/// </summary>
|
||||
public string LoginRequiredHintText
|
||||
=> ActiveUser.IsLoggedIn
|
||||
? string.Empty
|
||||
: AppResources.MarkingLoginRequiredToRerserve;
|
||||
/// <summary>
|
||||
/// Informs about need to log in before requesting an bike.
|
||||
/// </summary>
|
||||
public string LoginRequiredHintText
|
||||
=> ActiveUser.IsLoggedIn
|
||||
? string.Empty
|
||||
: AppResources.MarkingLoginRequiredToRerserve;
|
||||
|
||||
public string ContactSupportHintText
|
||||
=> string.Format(AppResources.MarkingContactSupport, Station.OperatorData?.Name ?? "Operator");
|
||||
public string ContactSupportHintText
|
||||
=> string.Format(AppResources.MarkingContactSupport, Station.OperatorData?.Name ?? "Operator");
|
||||
|
||||
/// <summary>
|
||||
/// Returns if info about the fact that user did not request or book any bikes is visible or not.
|
||||
/// </summary>
|
||||
public bool IsNoBikesAtStationVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return Count <= 0 && IsIdle == true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns if info about the fact that user did not request or book any bikes is visible or not.
|
||||
/// </summary>
|
||||
public bool IsNoBikesAtStationVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return Count <= 0 && IsIdle == true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Info about the fact that user did not request or book any bikes. </summary>
|
||||
public string NoBikesAtStationText
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsNoBikesAtStationVisible
|
||||
? $"Momentan sind keine Fahrräder an dieser Station verfügbar."
|
||||
: string.Empty;
|
||||
}
|
||||
}
|
||||
/// <summary> Info about the fact that user did not request or book any bikes. </summary>
|
||||
public string NoBikesAtStationText
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsNoBikesAtStationVisible
|
||||
? $"Momentan sind keine Fahrräder an dieser Station verfügbar."
|
||||
: string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Command object to bind login page redirect link to view model.</summary>
|
||||
public System.Windows.Input.ICommand ContactSupportClickedCommand
|
||||
/// <summary> Command object to bind login page redirect link to view model.</summary>
|
||||
public System.Windows.Input.ICommand ContactSupportClickedCommand
|
||||
#if USEFLYOUT
|
||||
=> new Xamarin.Forms.Command(() => OpenSupportPageAsync());
|
||||
#else
|
||||
=> new Xamarin.Forms.Command(async () => await OpenSupportPageAsync());
|
||||
=> new Xamarin.Forms.Command(async () => await OpenSupportPageAsync());
|
||||
#endif
|
||||
|
||||
/// <summary> Command object to bind login page redirect link to view model.</summary>
|
||||
public System.Windows.Input.ICommand LoginRequiredHintClickedCommand
|
||||
/// <summary> Command object to bind login page redirect link to view model.</summary>
|
||||
public System.Windows.Input.ICommand LoginRequiredHintClickedCommand
|
||||
#if USEFLYOUT
|
||||
=> new Xamarin.Forms.Command(() => OpenLoginPageAsync());
|
||||
#else
|
||||
=> new Xamarin.Forms.Command(async () => await OpenLoginPageAsync());
|
||||
=> new Xamarin.Forms.Command(async () => await OpenLoginPageAsync());
|
||||
#endif
|
||||
|
||||
/// <summary> Opens login page. </summary>
|
||||
/// <summary> Opens login page. </summary>
|
||||
#if USEFLYOUT
|
||||
public void OpenLoginPageAsync()
|
||||
#else
|
||||
public async Task OpenLoginPageAsync()
|
||||
public async Task OpenLoginPageAsync()
|
||||
#endif
|
||||
{
|
||||
try
|
||||
{
|
||||
// Switch to map page
|
||||
{
|
||||
try
|
||||
{
|
||||
// Switch to map page
|
||||
|
||||
#if USEFLYOUT
|
||||
ViewService.ShowPage(ViewTypes.LoginPage);
|
||||
#else
|
||||
await ViewService.ShowPage("//LoginPage");
|
||||
await ViewService.ShowPage("//LoginPage");
|
||||
#endif
|
||||
}
|
||||
catch (Exception p_oException)
|
||||
{
|
||||
Log.Error("Ein unerwarteter Fehler ist in der Klasse BikesAtStationPageViewModel aufgetreten. Kontext: Klick auf Hinweistext auf Station N- seite ohne Anmeldung. {@Exception}", p_oException);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception p_oException)
|
||||
{
|
||||
Log.Error("Ein unerwarteter Fehler ist in der Klasse BikesAtStationPageViewModel aufgetreten. Kontext: Klick auf Hinweistext auf Station N- seite ohne Anmeldung. {@Exception}", p_oException);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Opens support. </summary>
|
||||
/// <summary> Opens support. </summary>
|
||||
#if USEFLYOUT
|
||||
public void OpenSupportPageAsync()
|
||||
#else
|
||||
public async Task OpenSupportPageAsync()
|
||||
public async Task OpenSupportPageAsync()
|
||||
#endif
|
||||
{
|
||||
try
|
||||
{
|
||||
// Switch to map page
|
||||
{
|
||||
try
|
||||
{
|
||||
// Switch to map page
|
||||
|
||||
#if USEFLYOUT
|
||||
ViewService.ShowPage(ViewTypes.ContactPage, AppResources.MarkingFeedbackAndContact);
|
||||
#else
|
||||
await ViewService.ShowPage("//ContactPage");
|
||||
await ViewService.ShowPage("//ContactPage");
|
||||
#endif
|
||||
}
|
||||
catch (Exception p_oException)
|
||||
{
|
||||
Log.Error("Ein unerwarteter Fehler ist auf der Seite Kontakt aufgetreten. Kontext: Klick auf Hinweistext auf Station N- seite ohne Anmeldung. {@Exception}", p_oException);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception p_oException)
|
||||
{
|
||||
Log.Error("Ein unerwarteter Fehler ist auf der Seite Kontakt aufgetreten. Kontext: Klick auf Hinweistext auf Station N- seite ohne Anmeldung. {@Exception}", p_oException);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Returns detailed info about the station (station id).<summary>
|
||||
public string StationDetailText { get; private set; }
|
||||
/// <summary> Returns detailed info about the station (station id).<summary>
|
||||
public string StationDetailText { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when page is shown.
|
||||
/// Starts update process.
|
||||
/// </summary>
|
||||
public async Task OnAppearing()
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Information($"Bikes at station {Station.StationName} is appearing, either due to tap on a station or to app being shown again.");
|
||||
/// <summary>
|
||||
/// Invoked when page is shown.
|
||||
/// Starts update process.
|
||||
/// </summary>
|
||||
public async Task OnAppearing()
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Information($"Bikes at station {Station.StationName} is appearing, either due to tap on a station or to app being shown again.");
|
||||
|
||||
ActionText = "Einen Moment bitte...";
|
||||
ActionText = "Einen Moment bitte...";
|
||||
|
||||
// Stop polling before getting bikes info.
|
||||
await m_oViewUpdateManager.StopUpdatePeridically();
|
||||
// Stop polling before getting bikes info.
|
||||
await m_oViewUpdateManager.StopUpdatePeridically();
|
||||
|
||||
ActionText = AppResources.ActivityTextBikesAtStationGetBikes;
|
||||
ActionText = AppResources.ActivityTextBikesAtStationGetBikes;
|
||||
|
||||
var bikesAll = await ConnectorFactory(IsConnected).Query.GetBikesAsync();
|
||||
var bikesAll = await ConnectorFactory(IsConnected).Query.GetBikesAsync();
|
||||
|
||||
Exception = bikesAll.Exception; // Update communication error from query for bikes at station.
|
||||
Exception = bikesAll.Exception; // Update communication error from query for bikes at station.
|
||||
|
||||
var bikesAtStation = bikesAll.Response.GetAtStation(Station.Id);
|
||||
var lockIdList = bikesAtStation
|
||||
.GetLockIt()
|
||||
.Cast<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>()
|
||||
.Select(x => x.LockInfo)
|
||||
.ToList();
|
||||
var bikesAtStation = bikesAll.Response.GetAtStation(Station.Id);
|
||||
var lockIdList = bikesAtStation
|
||||
.GetLockIt()
|
||||
.Cast<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>()
|
||||
.Select(x => x.LockInfo)
|
||||
.ToList();
|
||||
|
||||
if (LockService is ILocksServiceFake serviceFake)
|
||||
{
|
||||
serviceFake.UpdateSimulation(bikesAtStation);
|
||||
}
|
||||
if (LockService is ILocksServiceFake serviceFake)
|
||||
{
|
||||
serviceFake.UpdateSimulation(bikesAtStation);
|
||||
}
|
||||
|
||||
ActionText = AppResources.ActivityTextSearchBikes;
|
||||
ActionText = AppResources.ActivityTextSearchBikes;
|
||||
|
||||
// Check location permissions.
|
||||
if (bikesAtStation.GetLockIt().Count > 0
|
||||
&& RuntimePlatform == Device.Android)
|
||||
{
|
||||
var status = await PermissionsService.CheckStatusAsync();
|
||||
if (status != Status.Granted)
|
||||
{
|
||||
var permissionResult = await PermissionsService.RequestAsync();
|
||||
// Check location permissions.
|
||||
if (bikesAtStation.GetLockIt().Count > 0
|
||||
&& 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,
|
||||
AppResources.MessageAnswerYes,
|
||||
AppResources.MessageAnswerNo);
|
||||
if (permissionResult != Status.Granted)
|
||||
{
|
||||
var dialogResult = await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageBikesManagementLocationPermissionOpenDialog,
|
||||
AppResources.MessageAnswerYes,
|
||||
AppResources.MessageAnswerNo);
|
||||
|
||||
if (!dialogResult)
|
||||
{
|
||||
// User decided not to give access to locations permissions.
|
||||
BikeCollection.Update(bikesAtStation, new List<IStation> { Station });
|
||||
if (!dialogResult)
|
||||
{
|
||||
// User decided not to give access to locations permissions.
|
||||
BikeCollection.Update(bikesAtStation, new List<IStation> { Station });
|
||||
|
||||
await OnAppearing(() => UpdateTask());
|
||||
await OnAppearing(() => UpdateTask());
|
||||
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
return;
|
||||
}
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Open permissions dialog.
|
||||
PermissionsService.OpenAppSettings();
|
||||
}
|
||||
}
|
||||
// Open permissions dialog.
|
||||
PermissionsService.OpenAppSettings();
|
||||
}
|
||||
}
|
||||
|
||||
if (Geolocation.IsGeolcationEnabled == false)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageBikesManagementLocationActivation,
|
||||
AppResources.MessageAnswerOk);
|
||||
if (Geolocation.IsGeolcationEnabled == false)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageBikesManagementLocationActivation,
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
BikeCollection.Update(bikesAtStation, new List<IStation> { Station });
|
||||
BikeCollection.Update(bikesAtStation, new List<IStation> { Station });
|
||||
|
||||
await OnAppearing(() => UpdateTask());
|
||||
await OnAppearing(() => UpdateTask());
|
||||
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
}
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
}
|
||||
|
||||
// Check if bluetooth is activated.
|
||||
if (await BluetoothService.GetBluetoothState() != BluetoothState.On)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageBikesManagementBluetoothActivation,
|
||||
AppResources.MessageAnswerOk);
|
||||
// Check if bluetooth is activated.
|
||||
if (await BluetoothService.GetBluetoothState() != BluetoothState.On)
|
||||
{
|
||||
await ViewService.DisplayAlert(
|
||||
AppResources.MessageTitleHint,
|
||||
AppResources.MessageBikesManagementBluetoothActivation,
|
||||
AppResources.MessageAnswerOk);
|
||||
|
||||
BikeCollection.Update(bikesAtStation, new List<IStation> { Station });
|
||||
BikeCollection.Update(bikesAtStation, new List<IStation> { Station });
|
||||
|
||||
await OnAppearing(() => UpdateTask());
|
||||
await OnAppearing(() => UpdateTask());
|
||||
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to bluetooth devices.
|
||||
ActionText = AppResources.ActivityTextSearchBikes;
|
||||
IEnumerable<LockInfoTdo> locksInfoTdo;
|
||||
try
|
||||
{
|
||||
locksInfoTdo = await LockService.GetLocksStateAsync(
|
||||
lockIdList.Select(x => x.ToLockInfoTdo()).ToList(),
|
||||
LockService.TimeOut.MultiConnect);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Error("Getting bluetooth state failed. {Exception}", exception);
|
||||
locksInfoTdo = new List<LockInfoTdo>();
|
||||
}
|
||||
// Connect to bluetooth devices.
|
||||
ActionText = AppResources.ActivityTextSearchBikes;
|
||||
IEnumerable<LockInfoTdo> locksInfoTdo;
|
||||
try
|
||||
{
|
||||
locksInfoTdo = await LockService.GetLocksStateAsync(
|
||||
lockIdList.Select(x => x.ToLockInfoTdo()).ToList(),
|
||||
LockService.TimeOut.MultiConnect);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Error("Getting bluetooth state failed. {Exception}", exception);
|
||||
locksInfoTdo = new List<LockInfoTdo>();
|
||||
}
|
||||
|
||||
var locksInfo = lockIdList.UpdateById(locksInfoTdo);
|
||||
var locksInfo = lockIdList.UpdateById(locksInfoTdo);
|
||||
|
||||
BikeCollection.Update(bikesAtStation.UpdateLockInfo(locksInfo), new List<IStation> { Station });
|
||||
BikeCollection.Update(bikesAtStation.UpdateLockInfo(locksInfo), new List<IStation> { Station });
|
||||
|
||||
// Backup GUI synchronization context.
|
||||
await OnAppearing(() => UpdateTask());
|
||||
// Backup GUI synchronization context.
|
||||
await OnAppearing(() => UpdateTask());
|
||||
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
}
|
||||
ActionText = "";
|
||||
IsIdle = true;
|
||||
}
|
||||
|
||||
/// <summary> Create task which updates my bike view model.</summary>
|
||||
private void UpdateTask()
|
||||
{
|
||||
PostAction(
|
||||
unused =>
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Debug("Updating action text...");
|
||||
ActionText = AppResources.ActivityTextUpdating;
|
||||
IsConnected = IsConnectedDelegate();
|
||||
},
|
||||
null);
|
||||
/// <summary> Create task which updates my bike view model.</summary>
|
||||
private void UpdateTask()
|
||||
{
|
||||
PostAction(
|
||||
unused =>
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Debug("Updating action text...");
|
||||
ActionText = AppResources.ActivityTextUpdating;
|
||||
IsConnected = IsConnectedDelegate();
|
||||
},
|
||||
null);
|
||||
|
||||
var result = ConnectorFactory(IsConnected).Query.GetBikesAsync().Result;
|
||||
var result = ConnectorFactory(IsConnected).Query.GetBikesAsync().Result;
|
||||
|
||||
BikeCollection bikes = result.Response.GetAtStation(Station.Id);
|
||||
BikeCollection bikes = result.Response.GetAtStation(Station.Id);
|
||||
|
||||
var exception = result.Exception;
|
||||
if (exception != null)
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Error("Getting all bikes bikes in polling context failed with exception {Exception}.", exception);
|
||||
}
|
||||
var exception = result.Exception;
|
||||
if (exception != null)
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Error("Getting all bikes bikes in polling context failed with exception {Exception}.", exception);
|
||||
}
|
||||
|
||||
PostAction(
|
||||
unused =>
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Debug("Updating bikes at station...");
|
||||
BikeCollection.Update(bikes, new List<IStation> { Station });
|
||||
Exception = result.Exception;
|
||||
ActionText = string.Empty;
|
||||
},
|
||||
null);
|
||||
}
|
||||
PostAction(
|
||||
unused =>
|
||||
{
|
||||
Log.ForContext<BikesAtStationPageViewModel>().Debug("Updating bikes at station...");
|
||||
BikeCollection.Update(bikes, new List<IStation> { Station });
|
||||
Exception = result.Exception;
|
||||
ActionText = string.Empty;
|
||||
},
|
||||
null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True if any action can be performed (request and cancel request)
|
||||
/// </summary>
|
||||
public override bool IsIdle
|
||||
{
|
||||
get => base.IsIdle;
|
||||
set
|
||||
{
|
||||
if (value == base.IsIdle)
|
||||
return;
|
||||
/// <summary>
|
||||
/// True if any action can be performed (request and cancel request)
|
||||
/// </summary>
|
||||
public override bool IsIdle
|
||||
{
|
||||
get => base.IsIdle;
|
||||
set
|
||||
{
|
||||
if (value == base.IsIdle)
|
||||
return;
|
||||
|
||||
Log.ForContext<BikesViewModel>().Debug($"Switch value of {nameof(IsIdle)} to {value}.");
|
||||
base.IsIdle = value;
|
||||
base.OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsNoBikesAtStationVisible)));
|
||||
base.OnPropertyChanged(new PropertyChangedEventArgs(nameof(NoBikesAtStationText)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.ForContext<BikesViewModel>().Debug($"Switch value of {nameof(IsIdle)} to {value}.");
|
||||
base.IsIdle = value;
|
||||
base.OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsNoBikesAtStationVisible)));
|
||||
base.OnPropertyChanged(new PropertyChangedEventArgs(nameof(NoBikesAtStationText)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue