2022-09-16 11:19:46 +02:00
|
|
|
using System;
|
2021-05-13 20:03:07 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Serilog;
|
2022-08-30 15:42:25 +02:00
|
|
|
using TINK.Model;
|
|
|
|
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
|
|
|
|
using TINK.Model.Connector;
|
|
|
|
using TINK.Model.Device;
|
|
|
|
using TINK.Model.User;
|
|
|
|
using TINK.MultilingualResources;
|
|
|
|
using TINK.Services.BluetoothLock;
|
|
|
|
using TINK.Services.Geolocation;
|
|
|
|
using TINK.View;
|
2023-08-31 12:20:06 +02:00
|
|
|
using static TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command.CloseCommand;
|
|
|
|
using static TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
public class BookedOpen : Base, IRequestHandler
|
|
|
|
{
|
|
|
|
/// <param name="bikesViewModel">View model to be used for progress report and unlocking/ locking view.</param>
|
|
|
|
public BookedOpen(
|
|
|
|
IBikeInfoMutable selectedBike,
|
|
|
|
Func<bool> isConnectedDelegate,
|
|
|
|
Func<bool, IConnector> connectorFactory,
|
2023-04-05 15:02:10 +02:00
|
|
|
IGeolocationService geolocation,
|
2022-09-06 16:08:19 +02:00
|
|
|
ILocksService lockService,
|
|
|
|
Func<IPollingUpdateTaskManager> viewUpdateManager,
|
|
|
|
ISmartDevice smartDevice,
|
|
|
|
IViewService viewService,
|
|
|
|
IBikesViewModel bikesViewModel,
|
|
|
|
IUser activeUser) : base(
|
|
|
|
selectedBike,
|
2023-08-31 12:20:06 +02:00
|
|
|
AppResources.ActionClose, // Copri button text: "Close lock"
|
|
|
|
true, // Show button to allow user to close lock.
|
2022-09-06 16:08:19 +02:00
|
|
|
isConnectedDelegate,
|
|
|
|
connectorFactory,
|
|
|
|
geolocation,
|
|
|
|
lockService,
|
|
|
|
viewUpdateManager,
|
|
|
|
smartDevice,
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser)
|
|
|
|
{
|
2023-08-31 12:20:06 +02:00
|
|
|
LockitButtonText = string.Empty;
|
|
|
|
IsLockitButtonVisible = false;
|
|
|
|
|
|
|
|
_closeLockActionViewModel = new CloseLockActionViewModel<BookedOpen>(
|
|
|
|
selectedBike,
|
|
|
|
viewUpdateManager,
|
|
|
|
viewService,
|
|
|
|
bikesViewModel);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
2023-08-31 12:20:06 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Holds the view model for close action.
|
|
|
|
/// </summary>
|
|
|
|
private CloseLockActionViewModel<BookedOpen> _closeLockActionViewModel;
|
2022-09-06 16:08:19 +02:00
|
|
|
|
2023-08-31 12:20:06 +02:00
|
|
|
/// <summary> Close lock (and return bike).</summary>
|
|
|
|
public async Task<IRequestHandler> HandleRequestOption1()
|
2022-09-06 16:08:19 +02:00
|
|
|
{
|
2023-08-31 12:20:06 +02:00
|
|
|
await _closeLockActionViewModel.CloseLockAsync();
|
|
|
|
if(_closeLockActionViewModel.IsEndRentalRequested == false)
|
2022-09-06 16:08:19 +02:00
|
|
|
{
|
2023-08-31 12:20:06 +02:00
|
|
|
return Create(
|
2022-09-16 11:19:46 +02:00
|
|
|
SelectedBike,
|
2023-08-31 12:20:06 +02:00
|
|
|
IsConnectedDelegate,
|
|
|
|
ConnectorFactory,
|
|
|
|
GeolocationService,
|
|
|
|
LockService,
|
|
|
|
ViewUpdateManager,
|
|
|
|
SmartDevice,
|
|
|
|
ViewService,
|
|
|
|
BikesViewModel,
|
|
|
|
ActiveUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
var _endRentalActionViewModel = new EndRentalActionViewModel<BookedClosed>(
|
|
|
|
SelectedBike,
|
|
|
|
IsConnectedDelegate,
|
|
|
|
ConnectorFactory,
|
|
|
|
LockService,
|
|
|
|
ViewUpdateManager,
|
|
|
|
ViewService,
|
|
|
|
BikesViewModel);
|
|
|
|
|
|
|
|
await _endRentalActionViewModel.EndRentalAsync();
|
|
|
|
|
|
|
|
return Create(
|
|
|
|
SelectedBike,
|
|
|
|
IsConnectedDelegate,
|
|
|
|
ConnectorFactory,
|
|
|
|
GeolocationService,
|
|
|
|
LockService,
|
|
|
|
ViewUpdateManager,
|
|
|
|
SmartDevice,
|
|
|
|
ViewService,
|
|
|
|
BikesViewModel,
|
|
|
|
ActiveUser);
|
2022-09-06 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
2023-08-31 12:20:06 +02:00
|
|
|
public Task<IRequestHandler> HandleRequestOption2() => throw new InvalidOperationException();
|
2022-09-06 16:08:19 +02:00
|
|
|
|
2023-08-31 12:20:06 +02:00
|
|
|
/// <summary> Request is not supported, button should be disabled. </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<IRequestHandler> UnsupportedRequest()
|
|
|
|
{
|
|
|
|
Log.ForContext<DisposableDisconnected>().Error("Click of unsupported button click detected.");
|
|
|
|
return await Task.FromResult<IRequestHandler>(this);
|
|
|
|
}
|
2022-09-06 16:08:19 +02:00
|
|
|
|
2023-08-31 12:20:06 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Processes the close lock progress.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Only used for testing.
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="step">Current step to process.</param>
|
|
|
|
public void ReportStep(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(State state, string details) => await _closeLockActionViewModel.ReportStateAsync(state, details);
|
2022-09-06 16:08:19 +02:00
|
|
|
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
}
|