sharee.bike-App/TINK/TINK/BackdoorMethodHelpers.cs

39 lines
1.3 KiB
C#
Raw Normal View History

2021-05-13 20:16:41 +02:00
using System.Linq;
using TINK.View.Map;
using TINK.ViewModel.Map;
using Xamarin.Forms;
namespace TINK
{
public static class BackdoorMethodHelpers
{
2021-06-26 20:57:55 +02:00
public static void DoTapPage(string stationId )
2021-05-13 20:16:41 +02:00
{
2021-06-26 20:57:55 +02:00
Serilog.Log.Information($"Request via backdoor to tap station {stationId}.");
2021-05-13 20:16:41 +02:00
var currentPage = GetCurrentPage();
var mapPageViewModel = (currentPage as MapPage)?.BindingContext as MapPageViewModel;
if (mapPageViewModel == null)
{
2021-06-26 20:57:55 +02:00
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}.");
2021-05-13 20:16:41 +02:00
return;
}
Serilog.Log.Information($"Invoking member to tap.");
2021-06-26 20:57:55 +02:00
mapPageViewModel?.OnStationClicked(stationId);
2021-05-13 20:16:41 +02: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
return (Application.Current.MainPage as AppShellViewModel)?.Detail.Navigation.NavigationStack.LastOrDefault();
#endif
2021-05-13 20:16:41 +02:00
}
}
}