Settings page and manage accounts navigation options.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using MoreLinq;
|
||||
using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using MoreLinq;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
@@ -13,7 +13,9 @@ using Wino.Views.Settings;
|
||||
|
||||
namespace Wino.Views;
|
||||
|
||||
public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient<BreadcrumbNavigationRequested>
|
||||
public sealed partial class SettingsPage : SettingsPageAbstract,
|
||||
IRecipient<BreadcrumbNavigationRequested>,
|
||||
IRecipient<BackBreadcrumNavigationRequested>
|
||||
{
|
||||
public ObservableCollection<BreadcrumbNavigationItemViewModel> PageHistory { get; set; } = [];
|
||||
|
||||
@@ -26,6 +28,10 @@ public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient<Brea
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
// Register for frame navigation events to track back button visibility
|
||||
SettingsFrame.Navigated -= SettingsFrameNavigated;
|
||||
SettingsFrame.Navigated += SettingsFrameNavigated;
|
||||
|
||||
SettingsFrame.Navigate(typeof(SettingOptionsPage), null, new SuppressNavigationTransitionInfo());
|
||||
|
||||
var initialRequest = new BreadcrumbNavigationRequested(Translator.MenuSettings, WinoPage.SettingOptionsPage);
|
||||
@@ -60,21 +66,29 @@ public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient<Brea
|
||||
|
||||
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
|
||||
{
|
||||
// Unregister frame navigation event
|
||||
SettingsFrame.Navigated -= SettingsFrameNavigated;
|
||||
|
||||
// Reset navigation state when leaving SettingsPage
|
||||
ViewModel.StatePersistenceService.IsSettingsNavigating = false;
|
||||
|
||||
base.OnNavigatingFrom(e);
|
||||
}
|
||||
|
||||
protected override void RegisterRecipients()
|
||||
{
|
||||
base.RegisterRecipients();
|
||||
|
||||
|
||||
WeakReferenceMessenger.Default.Register<BreadcrumbNavigationRequested>(this);
|
||||
WeakReferenceMessenger.Default.Register<BackBreadcrumNavigationRequested>(this);
|
||||
}
|
||||
|
||||
protected override void UnregisterRecipients()
|
||||
{
|
||||
base.UnregisterRecipients();
|
||||
|
||||
|
||||
WeakReferenceMessenger.Default.Unregister<BreadcrumbNavigationRequested>(this);
|
||||
WeakReferenceMessenger.Default.Unregister<BackBreadcrumNavigationRequested>(this);
|
||||
}
|
||||
|
||||
void IRecipient<BreadcrumbNavigationRequested>.Receive(BreadcrumbNavigationRequested message)
|
||||
@@ -90,16 +104,51 @@ public sealed partial class SettingsPage : SettingsPageAbstract, IRecipient<Brea
|
||||
PageHistory.Add(new BreadcrumbNavigationItemViewModel(message, true));
|
||||
}
|
||||
|
||||
private void SettingsFrameNavigated(object sender, NavigationEventArgs e)
|
||||
{
|
||||
// Update back button visibility based on whether we can go back within the frame
|
||||
ViewModel.StatePersistenceService.IsSettingsNavigating = SettingsFrame.CanGoBack;
|
||||
}
|
||||
|
||||
private void GoBackFrame(Core.Domain.Enums.NavigationTransitionEffect slideEffect)
|
||||
{
|
||||
if (SettingsFrame.CanGoBack)
|
||||
{
|
||||
PageHistory.RemoveAt(PageHistory.Count - 1);
|
||||
|
||||
var winuiEffect = slideEffect switch
|
||||
{
|
||||
Core.Domain.Enums.NavigationTransitionEffect.FromLeft => Microsoft.UI.Xaml.Media.Animation.SlideNavigationTransitionEffect.FromLeft,
|
||||
_ => Microsoft.UI.Xaml.Media.Animation.SlideNavigationTransitionEffect.FromRight,
|
||||
};
|
||||
|
||||
SettingsFrame.GoBack(new SlideNavigationTransitionInfo() { Effect = winuiEffect });
|
||||
|
||||
// Set the new last item as active
|
||||
if (PageHistory.Count > 0)
|
||||
{
|
||||
PageHistory.ForEach(a => a.IsActive = false);
|
||||
PageHistory[PageHistory.Count - 1].IsActive = true;
|
||||
}
|
||||
|
||||
// Update back button visibility after navigation
|
||||
ViewModel.StatePersistenceService.IsSettingsNavigating = SettingsFrame.CanGoBack;
|
||||
}
|
||||
}
|
||||
|
||||
private void BreadItemClicked(Microsoft.UI.Xaml.Controls.BreadcrumbBar sender, Microsoft.UI.Xaml.Controls.BreadcrumbBarItemClickedEventArgs args)
|
||||
{
|
||||
var clickedPageHistory = PageHistory[args.Index];
|
||||
var activeIndex = PageHistory.IndexOf(PageHistory.FirstOrDefault(a => a.IsActive));
|
||||
|
||||
// Trigger GoBack repeatedly until we reach the clicked breadcrumb item
|
||||
while (PageHistory.FirstOrDefault(a => a.IsActive) != clickedPageHistory)
|
||||
{
|
||||
SettingsFrame.GoBack(new SlideNavigationTransitionInfo() { Effect = SlideNavigationTransitionEffect.FromRight });
|
||||
PageHistory.RemoveAt(PageHistory.Count - 1);
|
||||
PageHistory[PageHistory.Count - 1].IsActive = true;
|
||||
ViewModel.NavigationService.GoBack();
|
||||
}
|
||||
}
|
||||
|
||||
public void Receive(BackBreadcrumNavigationRequested message)
|
||||
{
|
||||
GoBackFrame(message.SlideEffect);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user