mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-06 11:06:26 +01:00
133 lines
3.8 KiB
C#
133 lines
3.8 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Serilog;
|
|
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;
|
|
using static TINK.Model.Bikes.BikeInfoNS.BluetoothLock.Command.CloseCommand;
|
|
using static TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory;
|
|
|
|
namespace TINK.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
|
|
{
|
|
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,
|
|
IGeolocationService geolocation,
|
|
ILocksService lockService,
|
|
Func<IPollingUpdateTaskManager> viewUpdateManager,
|
|
ISmartDevice smartDevice,
|
|
IViewService viewService,
|
|
IBikesViewModel bikesViewModel,
|
|
IUser activeUser) : base(
|
|
selectedBike,
|
|
AppResources.ActionCloseLock, // Close Lock
|
|
true, // Show button "Close Lock"
|
|
isConnectedDelegate,
|
|
connectorFactory,
|
|
geolocation,
|
|
lockService,
|
|
viewUpdateManager,
|
|
smartDevice,
|
|
viewService,
|
|
bikesViewModel,
|
|
activeUser)
|
|
{
|
|
LockitButtonText = string.Empty;
|
|
IsLockitButtonVisible = false;
|
|
|
|
_closeLockActionViewModel = new CloseLockActionViewModel<BookedOpen>(
|
|
selectedBike,
|
|
viewUpdateManager,
|
|
viewService,
|
|
bikesViewModel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holds the view model for close action.
|
|
/// </summary>
|
|
private CloseLockActionViewModel<BookedOpen> _closeLockActionViewModel;
|
|
|
|
/// <summary> Close lock (and return bike).</summary>
|
|
public async Task<IRequestHandler> HandleRequestOption1()
|
|
{
|
|
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,
|
|
LockService,
|
|
ViewUpdateManager,
|
|
ViewService,
|
|
BikesViewModel);
|
|
|
|
await _endRentalActionViewModel.EndRentalAsync();
|
|
|
|
return Create(
|
|
SelectedBike,
|
|
IsConnectedDelegate,
|
|
ConnectorFactory,
|
|
GeolocationService,
|
|
LockService,
|
|
ViewUpdateManager,
|
|
SmartDevice,
|
|
ViewService,
|
|
BikesViewModel,
|
|
ActiveUser);
|
|
}
|
|
|
|
public Task<IRequestHandler> HandleRequestOption2() => throw new InvalidOperationException();
|
|
|
|
/// <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);
|
|
}
|
|
|
|
/// <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);
|
|
|
|
}
|
|
}
|