mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-06 11:06:26 +01:00
163 lines
5 KiB
C#
163 lines
5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
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 CloseCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.CloseCommand;
|
|
using OpenCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.OpenCommand;
|
|
using static ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory;
|
|
|
|
namespace ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|
{
|
|
public class BookedUnknown : Base, IRequestHandler, CloseCommand.ICloseCommandListener, OpenCommand.IOpenCommandListener
|
|
{
|
|
/// <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 BookedUnknown(
|
|
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.ActionOpenLock, // Open Lock
|
|
true, // Show button
|
|
isConnectedDelegate,
|
|
connectorFactory,
|
|
geolocation,
|
|
lockService,
|
|
viewUpdateManager,
|
|
smartDevice,
|
|
viewService,
|
|
bikesViewModel,
|
|
activeUser)
|
|
{
|
|
LockitButtonText = AppResources.ActionCloseLock; // Close Lock
|
|
IsLockitButtonVisible = true; // Show button
|
|
|
|
_openLockActionViewModel = new OpenLockActionViewModel<BookedUnknown>(
|
|
selectedBike,
|
|
viewUpdateManager,
|
|
viewService,
|
|
bikesViewModel);
|
|
|
|
_closeLockActionViewModel = new CloseLockActionViewModel<BookedUnknown>(
|
|
selectedBike,
|
|
viewUpdateManager,
|
|
viewService,
|
|
bikesViewModel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holds the view model for close action.
|
|
/// </summary>
|
|
private readonly OpenLockActionViewModel<BookedUnknown> _openLockActionViewModel;
|
|
|
|
/// <summary>
|
|
/// Processes the open lock progress.
|
|
/// </summary>
|
|
/// <param name="step">Current step to process.</param>
|
|
public void ReportStep(OpenCommand.Step step) => _openLockActionViewModel.ReportStep(step);
|
|
|
|
/// <summary>
|
|
/// Processes the open lock state.
|
|
/// </summary>
|
|
/// <param name="state">State to process.</param>
|
|
/// <param name="details">Textual details describing current state.</param>
|
|
public async Task ReportStateAsync(OpenCommand.State state, string details) => await _openLockActionViewModel.ReportStateAsync(state, details);
|
|
|
|
/// <summary> Open bike and update COPRI lock state. </summary>
|
|
public async Task<IRequestHandler> HandleRequestOption1()
|
|
{
|
|
await _openLockActionViewModel.OpenLockAsync();
|
|
return Create(
|
|
SelectedBike,
|
|
IsConnectedDelegate,
|
|
ConnectorFactory,
|
|
GeolocationService,
|
|
LockService,
|
|
ViewUpdateManager,
|
|
SmartDevice,
|
|
ViewService,
|
|
BikesViewModel,
|
|
ActiveUser);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holds the view model for close action.
|
|
/// </summary>
|
|
private readonly CloseLockActionViewModel<BookedUnknown> _closeLockActionViewModel;
|
|
|
|
/// <summary>
|
|
/// Processes the close lock progress.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Only used for testing.
|
|
/// </remarks>
|
|
/// <param name="step">Current step to process.</param>
|
|
public void ReportStep(CloseCommand.Step step) => _closeLockActionViewModel?.ReportStep(step);
|
|
|
|
/// <summary>
|
|
/// Processes the close 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(CloseCommand.State state, string details) => await _closeLockActionViewModel.ReportStateAsync(state, details);
|
|
|
|
|
|
/// <summary> Close lock in order to pause ride and update COPRI lock state.</summary>
|
|
public async Task<IRequestHandler> HandleRequestOption2()
|
|
{
|
|
await _closeLockActionViewModel.CloseLockAsync();
|
|
if (_closeLockActionViewModel.IsEndRentalRequested == false)
|
|
{
|
|
return Create(
|
|
SelectedBike,
|
|
IsConnectedDelegate,
|
|
ConnectorFactory,
|
|
GeolocationService,
|
|
LockService,
|
|
ViewUpdateManager,
|
|
SmartDevice,
|
|
ViewService,
|
|
BikesViewModel,
|
|
ActiveUser);
|
|
}
|
|
|
|
var _endRentalActionViewModel = new EndRentalActionViewModel<BookedClosed>(
|
|
SelectedBike,
|
|
IsConnectedDelegate,
|
|
ConnectorFactory,
|
|
ViewUpdateManager,
|
|
ViewService,
|
|
BikesViewModel);
|
|
|
|
await _endRentalActionViewModel.EndRentalAsync();
|
|
|
|
return Create(
|
|
SelectedBike,
|
|
IsConnectedDelegate,
|
|
ConnectorFactory,
|
|
GeolocationService,
|
|
LockService,
|
|
ViewUpdateManager,
|
|
SmartDevice,
|
|
ViewService,
|
|
BikesViewModel,
|
|
ActiveUser);
|
|
}
|
|
}
|
|
}
|