sharee.bike-App/LastenradBayern/TINK/View/RootFlyout/RootPage.xaml.cs

96 lines
2.6 KiB
C#
Raw Normal View History

2023-04-19 12:14:14 +02:00
using System;
using TINK.Model.Stations;
2021-11-07 19:42:59 +01:00
#if USEFLYOUT
using TINK.View.MasterDetail;
#endif
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace TINK.View.Root
{
2022-09-06 16:08:19 +02:00
/// <summary>
2023-04-19 12:14:14 +02:00
/// Manages creation of detail pages if a flyout page menu entry is selected.
2022-09-06 16:08:19 +02:00
/// Exposes flyout page style navigation which is used by detail pages.
/// </summary>
/// <remarks>
/// Examples of use cases when detail pages do navigation:
2023-04-19 12:14:14 +02:00
// - switch to map page after successfully logging in/ logging out
2022-09-06 16:08:19 +02:00
// - switch to login page form bikes at station page if not yet logged in
/// </remarks>
[XamlCompilation(XamlCompilationOptions.Compile)]
2021-11-07 19:42:59 +01:00
#if USEFLYOUT
public partial class RootPage : FlyoutPage, INavigationMasterDetail
#else
2022-09-06 16:08:19 +02:00
public partial class RootPage : FlyoutPage
2021-11-07 19:42:59 +01:00
#endif
2022-09-06 16:08:19 +02:00
{
public RootPage()
{
InitializeComponent();
FlyoutPage.ListView.ItemSelected += OnListViewItemSelected;
2021-11-07 19:42:59 +01:00
2023-04-19 12:14:14 +02:00
// Any type of split behavior conflicts with map shifting functionality (assuming FlyoutPage behaves same like MasterDetailPage).
2022-09-06 16:08:19 +02:00
FlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover;
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
var navigationPage = Detail as NavigationPage;
if (navigationPage == null)
{
return;
}
2021-11-07 19:42:59 +01:00
#if USEFLYOUT
var detailPage = navigationPage.RootPage as IDetailPage;
if (detailPage == null)
{
return;
}
detailPage.NavigationMasterDetail = this;
#endif
2022-09-06 16:08:19 +02:00
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Is called if a flyout page menu entry is selected.
/// Creates a new page.
/// </summary>
private void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if (!(e.SelectedItem is RootPageFlyoutMenuItem item))
{
// Unexpected argument detected.
return;
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
// Set selected station to new
2023-04-19 12:14:14 +02:00
App.ModelRoot.SelectedStation = new TINK.Model.Stations.StationNS.NullStation();
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
ShowPage(item.TargetType, item.Title);
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
IsPresented = false;
FlyoutPage.ListView.SelectedItem = null;
}
2021-11-07 19:42:59 +01:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Shows a detail page.
/// </summary>
/// <param name="typeOfPage">Type of page to show.</param>
/// <param name="title">Title of page.</param>
public void ShowPage(Type typeOfPage, string title)
{
var page = (Page)Activator.CreateInstance(typeOfPage);
page.Title = title;
2021-11-07 19:42:59 +01:00
#if USEFLYOUT
if (page is IDetailPage detailPage)
{
// Detail page needs reference to perform navigation.
// Examples see above in xdoc of class.
detailPage.NavigationMasterDetail = this;
}
#endif
2022-09-06 16:08:19 +02:00
Detail = new NavigationPage(page);
}
}
2023-04-19 12:14:14 +02:00
}