diff --git a/src/HyPlayer.App/App.csproj b/src/HyPlayer.App/App.csproj index e2152d7..4cbd477 100644 --- a/src/HyPlayer.App/App.csproj +++ b/src/HyPlayer.App/App.csproj @@ -32,6 +32,7 @@ + @@ -108,6 +109,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile diff --git a/src/HyPlayer.App/App.xaml.cs b/src/HyPlayer.App/App.xaml.cs index 4772fc3..8f7c6fe 100644 --- a/src/HyPlayer.App/App.xaml.cs +++ b/src/HyPlayer.App/App.xaml.cs @@ -74,6 +74,7 @@ public App() Depository?.AddSingleton(); Depository?.AddSingleton(); Depository?.AddSingleton(); + Depository?.AddSingleton(); } /// diff --git a/src/HyPlayer.App/Interfaces/Services/INavigationService.cs b/src/HyPlayer.App/Interfaces/Services/INavigationService.cs index c85990a..1840d0d 100644 --- a/src/HyPlayer.App/Interfaces/Services/INavigationService.cs +++ b/src/HyPlayer.App/Interfaces/Services/INavigationService.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Navigation; @@ -22,5 +22,7 @@ bool CanGoBack bool NavigateTo(Page Page, object? parameter = null); + bool NavigateTo(string pageKey, object? parameter = null); + bool GoBack(); } diff --git a/src/HyPlayer.App/Interfaces/Services/INavigationViewService.cs b/src/HyPlayer.App/Interfaces/Services/INavigationViewService.cs new file mode 100644 index 0000000..af30b55 --- /dev/null +++ b/src/HyPlayer.App/Interfaces/Services/INavigationViewService.cs @@ -0,0 +1,28 @@ +using Microsoft.UI.Xaml.Controls; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyPlayer.Interfaces.Services +{ + interface INavigationViewService + { + IList? MenuItems + { + get; + } + + object? SettingsItem + { + get; + } + + void Initialize(NavigationView navigationView); + + void UnregisterEvents(); + + NavigationViewItem? GetSelectedItem(Type pageType); + } +} diff --git a/src/HyPlayer.App/Services/ActivationService.cs b/src/HyPlayer.App/Services/ActivationService.cs index a057ace..3d0cc1d 100644 --- a/src/HyPlayer.App/Services/ActivationService.cs +++ b/src/HyPlayer.App/Services/ActivationService.cs @@ -41,7 +41,7 @@ public async Task OnLaunchedAsync(object ActivateEventArgs) Window MainWindow = WindowHelper.CreateWindow(); if (ActivatedEventArgs.Kind == ExtendedActivationKind.Launch) { - App.GetService().NavigateTo(typeof(Views.Pages.HomePage), ActivateEventArgs); + App.GetService().NavigateTo(typeof(Views.Pages.ErrorPage), ActivateEventArgs); } MainWindow.Activate(); } diff --git a/src/HyPlayer.App/Services/NavigationService.cs b/src/HyPlayer.App/Services/NavigationService.cs index 4efa46e..fa94109 100644 --- a/src/HyPlayer.App/Services/NavigationService.cs +++ b/src/HyPlayer.App/Services/NavigationService.cs @@ -1,4 +1,4 @@ -using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; using Microsoft.UI.Xaml.Navigation; using System; @@ -8,6 +8,14 @@ namespace HyPlayer.Services { internal class NavigationService : INavigationService { + private readonly IPageService _pageService; + private object? _lastParameterUsed; + + public NavigationService(IPageService pageService) + { + _pageService = pageService; + } + public bool CanGoBack => App.contentFrame.CanGoBack; public Frame? Frame => App.contentFrame; @@ -24,7 +32,7 @@ public bool GoBack() else return false; } - public bool NavigateTo(Type Page, object parameter) + public bool NavigateTo(Type Page, object? parameter = null) { if (Frame != null) { @@ -36,7 +44,7 @@ public bool NavigateTo(Type Page, object parameter) } } - public bool NavigateTo(Page Page, object parameter) + public bool NavigateTo(Page Page, object? parameter = null) { if (Frame != null) { @@ -48,5 +56,26 @@ public bool NavigateTo(Page Page, object parameter) return false; } } + + public bool NavigateTo(string pageKey, object? parameter = null) + { + var pageType = _pageService.GetPageType(pageKey); + + if (Frame != null && (Frame.Content?.GetType() != pageType || (parameter != null && !parameter.Equals(_lastParameterUsed)))) + { + + var navigated = Frame.Navigate(pageType, parameter); + if (navigated) + { + _lastParameterUsed = parameter; + + } + + return navigated; + } + + return false; + } + } } diff --git a/src/HyPlayer.App/Services/NavigationViewService.cs b/src/HyPlayer.App/Services/NavigationViewService.cs new file mode 100644 index 0000000..3b58bed --- /dev/null +++ b/src/HyPlayer.App/Services/NavigationViewService.cs @@ -0,0 +1,66 @@ +using HyPlayer.Helpers; +using HyPlayer.Interfaces.Services; +using HyPlayer.ViewModels; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Navigation; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyPlayer.Services +{ + class NavigationViewService : INavigationViewService + { + private readonly INavigationService _navigationService; + private readonly IPageService _pageService; + private NavigationView? _navigationView; + + public NavigationViewService(INavigationService navigationService, IPageService pageService) + { + _navigationService = navigationService; + _pageService = pageService; + } + + public IList? MenuItems => _navigationView.MenuItems; + + public object? SettingsItem => _navigationView.SettingsItem; + + public NavigationViewItem? GetSelectedItem(Type pageType) + { + throw new NotImplementedException(); + } + + public void Initialize(NavigationView navigationView) + { + _navigationView = navigationView; + navigationView.ItemInvoked += OnItemInvoked; + navigationView.BackRequested += OnBackRequested; + } + + public void UnregisterEvents() + { + throw new NotImplementedException(); + } + + private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args) => _navigationService.GoBack(); + + private void OnItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args) + { + if (args.IsSettingsInvoked) + { + _navigationService.NavigateTo(typeof(SettingsViewModel).FullName!); + } + else + { + var selectedItem = args.InvokedItemContainer as NavigationViewItem; + + if (selectedItem?.GetValue(NavigationHelper.NavigateToProperty) is string pageKey) + { + _navigationService.NavigateTo(pageKey); + } + } + } + } +} diff --git a/src/HyPlayer.App/Services/PageService.cs b/src/HyPlayer.App/Services/PageService.cs index 657947c..b132fbf 100644 --- a/src/HyPlayer.App/Services/PageService.cs +++ b/src/HyPlayer.App/Services/PageService.cs @@ -20,6 +20,7 @@ public PageService() ConfigurePage(); ConfigurePage(); ConfigurePage(); + ConfigurePage(); } public Type GetPageType(string key) diff --git a/src/HyPlayer.App/ViewModels/SettingsViewModel.cs b/src/HyPlayer.App/ViewModels/SettingsViewModel.cs new file mode 100644 index 0000000..d4f651a --- /dev/null +++ b/src/HyPlayer.App/ViewModels/SettingsViewModel.cs @@ -0,0 +1,14 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using HyPlayer.Interfaces.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HyPlayer.ViewModels +{ + public partial class SettingsViewModel : ObservableObject, IScopedViewModel + { + } +} diff --git a/src/HyPlayer.App/ViewModels/ShellViewModel.cs b/src/HyPlayer.App/ViewModels/ShellViewModel.cs index 1dd9c21..2b6c2ee 100644 --- a/src/HyPlayer.App/ViewModels/ShellViewModel.cs +++ b/src/HyPlayer.App/ViewModels/ShellViewModel.cs @@ -8,12 +8,17 @@ namespace HyPlayer.ViewModels { public partial class ShellViewModel : ObservableObject, IScopedViewModel { + private readonly INavigationViewService _navigationViewService; + private readonly INavigationService _navigationService; + [ObservableProperty] private AccountViewModel _accountViewModel; public bool IsProgressBarVisible => App.GetService().IsProgressBarVisible; - public ShellViewModel(AccountViewModel accountViewModel) - { + public ShellViewModel(AccountViewModel accountViewModel, INavigationViewService navigationViewService, INavigationService navigationService) + { _accountViewModel = accountViewModel; + _navigationViewService = navigationViewService; + _navigationService = navigationService; } [RelayCommand] diff --git a/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml b/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml index 901c72c..d2a5685 100644 --- a/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml +++ b/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml @@ -5,6 +5,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:base="using:HyPlayer.Views.Controls.Base" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:helpers="using:HyPlayer.Helpers" xmlns:local="using:HyPlayer.Views.Controls.App" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> @@ -17,7 +18,6 @@ IsBackEnabled="True" IsPaneOpen="{x:Bind IsPaneOpen}" IsPaneToggleButtonVisible="True" - ItemInvoked="{x:Bind NavView_ItemInvoked}" Loaded="NavView_Loaded" Style="{StaticResource LeftNavViewDefaultStyle}"> @@ -28,7 +28,8 @@ + helpers:NavigationHelper.NavigateTo="HomePage" + Tag="HyPlayer.ViewModel.HomeViewModel"> diff --git a/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml.cs b/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml.cs index 777b24f..7ebac85 100644 --- a/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml.cs +++ b/src/HyPlayer.App/Views/Controls/App/DesktopNavigationView.xaml.cs @@ -21,20 +21,10 @@ public DesktopNavigationView() { this.InitializeComponent(); HyPlayer.App.contentFrame = contentFrame; + HyPlayer.App.GetService().Initialize(NavView); } - - private void NavView_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args) - { - var invokedItemTag = HyPlayer.App.GetService().GetPageType((args.InvokedItemContainer as NavigationViewItem)?.Tag?.ToString()); - var invokedItemName = (args.InvokedItemContainer as NavigationViewItem)?.Content?.ToString(); - - - HyPlayer.App.GetService().NavigateTo(invokedItemTag); - // NavView.Header = invokedItemName; - } - private void NavView_Loaded(object sender, RoutedEventArgs e) { NavView.SelectedItem = Home; diff --git a/src/HyPlayer.App/Views/Pages/SettingsPage.xaml b/src/HyPlayer.App/Views/Pages/SettingsPage.xaml new file mode 100644 index 0000000..0f24b0d --- /dev/null +++ b/src/HyPlayer.App/Views/Pages/SettingsPage.xaml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/src/HyPlayer.App/Views/Pages/SettingsPage.xaml.cs b/src/HyPlayer.App/Views/Pages/SettingsPage.xaml.cs new file mode 100644 index 0000000..cf5dfce --- /dev/null +++ b/src/HyPlayer.App/Views/Pages/SettingsPage.xaml.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using HyPlayer.Interfaces.Views; +using HyPlayer.ViewModels; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace HyPlayer.Views.Pages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class SettingsPage : SettingsPageBase + { + public SettingsPage() + { + this.InitializeComponent(); + } + } + + public class SettingsPageBase : AppPageWithScopedViewModelBase + { + + } +}