From 70ac2d2bea288732adbd268ec3b77000e5f15fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Tue, 30 Dec 2025 10:36:27 +0100 Subject: [PATCH] New grouped collection for quick event dialog. --- .../IAccountCalendarStateService.cs | 3 + .../Entities/Shared/MailAccount.cs | 2 + .../Services/AccountCalendarStateService.cs | 60 +++++++++++++++++++ .../Views/Calendar/CalendarPage.xaml | 8 +-- 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/Wino.Calendar.ViewModels/Interfaces/IAccountCalendarStateService.cs b/Wino.Calendar.ViewModels/Interfaces/IAccountCalendarStateService.cs index 014ede02..79b9507f 100644 --- a/Wino.Calendar.ViewModels/Interfaces/IAccountCalendarStateService.cs +++ b/Wino.Calendar.ViewModels/Interfaces/IAccountCalendarStateService.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using CommunityToolkit.Mvvm.Collections; using Wino.Calendar.ViewModels.Data; +using Wino.Core.Domain.Entities.Shared; namespace Wino.Calendar.ViewModels.Interfaces; @@ -25,4 +27,5 @@ public interface IAccountCalendarStateService : INotifyPropertyChanged /// IEnumerable ActiveCalendars { get; } IEnumerable AllCalendars { get; } + ReadOnlyObservableGroupedCollection GroupedCalendars { get; set; } } diff --git a/Wino.Core.Domain/Entities/Shared/MailAccount.cs b/Wino.Core.Domain/Entities/Shared/MailAccount.cs index 8f40f70d..c6935095 100644 --- a/Wino.Core.Domain/Entities/Shared/MailAccount.cs +++ b/Wino.Core.Domain/Entities/Shared/MailAccount.cs @@ -107,4 +107,6 @@ public class MailAccount /// Gets whether the account can perform AliasInformation sync type. /// public bool IsAliasSyncSupported => ProviderType == MailProviderType.Gmail; + + public override string ToString() => Name; } diff --git a/Wino.Mail.WinUI/Services/AccountCalendarStateService.cs b/Wino.Mail.WinUI/Services/AccountCalendarStateService.cs index 1ae0bdfa..c42887a3 100644 --- a/Wino.Mail.WinUI/Services/AccountCalendarStateService.cs +++ b/Wino.Mail.WinUI/Services/AccountCalendarStateService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using CommunityToolkit.Mvvm.Collections; using CommunityToolkit.Mvvm.ComponentModel; using Wino.Calendar.ViewModels.Data; using Wino.Calendar.ViewModels.Interfaces; @@ -19,10 +20,14 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal public event EventHandler? AccountCalendarSelectionStateChanged; private readonly ObservableCollection _internalGroupedAccountCalendars; + private readonly ObservableGroupedCollection _internalGroupedCalendars; [ObservableProperty] public partial ReadOnlyObservableCollection GroupedAccountCalendars { get; set; } + [ObservableProperty] + public partial ReadOnlyObservableGroupedCollection GroupedCalendars { get; set; } + public IEnumerable ActiveCalendars { get @@ -46,6 +51,9 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal { _internalGroupedAccountCalendars = new ObservableCollection(); GroupedAccountCalendars = new ReadOnlyObservableCollection(_internalGroupedAccountCalendars); + + _internalGroupedCalendars = new ObservableGroupedCollection(); + GroupedCalendars = new ReadOnlyObservableGroupedCollection(_internalGroupedCalendars); } private void SingleGroupCalendarCollectiveStateChanged(object? sender, EventArgs e) @@ -60,6 +68,20 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal groupedAccountCalendar.CollectiveSelectionStateChanged += SingleGroupCalendarCollectiveStateChanged; _internalGroupedAccountCalendars.Add(groupedAccountCalendar); + + // Maintain the grouped calendars collection + var group = _internalGroupedCalendars.FirstOrDefault>(g => g.Key.Id == groupedAccountCalendar.Account.Id); + if (group == null) + { + _internalGroupedCalendars.Add(new ObservableGroup(groupedAccountCalendar.Account, groupedAccountCalendar.AccountCalendars)); + } + else + { + foreach (var calendar in groupedAccountCalendar.AccountCalendars) + { + group.Add(calendar); + } + } } public void RemoveGroupedAccountCalendar(GroupedAccountCalendarViewModel groupedAccountCalendar) @@ -68,6 +90,21 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal groupedAccountCalendar.CollectiveSelectionStateChanged -= SingleGroupCalendarCollectiveStateChanged; _internalGroupedAccountCalendars.Remove(groupedAccountCalendar); + + // Maintain the grouped calendars collection + var group = _internalGroupedCalendars.FirstOrDefault>(g => g.Key.Id == groupedAccountCalendar.Account.Id); + if (group != null) + { + foreach (var calendar in groupedAccountCalendar.AccountCalendars.ToList()) + { + group.Remove(calendar); + } + + if (group.Count == 0) + { + _internalGroupedCalendars.Remove(group); + } + } } public void ClearGroupedAccountCalendars() @@ -92,6 +129,17 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal else { group.AccountCalendars.Add(accountCalendar); + + // Maintain the grouped calendars collection + var calendarGroup = _internalGroupedCalendars.FirstOrDefault>(g => g.Key.Id == accountCalendar.Account.Id); + if (calendarGroup == null) + { + _internalGroupedCalendars.Add(new ObservableGroup(accountCalendar.Account, new[] { accountCalendar })); + } + else + { + calendarGroup.Add(accountCalendar); + } } } @@ -104,6 +152,18 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal group.AccountCalendars.Remove(accountCalendar); + // Maintain the grouped calendars collection + var calendarGroup = _internalGroupedCalendars.FirstOrDefault>(g => g.Key.Id == accountCalendar.Account.Id); + if (calendarGroup != null) + { + calendarGroup.Remove(accountCalendar); + + if (calendarGroup.Count == 0) + { + _internalGroupedCalendars.Remove(calendarGroup); + } + } + if (group.AccountCalendars.Count == 0) { RemoveGroupedAccountCalendar(group); diff --git a/Wino.Mail.WinUI/Views/Calendar/CalendarPage.xaml b/Wino.Mail.WinUI/Views/Calendar/CalendarPage.xaml index 38e3c60d..7777a78e 100644 --- a/Wino.Mail.WinUI/Views/Calendar/CalendarPage.xaml +++ b/Wino.Mail.WinUI/Views/Calendar/CalendarPage.xaml @@ -13,14 +13,14 @@ xmlns:local="using:Wino.Calendar.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" - xmlns:shared="using:Wino.Core.Domain.Entities.Shared" + xmlns:shared="using:Wino.Core.Domain.Entities.Shared" xmlns:collections="using:CommunityToolkit.Mvvm.Collections" mc:Ignorable="d"> + Source="{x:Bind ViewModel.AccountCalendarStateService.GroupedCalendars, Mode=OneWay}" /> - + + Text="{x:Bind Key.ToString()}" />