sharee.bike-App/TINKLib/ViewModel/Bikes/Bike/BC/RequestHandler/Base.cs

106 lines
3.8 KiB
C#
Raw Normal View History

2021-05-13 20:03:07 +02:00
using System;
using TINK.Model.Connector;
2021-06-26 20:57:55 +02:00
using TINK.Model.Device;
2021-05-13 20:03:07 +02:00
using TINK.Model.State;
using TINK.Model.User;
using TINK.View;
namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
{
public abstract class Base<T>
{
/// <summary>
/// View model to be used by subclasses for progress report and unlocking/ locking view.
/// </summary>
public IBikesViewModel BikesViewModel { get; set; }
/// <summary> Gets the bike state. </summary>
public abstract InUseStateEnum State { get; }
/// <summary>
/// Gets a value indicating whether the button to reserve bike is visible or not.
/// </summary>
public bool IsButtonVisible { get; }
/// <summary>
/// Gets the name of the button when bike is disposable.
/// </summary>
public string ButtonText { get; }
2021-06-26 20:57:55 +02:00
/// <summary> Provides info about the smart device (phone, tablet, ...).</summary>
protected ISmartDevice SmartDevice;
2021-05-13 20:03:07 +02:00
/// <summary>
/// Reference on view servcie to show modal notifications and to perform navigation.
/// </summary>
protected IViewService ViewService { get; }
/// <summary> Provides an connector object.</summary>
protected Func<bool, IConnector> ConnectorFactory { get; }
/// <summary> Delegate to retrieve connected state. </summary>
protected Func<bool> IsConnectedDelegate { get; }
/// <summary> Object to manage update of view model objects from Copri.</summary>
protected Func<IPollingUpdateTaskManager> ViewUpdateManager { get; }
/// <summary> Reference on the user </summary>
protected IUser ActiveUser { get; }
/// <summary> Bike to display. </summary>
protected T SelectedBike { get; }
/// <summary>Holds the is connected state. </summary>
private bool isConnected;
/// <summary>Gets the is connected state. </summary>
public bool IsConnected
{
get => isConnected;
set
{
if (value == isConnected)
return;
isConnected = value;
}
}
/// <summary> Gets if the bike has to be remvoed after action has been completed. </summary>
public bool IsRemoveBikeRequired { get; set; }
/// <summary>
/// Constructs the reqest handler base.
/// </summary>
/// <param name="selectedBike">Bike which is reserved or for which reservation is canceled.</param>
2021-06-26 20:57:55 +02:00
/// <param name="smartDevice">Provides info about the smart device (phone, tablet, ...).</param>
2021-05-13 20:03:07 +02:00
/// <param name="bikesViewModel">View model to be used by subclasses for progress report and unlocking/ locking view.</param>
public Base(
T selectedBike,
string buttonText,
bool isCopriButtonVisible,
Func<bool> isConnectedDelegate,
Func<bool, IConnector> connectorFactory,
Func<IPollingUpdateTaskManager> viewUpdateManager,
2021-06-26 20:57:55 +02:00
ISmartDevice smartDevice,
2021-05-13 20:03:07 +02:00
IViewService viewService,
IBikesViewModel bikesViewModel,
IUser activeUser)
{
ButtonText = buttonText;
IsButtonVisible = isCopriButtonVisible;
SelectedBike = selectedBike;
IsConnectedDelegate = isConnectedDelegate;
ConnectorFactory = connectorFactory;
ViewUpdateManager = viewUpdateManager;
2021-06-26 20:57:55 +02:00
SmartDevice = smartDevice;
2021-05-13 20:03:07 +02:00
ViewService = viewService;
ActiveUser = activeUser;
IsRemoveBikeRequired = false;
BikesViewModel = bikesViewModel
?? throw new ArgumentException($"Can not construct {GetType().Name}-object. {nameof(bikesViewModel)} must not be null.");
}
}
}