From 8e454c337529b364fabdf3d50ba26d82c47e8807 Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Sun, 12 Aug 2018 13:52:57 +0300 Subject: [PATCH] Navigation improvements --- FoxTube/Pages/MainPage.xaml.cs | 73 +++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/FoxTube/Pages/MainPage.xaml.cs b/FoxTube/Pages/MainPage.xaml.cs index 4836a23..e376243 100644 --- a/FoxTube/Pages/MainPage.xaml.cs +++ b/FoxTube/Pages/MainPage.xaml.cs @@ -48,6 +48,8 @@ namespace FoxTube /// An empty page that can be used on its own or navigated to within a Frame. /// + public enum Sender { Menu, Frame, None } + public sealed partial class MainPage : Page { public DownloadAgent Agent = new DownloadAgent(); @@ -55,6 +57,7 @@ namespace FoxTube ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; NotificationsCenter notificationsCenter = new NotificationsCenter(); + Sender s = Sender.None; public MainPage() { this.InitializeComponent(); @@ -389,27 +392,33 @@ namespace FoxTube private void nav_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) { - if (args.IsSettingsSelected) - content.Navigate(typeof(Settings)); - else + if (s == Sender.None) { - if (args.SelectedItem == toHome) - content.Navigate(typeof(Home)); - else if (args.SelectedItem == toHistory) + s = Sender.Menu; + if (args.IsSettingsSelected) content.Navigate(typeof(Settings)); - else if (args.SelectedItem == toLiked) - content.Navigate(typeof(PlaylistPage), SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.Likes); - else if (args.SelectedItem == toLater) - content.Navigate(typeof(PlaylistPage), SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.WatchLater); - else if (args.SelectedItem == toSubscriptions) - content.Navigate(typeof(Settings)); - else if (args.SelectedItem == toDownloads) - content.Navigate(typeof(Downloads)); - else if (args.SelectedItem == toChannel) - content.Navigate(typeof(Channel), SecretsVault.UserChannel.Id); else - content.Navigate(typeof(ChannelPage), SecretsVault.Subscriptions[Convert.ToInt32((args.SelectedItem as NavigationViewItem).Name)].Snippet.ResourceId.ChannelId); + { + if (args.SelectedItem == toHome) + content.Navigate(typeof(Home)); + else if (args.SelectedItem == toHistory) + content.Navigate(typeof(Settings)); + else if (args.SelectedItem == toLiked) + content.Navigate(typeof(PlaylistPage), SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.Likes); + else if (args.SelectedItem == toLater) + content.Navigate(typeof(PlaylistPage), SecretsVault.UserChannel.ContentDetails.RelatedPlaylists.WatchLater); + else if (args.SelectedItem == toSubscriptions) + content.Navigate(typeof(Settings)); + else if (args.SelectedItem == toDownloads) + content.Navigate(typeof(Downloads)); + else if (args.SelectedItem == toChannel) + content.Navigate(typeof(Channel), SecretsVault.UserChannel.Id); + else + content.Navigate(typeof(ChannelPage), SecretsVault.Subscriptions[Convert.ToInt32((args.SelectedItem as NavigationViewItem).Name)].Snippet.ResourceId.ChannelId); + } } + else if (s == Sender.Frame) + s = Sender.None; } private void content_Navigated(object sender, NavigationEventArgs e) @@ -425,7 +434,35 @@ namespace FoxTube { typeof(Downloads), () => header.Text = "Downloads" } }; - switchCase[e.SourcePageType](); + try { switchCase[e.SourcePageType](); } + catch { } + + if (s == Sender.None) + { + s = Sender.Frame; + + Dictionary navCase = new Dictionary() + { + { typeof(Settings), () => nav.SelectedItem = nav.SettingsItem }, + { typeof(ChannelPage), () => + { + //Check channel + } }, + { typeof(PlaylistPage), () => + { + //Check playlist + } }, + { typeof(Search), () => nav.SelectedItem = null }, + { typeof(History), () => nav.SelectedItem = toHistory }, + { typeof(Home), () => nav.SelectedItem = toHome }, + { typeof(Downloads), () => nav.SelectedItem = toDownloads } + }; + + try { navCase[e.SourcePageType](); } + catch { } + } + else if (s == Sender.Menu) + s = Sender.None; if (content.CanGoBack) nav.IsBackEnabled = true;