Some improvements on the quick event tip.

This commit is contained in:
Burak Kaan Köse
2024-12-31 22:22:19 +01:00
parent d524143a53
commit 068369fca2
6 changed files with 152 additions and 22 deletions

View File

@@ -36,6 +36,18 @@ namespace Wino.Calendar.ViewModels
[ObservableProperty] [ObservableProperty]
private DayRangeRenderModel _selectedDayRange; private DayRangeRenderModel _selectedDayRange;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(SelectedQuickEventAccountCalendarName))]
private AccountCalendarViewModel _selectedQuickEventAccountCalendar;
public string SelectedQuickEventAccountCalendarName
{
get
{
return SelectedQuickEventAccountCalendar == null ? "Pick a calendar" : SelectedQuickEventAccountCalendar.Name;
}
}
[ObservableProperty] [ObservableProperty]
private bool _isCalendarEnabled = true; private bool _isCalendarEnabled = true;
@@ -43,7 +55,6 @@ namespace Wino.Calendar.ViewModels
private const int maxDayRangeSize = 10; private const int maxDayRangeSize = 10;
private readonly ICalendarService _calendarService; private readonly ICalendarService _calendarService;
private readonly IAccountCalendarStateService _accountCalendarStateService;
private readonly IPreferencesService _preferencesService; private readonly IPreferencesService _preferencesService;
// Store latest rendered options. // Store latest rendered options.
@@ -55,6 +66,7 @@ namespace Wino.Calendar.ViewModels
private CalendarSettings _currentSettings = null; private CalendarSettings _currentSettings = null;
public IStatePersistanceService StatePersistanceService { get; } public IStatePersistanceService StatePersistanceService { get; }
public IAccountCalendarStateService AccountCalendarStateService { get; }
public CalendarPageViewModel(IStatePersistanceService statePersistanceService, public CalendarPageViewModel(IStatePersistanceService statePersistanceService,
ICalendarService calendarService, ICalendarService calendarService,
@@ -62,13 +74,13 @@ namespace Wino.Calendar.ViewModels
IPreferencesService preferencesService) IPreferencesService preferencesService)
{ {
StatePersistanceService = statePersistanceService; StatePersistanceService = statePersistanceService;
AccountCalendarStateService = accountCalendarStateService;
_calendarService = calendarService; _calendarService = calendarService;
_accountCalendarStateService = accountCalendarStateService;
_preferencesService = preferencesService; _preferencesService = preferencesService;
_accountCalendarStateService.AccountCalendarSelectionStateChanged += UpdateAccountCalendarRequested; AccountCalendarStateService.AccountCalendarSelectionStateChanged += UpdateAccountCalendarRequested;
_accountCalendarStateService.CollectiveAccountGroupSelectionStateChanged += AccountCalendarStateCollectivelyChanged; AccountCalendarStateService.CollectiveAccountGroupSelectionStateChanged += AccountCalendarStateCollectivelyChanged;
} }
private void AccountCalendarStateCollectivelyChanged(object sender, GroupedAccountCalendarViewModel e) private void AccountCalendarStateCollectivelyChanged(object sender, GroupedAccountCalendarViewModel e)
@@ -81,7 +93,7 @@ namespace Wino.Calendar.ViewModels
{ {
var days = dayRangeRenderModels.SelectMany(a => a.CalendarDays); var days = dayRangeRenderModels.SelectMany(a => a.CalendarDays);
days.ForEach(a => a.EventsCollection.FilterByCalendars(_accountCalendarStateService.ActiveCalendars.Select(a => a.Id))); days.ForEach(a => a.EventsCollection.FilterByCalendars(AccountCalendarStateService.ActiveCalendars.Select(a => a.Id)));
} }
// TODO: Replace when calendar settings are updated. // TODO: Replace when calendar settings are updated.
@@ -435,7 +447,7 @@ namespace Wino.Calendar.ViewModels
// Initialization is done for all calendars, regardless whether they are actively selected or not. // Initialization is done for all calendars, regardless whether they are actively selected or not.
// This is because the filtering is cached internally of the calendar items in CalendarEventCollection. // This is because the filtering is cached internally of the calendar items in CalendarEventCollection.
var allCalendars = _accountCalendarStateService.GroupedAccountCalendars.SelectMany(a => a.AccountCalendars); var allCalendars = AccountCalendarStateService.GroupedAccountCalendars.SelectMany(a => a.AccountCalendars);
foreach (var calendarViewModel in allCalendars) foreach (var calendarViewModel in allCalendars)
{ {

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
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
{ {
@@ -23,5 +25,6 @@ namespace Wino.Calendar.ViewModels.Interfaces
/// Enumeration of currently selected calendars. /// Enumeration of currently selected calendars.
/// </summary> /// </summary>
IEnumerable<AccountCalendarViewModel> ActiveCalendars { get; } IEnumerable<AccountCalendarViewModel> ActiveCalendars { get; }
IEnumerable<IGrouping<MailAccount, AccountCalendarViewModel>> GroupedAccountCalendarsEnumerable { get; }
} }
} }

View File

@@ -5,6 +5,7 @@ using System.Linq;
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;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Calendar.Services namespace Wino.Calendar.Services
{ {
@@ -32,6 +33,17 @@ namespace Wino.Calendar.Services
} }
} }
public IEnumerable<IGrouping<MailAccount, AccountCalendarViewModel>> GroupedAccountCalendarsEnumerable
{
get
{
return GroupedAccountCalendars
.Select(a => a.AccountCalendars)
.SelectMany(b => b)
.GroupBy(c => c.Account);
}
}
public AccountCalendarStateService() public AccountCalendarStateService()
{ {
GroupedAccountCalendars = new ReadOnlyObservableCollection<GroupedAccountCalendarViewModel>(_internalGroupedAccountCalendars); GroupedAccountCalendars = new ReadOnlyObservableCollection<GroupedAccountCalendarViewModel>(_internalGroupedAccountCalendars);

View File

@@ -249,8 +249,5 @@
</Setter> </Setter>
</Style> </Style>
<!-- Teaching tip dialog sizing. -->
<x:Double x:Key="TeachingTipMinWidth">1000</x:Double>
<x:Double x:Key="TeachingTipMaxWidth">1000</x:Double>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -5,15 +5,23 @@
xmlns:abstract="using:Wino.Calendar.Views.Abstract" xmlns:abstract="using:Wino.Calendar.Views.Abstract"
xmlns:calendarControls="using:Wino.Calendar.Controls" xmlns:calendarControls="using:Wino.Calendar.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="using:Wino.Helpers"
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"
mc:Ignorable="d"> mc:Ignorable="d">
<!--<Page.Resources> <Page.Resources>
<x:Double x:Key="TeachingTipMinWidth">500</x:Double> <!-- Teaching tip dialog sizing. -->
<x:Double x:Key="TeachingTipMaxWidth">500</x:Double> <x:Double x:Key="TeachingTipMinWidth">900</x:Double>
</Page.Resources>--> <x:Double x:Key="TeachingTipMaxWidth">900</x:Double>
<CollectionViewSource
x:Key="AQ"
IsSourceGrouped="True"
Source="{x:Bind ViewModel.AccountCalendarStateService.GroupedAccountCalendarsEnumerable, Mode=OneWay}" />
</Page.Resources>
<Border <Border
Margin="0,0,7,7" Margin="0,0,7,7"
@@ -40,28 +48,120 @@
<!-- Single teaching tip to display create event dialog. --> <!-- Single teaching tip to display create event dialog. -->
<muxc:TeachingTip <muxc:TeachingTip
x:Name="NewEventTip" x:Name="NewEventTip"
Width="500"
HorizontalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
Closed="CreateEventTipClosed" Closed="CreateEventTipClosed"
IsOpen="False" IsOpen="False"
PreferredPlacement="Right" PreferredPlacement="Right"
Target="{x:Bind TeachingTipPositionerGrid}"> Target="{x:Bind TeachingTipPositionerGrid}">
<muxc:TeachingTip.Content> <muxc:TeachingTip.Content>
<Grid Margin="0,24" RowSpacing="12"> <Grid
Margin="-12"
Padding="6,3,6,6"
RowSpacing="12">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="32" />
<RowDefinition Height="Auto" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TimePicker x:Name="EventTimePicker" ClockIdentifier="24HourClock" /> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="32" />
</Grid.ColumnDefinitions>
<!-- Title background -->
<Grid
Grid.ColumnSpan="2"
Margin="-6,-3,-6,-6"
Background="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(ViewModel.SelectedQuickEventAccountCalendar.BackgroundColorHex), Mode=OneWay, TargetNullValue='LightGray'}" />
<!-- Title and close button area. -->
<Grid VerticalAlignment="Top" ColumnSpacing="6">
<Button
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Background="Transparent">
<Button.Content>
<Grid ColumnSpacing="12">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Foreground="{x:Bind helpers:XamlHelpers.GetReadableTextColor(ViewModel.SelectedQuickEventAccountCalendar.BackgroundColorHex), Mode=OneWay}" Text="{x:Bind ViewModel.SelectedQuickEventAccountCalendar.Account.Name, Mode=OneWay}" />
<TextBlock
Grid.Column="1"
HorizontalAlignment="Right"
FontWeight="SemiBold"
Foreground="{x:Bind helpers:XamlHelpers.GetReadableTextColor(ViewModel.SelectedQuickEventAccountCalendar.BackgroundColorHex), Mode=OneWay}"
Text="{x:Bind ViewModel.SelectedQuickEventAccountCalendarName, Mode=OneWay}"
TextTrimming="CharacterEllipsis" />
<Viewbox Grid.Column="2" Width="12">
<PathIcon
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="F1 M 18.935547 4.560547 L 19.814453 5.439453 L 10 15.253906 L 0.185547 5.439453 L 1.064453 4.560547 L 10 13.496094 Z "
Foreground="{x:Bind helpers:XamlHelpers.GetReadableTextColor(ViewModel.SelectedQuickEventAccountCalendar.BackgroundColorHex), Mode=OneWay}" />
</Viewbox>
</Grid>
</Button.Content>
<Button.Flyout>
<Flyout x:Name="QuickEventAccountSelectorFlyout" Placement="Bottom">
<ListView
MaxHeight="300"
HorizontalAlignment="Stretch"
DisplayMemberPath="Name"
ItemsSource="{Binding Source={StaticResource AQ}}"
SelectedItem="{x:Bind ViewModel.SelectedQuickEventAccountCalendar, Mode=TwoWay}"
SelectionChanged="QuickEventAccountSelectorSelectionChanged">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key.Name}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Flyout>
</Button.Flyout>
</Button>
<!--<ComboBox
HorizontalAlignment="Stretch"
DisplayMemberPath="Account.Name"
ItemsSource="{x:Bind ViewModel.AccountCalendarStateService.GroupedAccountCalendars}"
SelectedItem="{x:Bind ViewModel.SelectedQuickEventAccountCalendarGroup, Mode=TwoWay}" />-->
<!--<ComboBox
Grid.Column="1"
HorizontalAlignment="Stretch"
DisplayMemberPath="Name"
ItemsSource="{x:Bind ViewModel.SelectedQuickEventAccountCalendarGroup.AccountCalendars, Mode=OneWay}"
SelectedItem="{x:Bind ViewModel.SelectedQuickEventAccountCalendar, Mode=TwoWay}" />-->
</Grid>
<!-- Rest of the content -->
<Grid
Grid.Row="1"
Grid.ColumnSpan="2"
Height="200" />
<!--<TimePicker x:Name="EventTimePicker" ClockIdentifier="24HourClock" />-->
<!-- Create events dialog --> <!-- Create events dialog -->
<Button <!--<Button
x:Name="AddEvent" x:Name="AddEvent"
Grid.Row="1" Grid.Row="1"
Click="AddEventClicked" Click="AddEventClicked"
Content="Add Event" /> Content="Add Event" />-->
</Grid> </Grid>
</muxc:TeachingTip.Content> </muxc:TeachingTip.Content>
@@ -72,3 +172,4 @@
</abstract:CalendarPageAbstract> </abstract:CalendarPageAbstract>

View File

@@ -73,7 +73,7 @@ namespace Wino.Calendar.Views
Id = Guid.NewGuid() Id = Guid.NewGuid()
}; };
WeakReferenceMessenger.Default.Send(new CalendarEventAdded(testCalendarItem)); //WeakReferenceMessenger.Default.Send(new CalendarEventAdded(testCalendarItem));
NewEventTip.IsOpen = true; NewEventTip.IsOpen = true;
} }
@@ -94,10 +94,15 @@ namespace Wino.Calendar.Views
{ {
if (selectedDateTime == null) return; if (selectedDateTime == null) return;
var eventEndDate = selectedDateTime.Value.Add(EventTimePicker.Time); // var eventEndDate = selectedDateTime.Value.Add(EventTimePicker.Time);
// Create the event. // Create the event.
// WeakReferenceMessenger.Default.Send(new CalendarEventAdded(new CalendarItem(selectedDateTime.Value, eventEndDate))); // WeakReferenceMessenger.Default.Send(new CalendarEventAdded(new CalendarItem(selectedDateTime.Value, eventEndDate)));
} }
private void QuickEventAccountSelectorSelectionChanged(object sender, SelectionChangedEventArgs e)
{
QuickEventAccountSelectorFlyout.Hide();
}
} }
} }