Improved shell experience.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
x:Class="Wino.Mail.WinUI.Controls.AppModeFooterSwitcherControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:domain="using:Wino.Core.Domain"
|
||||
Loaded="ControlLoaded"
|
||||
@@ -27,6 +28,11 @@
|
||||
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
||||
</controls:SegmentedItem.Icon>
|
||||
</controls:SegmentedItem>
|
||||
<controls:SegmentedItem ToolTipService.ToolTip="{x:Bind domain:Translator.MenuSettings, Mode=OneWay}">
|
||||
<controls:SegmentedItem.Icon>
|
||||
<SymbolIcon Symbol="Setting" />
|
||||
</controls:SegmentedItem.Icon>
|
||||
</controls:SegmentedItem>
|
||||
</controls:Segmented>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain;
|
||||
|
||||
namespace Wino.Mail.WinUI.Controls;
|
||||
|
||||
@@ -44,6 +45,13 @@ public sealed partial class AppModeFooterSwitcherControl : UserControl
|
||||
if (_isUpdatingSelection)
|
||||
return;
|
||||
|
||||
if (ModeSegmentedControl.SelectedIndex == 3)
|
||||
{
|
||||
_navigationService.Navigate(WinoPage.SettingsPage);
|
||||
UpdateSelection(_statePersistenceService.ApplicationMode);
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedMode = ModeSegmentedControl.SelectedIndex switch
|
||||
{
|
||||
1 => WinoApplicationMode.Calendar,
|
||||
|
||||
@@ -49,6 +49,7 @@ public partial class CustomCalendarFlipView : FlipView
|
||||
HideButton(PreviousButtonVertical);
|
||||
HideButton(NextButtonVertical);
|
||||
|
||||
SelectionChanged -= FlipViewSelectionChanged;
|
||||
SelectionChanged += FlipViewSelectionChanged;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using Wino.Helpers;
|
||||
|
||||
namespace Wino.Calendar.Controls;
|
||||
|
||||
public partial class WinoCalendarControl : Control
|
||||
public partial class WinoCalendarControl : Control, IDisposable
|
||||
{
|
||||
private const string PART_WinoFlipView = nameof(PART_WinoFlipView);
|
||||
private const string PART_IdleGrid = nameof(PART_IdleGrid);
|
||||
@@ -93,6 +93,12 @@ public partial class WinoCalendarControl : Control
|
||||
partial void OnIsFlipIdleChanged(bool newValue)
|
||||
=> UpdateIdleState();
|
||||
|
||||
partial void OnDayRangesChanged(ObservableCollection<DayRangeRenderModel>? newValue)
|
||||
=> EnsureStableSelection();
|
||||
|
||||
partial void OnSelectedFlipViewDayRangeChanged(DayRangeRenderModel? newValue)
|
||||
=> EnsureStableSelection();
|
||||
|
||||
partial void OnActiveScrollViewerPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var newValue = e.NewValue as ScrollViewer;
|
||||
@@ -200,6 +206,23 @@ public partial class WinoCalendarControl : Control
|
||||
if (InternalFlipView != null)
|
||||
{
|
||||
InternalFlipView.ProgrammaticNavigationCompleted -= InternalFlipViewProgrammaticNavigationCompleted;
|
||||
|
||||
if (InternalFlipView is IDisposable disposableFlipView)
|
||||
{
|
||||
disposableFlipView.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
if (_previousScrollViewer != null)
|
||||
{
|
||||
DeregisterScrollChanges(_previousScrollViewer);
|
||||
_previousScrollViewer = null;
|
||||
}
|
||||
|
||||
if (_previousCanvas != null)
|
||||
{
|
||||
DeregisterCanvas(_previousCanvas);
|
||||
_previousCanvas = null;
|
||||
}
|
||||
|
||||
InternalFlipView = GetTemplateChild(PART_WinoFlipView) as WinoCalendarFlipView;
|
||||
@@ -213,6 +236,7 @@ public partial class WinoCalendarControl : Control
|
||||
UpdateIdleState();
|
||||
ManageCalendarOrientation();
|
||||
ManageDisplayType();
|
||||
EnsureStableSelection();
|
||||
}
|
||||
|
||||
private void InternalFlipViewProgrammaticNavigationCompleted(object? sender, ProgrammaticNavigationCompletedEventArgs e)
|
||||
@@ -233,6 +257,33 @@ public partial class WinoCalendarControl : Control
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureStableSelection()
|
||||
{
|
||||
if (InternalFlipView == null || DayRanges == null || DayRanges.Count == 0)
|
||||
return;
|
||||
|
||||
var targetIndex = SelectedFlipViewIndex;
|
||||
|
||||
if (SelectedFlipViewDayRange != null)
|
||||
{
|
||||
var selectedRangeIndex = DayRanges.IndexOf(SelectedFlipViewDayRange);
|
||||
if (selectedRangeIndex >= 0)
|
||||
{
|
||||
targetIndex = selectedRangeIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetIndex < 0 || targetIndex >= DayRanges.Count)
|
||||
{
|
||||
targetIndex = 0;
|
||||
}
|
||||
|
||||
if (InternalFlipView.SelectedIndex != targetIndex)
|
||||
{
|
||||
InternalFlipView.SelectedIndex = targetIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private void ActiveTimelineCellUnselected(object? sender, TimelineCellUnselectedArgs e)
|
||||
=> TimelineCellUnselected?.Invoke(this, e);
|
||||
|
||||
@@ -291,4 +342,40 @@ public partial class WinoCalendarControl : Control
|
||||
{
|
||||
return this.FindDescendants<CalendarItemControl>().FirstOrDefault(a => a.CalendarItem == calendarItemViewModel)!;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
SizeChanged -= CalendarSizeChanged;
|
||||
|
||||
if (_previousScrollViewer != null)
|
||||
{
|
||||
DeregisterScrollChanges(_previousScrollViewer);
|
||||
_previousScrollViewer = null;
|
||||
}
|
||||
|
||||
if (_previousCanvas != null)
|
||||
{
|
||||
DeregisterCanvas(_previousCanvas);
|
||||
_previousCanvas = null;
|
||||
}
|
||||
|
||||
if (InternalFlipView != null)
|
||||
{
|
||||
InternalFlipView.ProgrammaticNavigationCompleted -= InternalFlipViewProgrammaticNavigationCompleted;
|
||||
|
||||
if (InternalFlipView is IDisposable disposableFlipView)
|
||||
{
|
||||
disposableFlipView.Dispose();
|
||||
}
|
||||
|
||||
InternalFlipView = null;
|
||||
}
|
||||
|
||||
IdleGrid = null;
|
||||
ActiveCanvas = null;
|
||||
ActiveScrollViewer = null;
|
||||
TimelineCellSelected = null;
|
||||
TimelineCellUnselected = null;
|
||||
ScrollPositionChanging = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using Wino.Core.Domain.Models.Calendar;
|
||||
|
||||
namespace Wino.Calendar.Controls;
|
||||
|
||||
public partial class WinoCalendarFlipView : CustomCalendarFlipView
|
||||
public partial class WinoCalendarFlipView : CustomCalendarFlipView, IDisposable
|
||||
{
|
||||
public static readonly DependencyProperty IsIdleProperty = DependencyProperty.Register(nameof(IsIdle), typeof(bool), typeof(WinoCalendarFlipView), new PropertyMetadata(true));
|
||||
public static readonly DependencyProperty ActiveCanvasProperty = DependencyProperty.Register(nameof(ActiveCanvas), typeof(WinoDayTimelineCanvas), typeof(WinoCalendarFlipView), new PropertyMetadata(null));
|
||||
@@ -50,10 +50,11 @@ public partial class WinoCalendarFlipView : CustomCalendarFlipView
|
||||
internal event EventHandler<ProgrammaticNavigationCompletedEventArgs>? ProgrammaticNavigationCompleted;
|
||||
|
||||
private INotifyCollectionChanged? _trackedItemsSource;
|
||||
private readonly long _itemsSourceCallbackToken;
|
||||
|
||||
public WinoCalendarFlipView()
|
||||
{
|
||||
RegisterPropertyChangedCallback(ItemsSourceProperty, new DependencyPropertyChangedCallback(OnItemsSourceChanged));
|
||||
_itemsSourceCallbackToken = RegisterPropertyChangedCallback(ItemsSourceProperty, new DependencyPropertyChangedCallback(OnItemsSourceChanged));
|
||||
}
|
||||
|
||||
private static void OnItemsSourceChanged(DependencyObject d, DependencyProperty e)
|
||||
@@ -207,6 +208,18 @@ public partial class WinoCalendarFlipView : CustomCalendarFlipView
|
||||
|
||||
private ObservableRangeCollection<DayRangeRenderModel>? GetItemsSource()
|
||||
=> ItemsSource as ObservableRangeCollection<DayRangeRenderModel>;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_trackedItemsSource != null)
|
||||
{
|
||||
_trackedItemsSource.CollectionChanged -= ItemsSourceUpdated;
|
||||
_trackedItemsSource = null;
|
||||
}
|
||||
|
||||
UnregisterPropertyChangedCallback(ItemsSourceProperty, _itemsSourceCallbackToken);
|
||||
ProgrammaticNavigationCompleted = null;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ProgrammaticNavigationCompletedEventArgs : EventArgs
|
||||
|
||||
@@ -10,7 +10,7 @@ using Wino.Helpers;
|
||||
|
||||
namespace Wino.Calendar.Controls;
|
||||
|
||||
public partial class WinoCalendarView : Control
|
||||
public partial class WinoCalendarView : Control, IDisposable
|
||||
{
|
||||
private const string PART_DayViewItemBorder = nameof(PART_DayViewItemBorder);
|
||||
private const string PART_CalendarView = nameof(PART_CalendarView);
|
||||
@@ -54,6 +54,7 @@ public partial class WinoCalendarView : Control
|
||||
|
||||
|
||||
private CalendarView? CalendarView;
|
||||
private long _displayModeCallbackToken = -1;
|
||||
|
||||
public WinoCalendarView()
|
||||
{
|
||||
@@ -64,6 +65,17 @@ public partial class WinoCalendarView : Control
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
if (CalendarView != null)
|
||||
{
|
||||
CalendarView.SelectedDatesChanged -= InternalCalendarViewSelectionChanged;
|
||||
|
||||
if (_displayModeCallbackToken != -1)
|
||||
{
|
||||
CalendarView.UnregisterPropertyChangedCallback(CalendarView.DisplayModeProperty, _displayModeCallbackToken);
|
||||
_displayModeCallbackToken = -1;
|
||||
}
|
||||
}
|
||||
|
||||
CalendarView = GetTemplateChild(PART_CalendarView) as CalendarView;
|
||||
|
||||
Guard.IsNotNull(CalendarView, nameof(CalendarView));
|
||||
@@ -78,7 +90,7 @@ public partial class WinoCalendarView : Control
|
||||
// Everytime display mode changes, update the visible date range backgrounds.
|
||||
// If users go back from year -> month -> day, we need to update the visible date range backgrounds.
|
||||
|
||||
CalendarView.RegisterPropertyChangedCallback(CalendarView.DisplayModeProperty, (s, e) => UpdateVisibleDateRangeBackgrounds());
|
||||
_displayModeCallbackToken = CalendarView.RegisterPropertyChangedCallback(CalendarView.DisplayModeProperty, (s, e) => UpdateVisibleDateRangeBackgrounds());
|
||||
}
|
||||
|
||||
private void InternalCalendarViewSelectionChanged(CalendarView sender, CalendarViewSelectedDatesChangedEventArgs args)
|
||||
@@ -147,4 +159,20 @@ public partial class WinoCalendarView : Control
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (CalendarView == null)
|
||||
return;
|
||||
|
||||
CalendarView.SelectedDatesChanged -= InternalCalendarViewSelectionChanged;
|
||||
|
||||
if (_displayModeCallbackToken != -1)
|
||||
{
|
||||
CalendarView.UnregisterPropertyChangedCallback(CalendarView.DisplayModeProperty, _displayModeCallbackToken);
|
||||
_displayModeCallbackToken = -1;
|
||||
}
|
||||
|
||||
CalendarView = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user