From b6edbad74499dfbeffd6c7870035534cd7fcaa71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Tue, 7 Jan 2025 22:12:54 +0100 Subject: [PATCH] Fix multi-day event recurrences for monthly calendar. --- .../CalendarPageViewModel.cs | 37 ++++++++++--------- .../Styles/WinoCalendarResources.xaml | 31 ++++------------ .../Entities/Calendar/CalendarItem.cs | 32 ++++++++++++++++ Wino.Services/CalendarService.cs | 5 +-- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/Wino.Calendar.ViewModels/CalendarPageViewModel.cs b/Wino.Calendar.ViewModels/CalendarPageViewModel.cs index b4bda90e..ea52a609 100644 --- a/Wino.Calendar.ViewModels/CalendarPageViewModel.cs +++ b/Wino.Calendar.ViewModels/CalendarPageViewModel.cs @@ -330,7 +330,25 @@ namespace Wino.Calendar.ViewModels !(message.DisplayDate >= DayRanges.DisplayRange.StartDate && message.DisplayDate <= DayRanges.DisplayRange.EndDate)); } + private void AdjustCalendarOrientation() + { + // Orientation only changes when we should reset. + // Handle the FlipView orientation here. + // We don't want to change the orientation while the item manipulation is going on. + // That causes a glitch in the UI. + bool isRequestedVerticalCalendar = StatePersistanceService.CalendarDisplayType == CalendarDisplayType.Month; + bool isLastRenderedVerticalCalendar = _currentDisplayType == CalendarDisplayType.Month; + + if (isRequestedVerticalCalendar && !isLastRenderedVerticalCalendar) + { + CalendarOrientation = CalendarOrientation.Vertical; + } + else + { + CalendarOrientation = CalendarOrientation.Horizontal; + } + } public async void Receive(LoadCalendarMessage message) { @@ -344,23 +362,6 @@ namespace Wino.Calendar.ViewModels { Debug.WriteLine("Will reset day ranges."); await ClearDayRangeModelsAsync(); - - // Orientation only changes when we should reset. - // Handle the FlipView orientation here. - // We don't want to change the orientation while the item manipulation is going on. - // That causes a glitch in the UI. - - bool isRequestedVerticalCalendar = StatePersistanceService.CalendarDisplayType == CalendarDisplayType.Month; - bool isLastRenderedVerticalCalendar = _currentDisplayType == CalendarDisplayType.Month; - - if (isRequestedVerticalCalendar && !isLastRenderedVerticalCalendar) - { - CalendarOrientation = CalendarOrientation.Vertical; - } - else - { - CalendarOrientation = CalendarOrientation.Horizontal; - } } else if (ShouldScrollToItem(message)) { @@ -370,6 +371,8 @@ namespace Wino.Calendar.ViewModels return; } + AdjustCalendarOrientation(); + // This will replace the whole collection because the user initiated a new render. await RenderDatesAsync(message.CalendarInitInitiative, message.DisplayDate, diff --git a/Wino.Calendar/Styles/WinoCalendarResources.xaml b/Wino.Calendar/Styles/WinoCalendarResources.xaml index ebeb0298..c0469ff1 100644 --- a/Wino.Calendar/Styles/WinoCalendarResources.xaml +++ b/Wino.Calendar/Styles/WinoCalendarResources.xaml @@ -367,9 +367,6 @@ - - - @@ -380,26 +377,14 @@ Margin="0,6" Padding="0,0,16,0"> - - - - - - - - - - - - - - + + + + + diff --git a/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs b/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs index be122bed..6bf32129 100644 --- a/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs +++ b/Wino.Core.Domain/Entities/Calendar/CalendarItem.cs @@ -123,5 +123,37 @@ namespace Wino.Core.Domain.Entities.Calendar [Ignore] public IAccountCalendar AssignedCalendar { get; set; } + + public CalendarItem CreateRecurrence(DateTime startDate, double durationInSeconds) + { + // Create a copy with the new start date and duration + + return new CalendarItem + { + Id = Guid.NewGuid(), + Title = Title, + Description = Description, + Location = Location, + StartDate = startDate, + DurationInSeconds = durationInSeconds, + Recurrence = Recurrence, + OrganizerDisplayName = OrganizerDisplayName, + OrganizerEmail = OrganizerEmail, + RecurringCalendarItemId = Id, + AssignedCalendar = AssignedCalendar, + CalendarId = CalendarId, + CreatedAt = CreatedAt, + UpdatedAt = UpdatedAt, + Visibility = Visibility, + Status = Status, + CustomEventColorHex = CustomEventColorHex, + HtmlLink = HtmlLink, + StartDateOffset = StartDateOffset, + EndDateOffset = EndDateOffset, + RemoteEventId = RemoteEventId, + IsHidden = IsHidden, + IsLocked = IsLocked, + }; + } } } diff --git a/Wino.Services/CalendarService.cs b/Wino.Services/CalendarService.cs index 6b405269..f2e74db6 100644 --- a/Wino.Services/CalendarService.cs +++ b/Wino.Services/CalendarService.cs @@ -158,10 +158,9 @@ namespace Wino.Services // There is no exception for the period. // Change the instance StartDate and Duration. - ev.StartDate = occurrence.Period.StartTime.Value; - ev.DurationInSeconds = (occurrence.Period.EndTime.Value - occurrence.Period.StartTime.Value).TotalSeconds; + var recurrence = ev.CreateRecurrence(occurrence.Period.StartTime.Value, occurrence.Period.Duration.TotalSeconds); - result.Add(ev); + result.Add(recurrence); } else {