mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-06 11:06:26 +01:00
109 lines
3.5 KiB
C#
109 lines
3.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Serilog;
|
|
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
|
|
using ShareeBike.Model.Connector;
|
|
using ShareeBike.Model.Device;
|
|
using ShareeBike.Model.User;
|
|
using ShareeBike.MultilingualResources;
|
|
using ShareeBike.Services.BluetoothLock;
|
|
using ShareeBike.Services.Geolocation;
|
|
using ShareeBike.View;
|
|
using ConnectCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.ConnectAndGetStateCommand;
|
|
using static ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory;
|
|
|
|
namespace ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|
{
|
|
public class BookedDisconnected : Base, IRequestHandler, ConnectCommand.IConnectAndGetStateCommandListener
|
|
{
|
|
/// <param name="smartDevice">Provides info about the smart device (phone, tablet, ...)</param>
|
|
/// <param name="bikesViewModel">View model to be used for progress report and unlocking/ locking view.</param>
|
|
public BookedDisconnected(
|
|
IBikeInfoMutable selectedBike,
|
|
Func<bool> isConnectedDelegate,
|
|
Func<bool, IConnector> connectorFactory,
|
|
IGeolocationService geolocation,
|
|
ILocksService lockService,
|
|
Func<IPollingUpdateTaskManager> viewUpdateManager,
|
|
ISmartDevice smartDevice,
|
|
IViewService viewService,
|
|
IBikesViewModel bikesViewModel,
|
|
IUser activeUser) :
|
|
base(
|
|
selectedBike,
|
|
AppResources.ActionSearchLock, // Connect Lock
|
|
true, // Show button
|
|
isConnectedDelegate,
|
|
connectorFactory,
|
|
geolocation,
|
|
lockService,
|
|
viewUpdateManager,
|
|
smartDevice,
|
|
viewService,
|
|
bikesViewModel,
|
|
activeUser)
|
|
{
|
|
LockitButtonText = GetType().Name;
|
|
IsLockitButtonVisible = false;
|
|
|
|
_connectLockActionViewModel = new ConnectLockActionViewModel<BookedDisconnected>(
|
|
selectedBike,
|
|
viewUpdateManager,
|
|
viewService,
|
|
bikesViewModel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holds the view model for connecting to lock action.
|
|
/// </summary>
|
|
private readonly ConnectLockActionViewModel<BookedDisconnected> _connectLockActionViewModel;
|
|
|
|
/// <summary>
|
|
/// Processes the connect to lock progress.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Only used for testing.
|
|
/// </remarks>
|
|
/// <param name="step">Current step to process.</param>
|
|
public void ReportStep(ConnectCommand.Step step) => _connectLockActionViewModel?.ReportStep(step);
|
|
|
|
/// <summary>
|
|
/// Processes the connect to lock state.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Only used for testing.
|
|
/// </remarks>
|
|
/// <param name="state">State to process.</param>
|
|
/// <param name="details">Textual details describing current state.</param>
|
|
public async Task ReportStateAsync(ConnectCommand.State state, string details) => await _connectLockActionViewModel.ReportStateAsync(state, details);
|
|
|
|
|
|
public async Task<IRequestHandler> HandleRequestOption2() => await UnsupportedRequest();
|
|
|
|
/// <summary> Scan for lock.</summary>
|
|
/// <returns></returns>
|
|
public async Task<IRequestHandler> HandleRequestOption1()
|
|
{
|
|
await _connectLockActionViewModel.ConnectLockAsync();
|
|
return Create(
|
|
SelectedBike,
|
|
IsConnectedDelegate,
|
|
ConnectorFactory,
|
|
GeolocationService,
|
|
LockService,
|
|
ViewUpdateManager,
|
|
SmartDevice,
|
|
ViewService,
|
|
BikesViewModel,
|
|
ActiveUser);
|
|
}
|
|
|
|
/// <summary> Request is not supported, button should be disabled. </summary>
|
|
/// <returns></returns>
|
|
public async Task<IRequestHandler> UnsupportedRequest()
|
|
{
|
|
Log.ForContext<BookedDisconnected>().Error("Click of unsupported button click detected.");
|
|
return await Task.FromResult<IRequestHandler>(this);
|
|
}
|
|
}
|
|
}
|