2021-11-07 19:42:59 +01:00
using System.Linq ;
using TINK.View.Map ;
using TINK.ViewModel.Map ;
using Xamarin.Forms ;
namespace TINK
{
public static class BackdoorMethodHelpers
{
2022-08-30 15:42:25 +02:00
public static void DoTapPage ( string stationId )
2021-11-07 19:42:59 +01:00
{
Serilog . Log . Information ( $"Request via backdoor to tap station {stationId}." ) ;
var currentPage = GetCurrentPage ( ) ;
var mapPageViewModel = ( currentPage as MapPage ) ? . BindingContext as MapPageViewModel ;
if ( mapPageViewModel = = null )
{
Serilog . Log . Error ( $"Request via backdoor to tap station {stationId} aborted because current page is not of expected type {typeof(MapPage).Name}. Type detected is {currentPage.GetType().Name}." ) ;
return ;
}
Serilog . Log . Information ( $"Invoking member to tap." ) ;
2022-08-30 15:42:25 +02:00
mapPageViewModel ? . OnStationClicked ( stationId ) ;
2021-11-07 19:42:59 +01:00
}
/// <summary> Gets the current page assumed that app is master detail page.</summary>
/// <returns></returns>
static Page GetCurrentPage ( )
{
#if USEFLYOUT
return ( Application . Current . MainPage as FlyoutPage ) ? . Detail . Navigation . NavigationStack . LastOrDefault ( ) ;
#else
2022-01-22 18:32:22 +01:00
return Shell . Current . CurrentPage ;
2021-11-07 19:42:59 +01:00
#endif
}
}
}