mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-06 11:06:26 +01:00
168 lines
5.5 KiB
C#
168 lines
5.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 CancelReservationCommand = ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Command.CancelReservationCommand;
|
||
|
using StartRentalCommand = ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Command.StartRentalCommand;
|
||
|
using static ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory;
|
||
|
|
||
|
namespace ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
||
|
{
|
||
|
public class ReservedDisconnected : Base, IRequestHandler, CancelReservationCommand.ICancelReservationCommandListener, StartRentalCommand.IStartRentalCommandListener
|
||
|
{
|
||
|
/// <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 ReservedDisconnected(
|
||
|
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.ActionCancelReservation, // Cancel Reservation
|
||
|
true, // Show button
|
||
|
isConnectedDelegate,
|
||
|
connectorFactory,
|
||
|
geolocation,
|
||
|
lockService,
|
||
|
viewUpdateManager,
|
||
|
smartDevice,
|
||
|
viewService,
|
||
|
bikesViewModel,
|
||
|
activeUser)
|
||
|
{
|
||
|
LockitButtonText = AppResources.ActionRentBike; // Rent bike
|
||
|
IsLockitButtonVisible = true; // Show button
|
||
|
|
||
|
_cancelReservationlActionViewModel = new CancelReservationActionViewModel<ReservedDisconnected>(
|
||
|
selectedBike,
|
||
|
viewUpdateManager,
|
||
|
viewService,
|
||
|
bikesViewModel);
|
||
|
|
||
|
_startRentalActionViewModel = new StartReservationOrRentalActionViewModel<ReservedDisconnected>(
|
||
|
selectedBike,
|
||
|
viewUpdateManager,
|
||
|
viewService,
|
||
|
bikesViewModel);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Holds the view model for requesting a bike action.
|
||
|
/// </summary>
|
||
|
private readonly CancelReservationActionViewModel<ReservedDisconnected> _cancelReservationlActionViewModel;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Processes the canceling of reservation progress.
|
||
|
/// </summary>
|
||
|
/// <remarks>
|
||
|
/// Only used for testing.
|
||
|
/// </remarks>
|
||
|
/// <param name="step">Current step to process.</param>
|
||
|
public void ReportStep(CancelReservationCommand.Step step) => _cancelReservationlActionViewModel?.ReportStep(step);
|
||
|
|
||
|
/// <summary>
|
||
|
/// Processes the canceling of reservation 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(CancelReservationCommand.State state, string details) => await _cancelReservationlActionViewModel.ReportStateAsync(state, details);
|
||
|
|
||
|
/// <summary> Cancel reservation. </summary>
|
||
|
public async Task<IRequestHandler> HandleRequestOption1()
|
||
|
{
|
||
|
await _cancelReservationlActionViewModel.CancelReservationAsync();
|
||
|
return Create(
|
||
|
SelectedBike,
|
||
|
IsConnectedDelegate,
|
||
|
ConnectorFactory,
|
||
|
GeolocationService,
|
||
|
LockService,
|
||
|
ViewUpdateManager,
|
||
|
SmartDevice,
|
||
|
ViewService,
|
||
|
BikesViewModel,
|
||
|
ActiveUser);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Holds the view model for requesting a bike action.
|
||
|
/// </summary>
|
||
|
private readonly StartReservationOrRentalActionViewModel<ReservedDisconnected> _startRentalActionViewModel;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Processes the renting a bike progress.
|
||
|
/// </summary>
|
||
|
/// <remarks>
|
||
|
/// Only used for testing.
|
||
|
/// </remarks>
|
||
|
/// <param name="step">Current step to process.</param>
|
||
|
public void ReportStep(StartRentalCommand.Step step) => _startRentalActionViewModel?.ReportStep(step);
|
||
|
|
||
|
/// <summary>
|
||
|
/// Processes the renting a bike 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(StartRentalCommand.State state, string details) => await _startRentalActionViewModel.ReportStateAsync(state, details);
|
||
|
|
||
|
|
||
|
/// <summary> Connect to reserved bike ask whether to rent bike or not and if yes open lock. </summary>
|
||
|
/// <returns></returns>
|
||
|
public async Task<IRequestHandler> HandleRequestOption2()
|
||
|
{
|
||
|
await _startRentalActionViewModel.StartReservationOrRentalAsync();
|
||
|
if (_startRentalActionViewModel.ContinueWithOpenLock == false)
|
||
|
{
|
||
|
return Create(
|
||
|
SelectedBike,
|
||
|
IsConnectedDelegate,
|
||
|
ConnectorFactory,
|
||
|
GeolocationService,
|
||
|
LockService,
|
||
|
ViewUpdateManager,
|
||
|
SmartDevice,
|
||
|
ViewService,
|
||
|
BikesViewModel,
|
||
|
ActiveUser);
|
||
|
}
|
||
|
|
||
|
var _openLockActionViewModel = new OpenLockActionViewModel<BookedClosed>(
|
||
|
SelectedBike,
|
||
|
ViewUpdateManager,
|
||
|
ViewService,
|
||
|
BikesViewModel);
|
||
|
|
||
|
await _openLockActionViewModel.OpenLockAsync();
|
||
|
return Create(
|
||
|
SelectedBike,
|
||
|
IsConnectedDelegate,
|
||
|
ConnectorFactory,
|
||
|
GeolocationService,
|
||
|
LockService,
|
||
|
ViewUpdateManager,
|
||
|
SmartDevice,
|
||
|
ViewService,
|
||
|
BikesViewModel,
|
||
|
ActiveUser);
|
||
|
}
|
||
|
}
|
||
|
}
|