Fix couple issues with starting mode.

This commit is contained in:
Burak Kaan Köse
2026-02-27 10:22:52 +01:00
parent 4b22608bc5
commit e1ce85698c
4 changed files with 165 additions and 79 deletions
@@ -221,10 +221,17 @@ public partial class WinoCalendarControl : Control
} }
private void UpdateIdleState() private void UpdateIdleState()
{
if (InternalFlipView != null)
{ {
InternalFlipView.Opacity = IsFlipIdle ? 0 : 1; InternalFlipView.Opacity = IsFlipIdle ? 0 : 1;
}
if (IdleGrid != null)
{
IdleGrid.Visibility = IsFlipIdle ? Visibility.Visible : Visibility.Collapsed; IdleGrid.Visibility = IsFlipIdle ? Visibility.Visible : Visibility.Collapsed;
} }
}
private void ActiveTimelineCellUnselected(object sender, TimelineCellUnselectedArgs e) private void ActiveTimelineCellUnselected(object sender, TimelineCellUnselectedArgs e)
=> TimelineCellUnselected?.Invoke(this, e); => TimelineCellUnselected?.Invoke(this, e);
@@ -49,6 +49,8 @@ public partial class WinoCalendarFlipView : CustomCalendarFlipView
internal event EventHandler<ProgrammaticNavigationCompletedEventArgs>? ProgrammaticNavigationCompleted; internal event EventHandler<ProgrammaticNavigationCompletedEventArgs>? ProgrammaticNavigationCompleted;
private INotifyCollectionChanged? _trackedItemsSource;
public WinoCalendarFlipView() public WinoCalendarFlipView()
{ {
RegisterPropertyChangedCallback(ItemsSourceProperty, new DependencyPropertyChangedCallback(OnItemsSourceChanged)); RegisterPropertyChangedCallback(ItemsSourceProperty, new DependencyPropertyChangedCallback(OnItemsSourceChanged));
@@ -64,10 +66,19 @@ public partial class WinoCalendarFlipView : CustomCalendarFlipView
private void RegisterItemsSourceChange() private void RegisterItemsSourceChange()
{ {
if (GetItemsSource() is INotifyCollectionChanged notifyCollectionChanged) if (_trackedItemsSource != null)
{ {
notifyCollectionChanged.CollectionChanged += ItemsSourceUpdated; _trackedItemsSource.CollectionChanged -= ItemsSourceUpdated;
} }
_trackedItemsSource = GetItemsSource();
if (_trackedItemsSource != null)
{
_trackedItemsSource.CollectionChanged += ItemsSourceUpdated;
}
UpdateIdleState();
} }
protected override void OnSelectedItemChanged(object oldValue, object newValue) protected override void OnSelectedItemChanged(object oldValue, object newValue)
@@ -92,7 +103,13 @@ public partial class WinoCalendarFlipView : CustomCalendarFlipView
private void ItemsSourceUpdated(object sender, NotifyCollectionChangedEventArgs e) private void ItemsSourceUpdated(object sender, NotifyCollectionChangedEventArgs e)
{ {
IsIdle = e.Action == NotifyCollectionChangedAction.Reset || e.Action == NotifyCollectionChangedAction.Replace; UpdateIdleState();
}
private void UpdateIdleState()
{
var itemsSource = GetItemsSource();
IsIdle = itemsSource == null || itemsSource.Count == 0;
} }
private void UpdateActiveElements() private void UpdateActiveElements()
@@ -25,6 +25,8 @@ public partial class AccountCalendarStateService : ObservableRecipient,
IRecipient<CalendarListDeleted>, IRecipient<CalendarListDeleted>,
IRecipient<AccountRemovedMessage> IRecipient<AccountRemovedMessage>
{ {
private readonly object _calendarStateLock = new();
public IDispatcher? Dispatcher { get; set; } public IDispatcher? Dispatcher { get; set; }
public event EventHandler<GroupedAccountCalendarViewModel>? CollectiveAccountGroupSelectionStateChanged; public event EventHandler<GroupedAccountCalendarViewModel>? CollectiveAccountGroupSelectionStateChanged;
@@ -42,19 +44,27 @@ public partial class AccountCalendarStateService : ObservableRecipient,
public IEnumerable<AccountCalendarViewModel> ActiveCalendars public IEnumerable<AccountCalendarViewModel> ActiveCalendars
{ {
get get
{
lock (_calendarStateLock)
{ {
return _internalGroupedAccountCalendars return _internalGroupedAccountCalendars
.SelectMany(a => a.AccountCalendars) .SelectMany(a => a.AccountCalendars)
.Where(b => b.IsChecked); .Where(b => b.IsChecked)
.ToList();
}
} }
} }
public IEnumerable<AccountCalendarViewModel> AllCalendars public IEnumerable<AccountCalendarViewModel> AllCalendars
{ {
get get
{
lock (_calendarStateLock)
{ {
return _internalGroupedAccountCalendars return _internalGroupedAccountCalendars
.SelectMany(a => a.AccountCalendars); .SelectMany(a => a.AccountCalendars)
.ToList();
}
} }
} }
@@ -83,6 +93,8 @@ public partial class AccountCalendarStateService : ObservableRecipient,
=> AccountCalendarSelectionStateChanged?.Invoke(this, e); => AccountCalendarSelectionStateChanged?.Invoke(this, e);
public void AddGroupedAccountCalendar(GroupedAccountCalendarViewModel groupedAccountCalendar) public void AddGroupedAccountCalendar(GroupedAccountCalendarViewModel groupedAccountCalendar)
{
lock (_calendarStateLock)
{ {
groupedAccountCalendar.CalendarSelectionStateChanged += SingleCalendarSelectionStateChanged; groupedAccountCalendar.CalendarSelectionStateChanged += SingleCalendarSelectionStateChanged;
groupedAccountCalendar.CollectiveSelectionStateChanged += SingleGroupCalendarCollectiveStateChanged; groupedAccountCalendar.CollectiveSelectionStateChanged += SingleGroupCalendarCollectiveStateChanged;
@@ -103,8 +115,11 @@ public partial class AccountCalendarStateService : ObservableRecipient,
} }
} }
} }
}
public void RemoveGroupedAccountCalendar(GroupedAccountCalendarViewModel groupedAccountCalendar) public void RemoveGroupedAccountCalendar(GroupedAccountCalendarViewModel groupedAccountCalendar)
{
lock (_calendarStateLock)
{ {
groupedAccountCalendar.CalendarSelectionStateChanged -= SingleCalendarSelectionStateChanged; groupedAccountCalendar.CalendarSelectionStateChanged -= SingleCalendarSelectionStateChanged;
groupedAccountCalendar.CollectiveSelectionStateChanged -= SingleGroupCalendarCollectiveStateChanged; groupedAccountCalendar.CollectiveSelectionStateChanged -= SingleGroupCalendarCollectiveStateChanged;
@@ -126,16 +141,22 @@ public partial class AccountCalendarStateService : ObservableRecipient,
} }
} }
} }
}
public void ClearGroupedAccountCalendars() public void ClearGroupedAccountCalendars()
{
lock (_calendarStateLock)
{ {
while (_internalGroupedAccountCalendars.Any()) while (_internalGroupedAccountCalendars.Any())
{ {
RemoveGroupedAccountCalendar(_internalGroupedAccountCalendars[0]); RemoveGroupedAccountCalendar(_internalGroupedAccountCalendars[0]);
} }
} }
}
public void AddAccountCalendar(AccountCalendarViewModel accountCalendar) public void AddAccountCalendar(AccountCalendarViewModel accountCalendar)
{
lock (_calendarStateLock)
{ {
// Find the group that this calendar belongs to. // Find the group that this calendar belongs to.
var group = _internalGroupedAccountCalendars.FirstOrDefault(g => g.Account.Id == accountCalendar.Account.Id); var group = _internalGroupedAccountCalendars.FirstOrDefault(g => g.Account.Id == accountCalendar.Account.Id);
@@ -162,8 +183,11 @@ public partial class AccountCalendarStateService : ObservableRecipient,
} }
} }
} }
}
public void RemoveAccountCalendar(AccountCalendarViewModel accountCalendar) public void RemoveAccountCalendar(AccountCalendarViewModel accountCalendar)
{
lock (_calendarStateLock)
{ {
var group = _internalGroupedAccountCalendars.FirstOrDefault(g => g.Account.Id == accountCalendar.Account.Id); var group = _internalGroupedAccountCalendars.FirstOrDefault(g => g.Account.Id == accountCalendar.Account.Id);
@@ -189,6 +213,7 @@ public partial class AccountCalendarStateService : ObservableRecipient,
RemoveGroupedAccountCalendar(group); RemoveGroupedAccountCalendar(group);
} }
} }
}
public async void Receive(CalendarListAdded message) public async void Receive(CalendarListAdded message)
{ {
@@ -289,7 +314,11 @@ public partial class AccountCalendarStateService : ObservableRecipient,
{ {
await Dispatcher.ExecuteOnUIThread(() => await Dispatcher.ExecuteOnUIThread(() =>
{ {
var groupedAccount = _internalGroupedAccountCalendars.FirstOrDefault(a => a.Account.Id == removedAccountId); GroupedAccountCalendarViewModel? groupedAccount;
lock (_calendarStateLock)
{
groupedAccount = _internalGroupedAccountCalendars.FirstOrDefault(a => a.Account.Id == removedAccountId);
}
if (groupedAccount != null) if (groupedAccount != null)
{ {
@@ -299,7 +328,11 @@ public partial class AccountCalendarStateService : ObservableRecipient,
} }
else else
{ {
var groupedAccount = _internalGroupedAccountCalendars.FirstOrDefault(a => a.Account.Id == removedAccountId); GroupedAccountCalendarViewModel? groupedAccount;
lock (_calendarStateLock)
{
groupedAccount = _internalGroupedAccountCalendars.FirstOrDefault(a => a.Account.Id == removedAccountId);
}
if (groupedAccount != null) if (groupedAccount != null)
{ {
+32 -3
View File
@@ -35,6 +35,21 @@ public class NavigationService : NavigationServiceBase, INavigationService
WinoPage.ComposePage WinoPage.ComposePage
}; };
private static readonly WinoPage[] MailOnlyPages =
[
WinoPage.MailListPage,
WinoPage.MailRenderingPage,
WinoPage.ComposePage,
WinoPage.IdlePage,
WinoPage.WelcomePage
];
private static readonly WinoPage[] CalendarOnlyPages =
[
WinoPage.CalendarPage,
WinoPage.EventDetailsPage
];
public NavigationService(IStatePersistanceService statePersistanceService) public NavigationService(IStatePersistanceService statePersistanceService)
{ {
_statePersistanceService = statePersistanceService; _statePersistanceService = statePersistanceService;
@@ -140,9 +155,17 @@ public class NavigationService : NavigationServiceBase, INavigationService
var pageType = GetPageType(page); var pageType = GetPageType(page);
if (pageType == null) return false; if (pageType == null) return false;
var currentApplicationMode = GetCoreFrame(NavigationReferenceFrame.ShellFrame)?.Content?.GetType() == typeof(MailAppShell) var currentApplicationMode = _statePersistanceService.ApplicationMode;
? WinoApplicationMode.Mail
: WinoApplicationMode.Calendar; if (currentApplicationMode == WinoApplicationMode.Calendar && IsMailOnlyPage(page))
{
return false;
}
if (currentApplicationMode == WinoApplicationMode.Mail && IsCalendarOnlyPage(page))
{
return false;
}
_statePersistanceService.IsReadingMail = _renderingPageTypes.Contains(page); _statePersistanceService.IsReadingMail = _renderingPageTypes.Contains(page);
_statePersistanceService.IsEventDetailsVisible = page == WinoPage.EventDetailsPage; _statePersistanceService.IsEventDetailsVisible = page == WinoPage.EventDetailsPage;
@@ -248,6 +271,12 @@ public class NavigationService : NavigationServiceBase, INavigationService
return false; return false;
} }
private static bool IsMailOnlyPage(WinoPage page)
=> MailOnlyPages.Contains(page);
private static bool IsCalendarOnlyPage(WinoPage page)
=> CalendarOnlyPages.Contains(page);
private static LoadCalendarMessage CreateLoadCalendarMessage(CalendarPageNavigationArgs args) private static LoadCalendarMessage CreateLoadCalendarMessage(CalendarPageNavigationArgs args)
{ {
var targetDate = args.RequestDefaultNavigation var targetDate = args.RequestDefaultNavigation