New grouped collection for quick event dialog.
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Collections;
|
||||||
using Wino.Calendar.ViewModels.Data;
|
using Wino.Calendar.ViewModels.Data;
|
||||||
|
using Wino.Core.Domain.Entities.Shared;
|
||||||
|
|
||||||
namespace Wino.Calendar.ViewModels.Interfaces;
|
namespace Wino.Calendar.ViewModels.Interfaces;
|
||||||
|
|
||||||
@@ -25,4 +27,5 @@ public interface IAccountCalendarStateService : INotifyPropertyChanged
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IEnumerable<AccountCalendarViewModel> ActiveCalendars { get; }
|
IEnumerable<AccountCalendarViewModel> ActiveCalendars { get; }
|
||||||
IEnumerable<AccountCalendarViewModel> AllCalendars { get; }
|
IEnumerable<AccountCalendarViewModel> AllCalendars { get; }
|
||||||
|
ReadOnlyObservableGroupedCollection<MailAccount, AccountCalendarViewModel> GroupedCalendars { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,4 +107,6 @@ public class MailAccount
|
|||||||
/// Gets whether the account can perform AliasInformation sync type.
|
/// Gets whether the account can perform AliasInformation sync type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsAliasSyncSupported => ProviderType == MailProviderType.Gmail;
|
public bool IsAliasSyncSupported => ProviderType == MailProviderType.Gmail;
|
||||||
|
|
||||||
|
public override string ToString() => Name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using CommunityToolkit.Mvvm.Collections;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using Wino.Calendar.ViewModels.Data;
|
using Wino.Calendar.ViewModels.Data;
|
||||||
using Wino.Calendar.ViewModels.Interfaces;
|
using Wino.Calendar.ViewModels.Interfaces;
|
||||||
@@ -19,10 +20,14 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal
|
|||||||
public event EventHandler<AccountCalendarViewModel>? AccountCalendarSelectionStateChanged;
|
public event EventHandler<AccountCalendarViewModel>? AccountCalendarSelectionStateChanged;
|
||||||
|
|
||||||
private readonly ObservableCollection<GroupedAccountCalendarViewModel> _internalGroupedAccountCalendars;
|
private readonly ObservableCollection<GroupedAccountCalendarViewModel> _internalGroupedAccountCalendars;
|
||||||
|
private readonly ObservableGroupedCollection<MailAccount, AccountCalendarViewModel> _internalGroupedCalendars;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public partial ReadOnlyObservableCollection<GroupedAccountCalendarViewModel> GroupedAccountCalendars { get; set; }
|
public partial ReadOnlyObservableCollection<GroupedAccountCalendarViewModel> GroupedAccountCalendars { get; set; }
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public partial ReadOnlyObservableGroupedCollection<MailAccount, AccountCalendarViewModel> GroupedCalendars { get; set; }
|
||||||
|
|
||||||
public IEnumerable<AccountCalendarViewModel> ActiveCalendars
|
public IEnumerable<AccountCalendarViewModel> ActiveCalendars
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -46,6 +51,9 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal
|
|||||||
{
|
{
|
||||||
_internalGroupedAccountCalendars = new ObservableCollection<GroupedAccountCalendarViewModel>();
|
_internalGroupedAccountCalendars = new ObservableCollection<GroupedAccountCalendarViewModel>();
|
||||||
GroupedAccountCalendars = new ReadOnlyObservableCollection<GroupedAccountCalendarViewModel>(_internalGroupedAccountCalendars);
|
GroupedAccountCalendars = new ReadOnlyObservableCollection<GroupedAccountCalendarViewModel>(_internalGroupedAccountCalendars);
|
||||||
|
|
||||||
|
_internalGroupedCalendars = new ObservableGroupedCollection<MailAccount, AccountCalendarViewModel>();
|
||||||
|
GroupedCalendars = new ReadOnlyObservableGroupedCollection<MailAccount, AccountCalendarViewModel>(_internalGroupedCalendars);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SingleGroupCalendarCollectiveStateChanged(object? sender, EventArgs e)
|
private void SingleGroupCalendarCollectiveStateChanged(object? sender, EventArgs e)
|
||||||
@@ -60,6 +68,20 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal
|
|||||||
groupedAccountCalendar.CollectiveSelectionStateChanged += SingleGroupCalendarCollectiveStateChanged;
|
groupedAccountCalendar.CollectiveSelectionStateChanged += SingleGroupCalendarCollectiveStateChanged;
|
||||||
|
|
||||||
_internalGroupedAccountCalendars.Add(groupedAccountCalendar);
|
_internalGroupedAccountCalendars.Add(groupedAccountCalendar);
|
||||||
|
|
||||||
|
// Maintain the grouped calendars collection
|
||||||
|
var group = _internalGroupedCalendars.FirstOrDefault<ObservableGroup<MailAccount, AccountCalendarViewModel>>(g => g.Key.Id == groupedAccountCalendar.Account.Id);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
_internalGroupedCalendars.Add(new ObservableGroup<MailAccount, AccountCalendarViewModel>(groupedAccountCalendar.Account, groupedAccountCalendar.AccountCalendars));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var calendar in groupedAccountCalendar.AccountCalendars)
|
||||||
|
{
|
||||||
|
group.Add(calendar);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveGroupedAccountCalendar(GroupedAccountCalendarViewModel groupedAccountCalendar)
|
public void RemoveGroupedAccountCalendar(GroupedAccountCalendarViewModel groupedAccountCalendar)
|
||||||
@@ -68,6 +90,21 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal
|
|||||||
groupedAccountCalendar.CollectiveSelectionStateChanged -= SingleGroupCalendarCollectiveStateChanged;
|
groupedAccountCalendar.CollectiveSelectionStateChanged -= SingleGroupCalendarCollectiveStateChanged;
|
||||||
|
|
||||||
_internalGroupedAccountCalendars.Remove(groupedAccountCalendar);
|
_internalGroupedAccountCalendars.Remove(groupedAccountCalendar);
|
||||||
|
|
||||||
|
// Maintain the grouped calendars collection
|
||||||
|
var group = _internalGroupedCalendars.FirstOrDefault<ObservableGroup<MailAccount, AccountCalendarViewModel>>(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()
|
public void ClearGroupedAccountCalendars()
|
||||||
@@ -92,6 +129,17 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
group.AccountCalendars.Add(accountCalendar);
|
group.AccountCalendars.Add(accountCalendar);
|
||||||
|
|
||||||
|
// Maintain the grouped calendars collection
|
||||||
|
var calendarGroup = _internalGroupedCalendars.FirstOrDefault<ObservableGroup<MailAccount, AccountCalendarViewModel>>(g => g.Key.Id == accountCalendar.Account.Id);
|
||||||
|
if (calendarGroup == null)
|
||||||
|
{
|
||||||
|
_internalGroupedCalendars.Add(new ObservableGroup<MailAccount, AccountCalendarViewModel>(accountCalendar.Account, new[] { accountCalendar }));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
calendarGroup.Add(accountCalendar);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +152,18 @@ public partial class AccountCalendarStateService : ObservableObject, IAccountCal
|
|||||||
|
|
||||||
group.AccountCalendars.Remove(accountCalendar);
|
group.AccountCalendars.Remove(accountCalendar);
|
||||||
|
|
||||||
|
// Maintain the grouped calendars collection
|
||||||
|
var calendarGroup = _internalGroupedCalendars.FirstOrDefault<ObservableGroup<MailAccount, AccountCalendarViewModel>>(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)
|
if (group.AccountCalendars.Count == 0)
|
||||||
{
|
{
|
||||||
RemoveGroupedAccountCalendar(group);
|
RemoveGroupedAccountCalendar(group);
|
||||||
|
|||||||
@@ -13,14 +13,14 @@
|
|||||||
xmlns:local="using:Wino.Calendar.Views"
|
xmlns:local="using:Wino.Calendar.Views"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
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">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<CollectionViewSource
|
<CollectionViewSource
|
||||||
x:Name="GroupedCalendarEnumerableViewSource"
|
x:Name="GroupedCalendarEnumerableViewSource"
|
||||||
IsSourceGrouped="True"
|
IsSourceGrouped="True"
|
||||||
Source="{x:Bind ViewModel.AccountCalendarStateService.GroupedAccountCalendars, Mode=OneWay}" />
|
Source="{x:Bind ViewModel.AccountCalendarStateService.GroupedCalendars, Mode=OneWay}" />
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<Border
|
<Border
|
||||||
@@ -150,11 +150,11 @@
|
|||||||
<ListView.GroupStyle>
|
<ListView.GroupStyle>
|
||||||
<GroupStyle>
|
<GroupStyle>
|
||||||
<GroupStyle.HeaderTemplate>
|
<GroupStyle.HeaderTemplate>
|
||||||
<DataTemplate x:DataType="data:GroupedAccountCalendarViewModel">
|
<DataTemplate x:DataType="collections:IReadOnlyObservableGroup">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
FontSize="14"
|
FontSize="14"
|
||||||
FontWeight="SemiBold"
|
FontWeight="SemiBold"
|
||||||
Text="{x:Bind Account.Name}" />
|
Text="{x:Bind Key.ToString()}" />
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</GroupStyle.HeaderTemplate>
|
</GroupStyle.HeaderTemplate>
|
||||||
</GroupStyle>
|
</GroupStyle>
|
||||||
|
|||||||
Reference in New Issue
Block a user