2023-06-06 12:00:24 +02:00
using System ;
2021-05-13 20:03:07 +02:00
using System.Threading.Tasks ;
2022-08-30 15:42:25 +02:00
using Serilog ;
2021-05-13 20:03:07 +02:00
using TINK.Model.State ;
2023-08-31 12:20:06 +02:00
using TINK.MultilingualResources ;
2021-05-13 20:03:07 +02:00
using TINK.View ;
namespace TINK.ViewModel.Bikes.Bike.BluetoothLock
{
2022-09-06 16:08:19 +02:00
public class NotLoggedIn : IRequestHandler
{
/// <param name="bikesViewModel">View model to be used for progress report and unlocking/ locking view.</param>
public NotLoggedIn (
InUseStateEnum state ,
IViewService viewService ,
IBikesViewModel bikesViewModel )
{
ButtonText = BC . StateToText . GetActionText ( state ) ;
ViewService = viewService ;
BikesViewModel = bikesViewModel
? ? throw new ArgumentException ( $"Can not construct {GetType().Name}-object. {nameof(bikesViewModel)} must not be null." ) ;
}
/// <summary>View model to be used for progress report and unlocking/ locking view.</summary>
public IBikesViewModel BikesViewModel { get ; }
public bool IsButtonVisible = > true ;
public bool IsLockitButtonVisible = > false ;
public string ButtonText { get ; private set ; }
public string LockitButtonText = > GetType ( ) . Name ;
/// <summary>
/// Reference on view service to show modal notifications and to perform navigation.
/// </summary>
private IViewService ViewService { get ; }
public bool IsConnected = > throw new NotImplementedException ( ) ;
2023-06-06 12:00:24 +02:00
/// <summary> Gets if the bike has to be removed after action has been completed. </summary>
2022-09-06 16:08:19 +02:00
public bool IsRemoveBikeRequired = > false ;
public async Task < IRequestHandler > HandleRequestOption1 ( )
{
Log . ForContext < BikesViewModel > ( ) . Information ( "User selected bike but is not logged in." ) ;
// User is not logged in
BikesViewModel . ActionText = string . Empty ;
var l_oResult = await ViewService . DisplayAlert (
2023-08-31 12:20:06 +02:00
AppResources . QuestionLogInTitle ,
AppResources . QuestionLogIn ,
AppResources . MessageAnswerYes ,
AppResources . MessageAnswerNo ) ;
2022-09-06 16:08:19 +02:00
if ( l_oResult = = false )
{
// User aborted booking process
BikesViewModel . IsIdle = true ;
return this ;
}
try
{
// Switch to map page
await ViewService . ShowPage ( "//LoginPage" ) ;
}
catch ( Exception p_oException )
{
Log . ForContext < BikesViewModel > ( ) . Error ( "Ein unerwarteter Fehler ist in der Klasse NotLoggedIn aufgetreten. Kontext: Aufruf nach Reservierungsversuch ohne Anmeldung. {@Exception}" , p_oException ) ;
BikesViewModel . IsIdle = true ;
return this ;
}
BikesViewModel . IsIdle = true ;
return this ;
}
public async Task < IRequestHandler > HandleRequestOption2 ( )
{
Log . ForContext < NotLoggedIn > ( ) . Error ( "Click of unsupported button detected." ) ;
return await Task . FromResult ( this ) ;
}
public string ErrorText = > string . Empty ;
}
2021-05-13 20:03:07 +02:00
}