Improved calendar rendering, standartization of some templates and cleanup of old styles.
This commit is contained in:
@@ -1,36 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
namespace Wino.Core.Domain.Collections
|
||||
{
|
||||
// TODO: Could be read-only collection in the MVVM package.
|
||||
public class CalendarEventCollection : ObservableRangeCollection<ICalendarItem>
|
||||
public class CalendarEventCollection
|
||||
{
|
||||
public ObservableCollection<ICalendarItem> AllDayEvents { get; } = new ObservableCollection<ICalendarItem>();
|
||||
public new void Add(ICalendarItem calendarItem)
|
||||
public event EventHandler<ICalendarItem> CalendarItemAdded;
|
||||
public event EventHandler<ICalendarItem> CalendarItemRemoved;
|
||||
|
||||
public event EventHandler<List<ICalendarItem>> CalendarItemRangeAdded;
|
||||
public event EventHandler<List<ICalendarItem>> CalendarItemRangeRemoved;
|
||||
|
||||
private ObservableRangeCollection<ICalendarItem> _internalRegularEvents = [];
|
||||
private ObservableRangeCollection<ICalendarItem> _internalAllDayEvents = [];
|
||||
|
||||
public ReadOnlyObservableCollection<ICalendarItem> RegularEvents { get; }
|
||||
public ReadOnlyObservableCollection<ICalendarItem> AllDayEvents { get; }
|
||||
|
||||
public CalendarEventCollection()
|
||||
{
|
||||
RegularEvents = new ReadOnlyObservableCollection<ICalendarItem>(_internalRegularEvents);
|
||||
AllDayEvents = new ReadOnlyObservableCollection<ICalendarItem>(_internalAllDayEvents);
|
||||
}
|
||||
|
||||
public void AddCalendarItemRange(IEnumerable<ICalendarItem> calendarItems, bool reportChange = true)
|
||||
{
|
||||
foreach (var calendarItem in calendarItems)
|
||||
{
|
||||
AddCalendarItem(calendarItem, reportChange: false);
|
||||
}
|
||||
|
||||
CalendarItemRangeAdded?.Invoke(this, new List<ICalendarItem>(calendarItems));
|
||||
}
|
||||
|
||||
public void RemoveCalendarItemRange(IEnumerable<ICalendarItem> calendarItems, bool reportChange = true)
|
||||
{
|
||||
foreach (var calendarItem in calendarItems)
|
||||
{
|
||||
RemoveCalendarItem(calendarItem, reportChange);
|
||||
}
|
||||
|
||||
CalendarItemRangeRemoved?.Invoke(this, new List<ICalendarItem>(calendarItems));
|
||||
}
|
||||
|
||||
public void AddCalendarItem(ICalendarItem calendarItem, bool reportChange = true)
|
||||
{
|
||||
if (calendarItem is not ICalendarItemViewModel)
|
||||
throw new ArgumentException("CalendarItem must be of type ICalendarItemViewModel", nameof(calendarItem));
|
||||
|
||||
base.Add(calendarItem);
|
||||
|
||||
if (calendarItem.Period.Duration.TotalMinutes == 1440)
|
||||
{
|
||||
AllDayEvents.Add(calendarItem);
|
||||
_internalAllDayEvents.Add(calendarItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
_internalRegularEvents.Add(calendarItem);
|
||||
}
|
||||
|
||||
if (reportChange)
|
||||
{
|
||||
CalendarItemAdded?.Invoke(this, calendarItem);
|
||||
}
|
||||
}
|
||||
|
||||
public new void Remove(ICalendarItem calendarItem)
|
||||
public void RemoveCalendarItem(ICalendarItem calendarItem, bool reportChange = true)
|
||||
{
|
||||
if (calendarItem is not ICalendarItemViewModel)
|
||||
throw new ArgumentException("CalendarItem must be of type ICalendarItemViewModel", nameof(calendarItem));
|
||||
|
||||
base.Remove(calendarItem);
|
||||
|
||||
if (calendarItem.Period.Duration.TotalMinutes == 1440)
|
||||
{
|
||||
AllDayEvents.Remove(calendarItem);
|
||||
_internalAllDayEvents.Remove(calendarItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
_internalRegularEvents.Remove(calendarItem);
|
||||
}
|
||||
|
||||
if (reportChange)
|
||||
{
|
||||
CalendarItemRemoved?.Invoke(this, calendarItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Itenso.TimePeriod;
|
||||
using Wino.Core.Domain.Enums;
|
||||
@@ -7,13 +8,15 @@ namespace Wino.Core.Domain.Models.Calendar
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a range of days in the calendar.
|
||||
/// Usually it's used for day or week, but supports custom ranges.
|
||||
/// Corresponds to 1 view of the FlipView in CalendarPage.
|
||||
/// </summary>
|
||||
public class DayRangeRenderModel
|
||||
{
|
||||
public event EventHandler<CalendarDayModel> CalendarDayEventCollectionUpdated;
|
||||
|
||||
public ITimePeriod Period { get; }
|
||||
public List<CalendarDayModel> CalendarDays { get; } = new List<CalendarDayModel>();
|
||||
public List<DayHeaderRenderModel> DayHeaders { get; } = new List<DayHeaderRenderModel>();
|
||||
public List<CalendarDayModel> CalendarDays { get; } = [];
|
||||
public List<DayHeaderRenderModel> DayHeaders { get; } = [];
|
||||
public CalendarRenderOptions CalendarRenderOptions { get; }
|
||||
|
||||
public DayRangeRenderModel(CalendarRenderOptions calendarRenderOptions)
|
||||
@@ -46,5 +49,39 @@ namespace Wino.Core.Domain.Models.Calendar
|
||||
DayHeaders.Add(new DayHeaderRenderModel(dayHeader, calendarRenderOptions.CalendarSettings.HourHeight));
|
||||
}
|
||||
}
|
||||
|
||||
//private void RegisterCalendarDayEvents(CalendarDayModel calendarDayModel)
|
||||
//{
|
||||
// calendarDayModel.EventsCollection.CalendarItemAdded += CalendarItemAdded;
|
||||
// calendarDayModel.EventsCollection.CalendarItemRangeRemoved += CalendarItemRangeRemoved;
|
||||
// calendarDayModel.EventsCollection.CalendarItemRemoved += CalendarItemRemoved;
|
||||
// calendarDayModel.EventsCollection.CalendarItemRangeAdded += CalendarItemRangeAdded;
|
||||
//}
|
||||
|
||||
//private void CalendarItemRangeAdded(object sender, List<ICalendarItem> e)
|
||||
// => CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
|
||||
|
||||
//private void CalendarItemRemoved(object sender, ICalendarItem e)
|
||||
// => CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
|
||||
|
||||
//private void CalendarItemAdded(object sender, ICalendarItem e)
|
||||
// => CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
|
||||
|
||||
//private void CalendarItemRangeRemoved(object sender, List<ICalendarItem> e)
|
||||
// => CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
|
||||
|
||||
///// <summary>
|
||||
///// Unregisters all calendar item change listeners to draw the UI for calendar events.
|
||||
///// </summary>
|
||||
//public void UnregisterAll()
|
||||
//{
|
||||
// foreach (var day in CalendarDays)
|
||||
// {
|
||||
// day.EventsCollection.CalendarItemRangeRemoved -= CalendarItemRangeRemoved;
|
||||
// day.EventsCollection.CalendarItemRemoved -= CalendarItemRemoved;
|
||||
// day.EventsCollection.CalendarItemRangeAdded -= CalendarItemRangeAdded;
|
||||
// day.EventsCollection.CalendarItemAdded -= CalendarItemAdded;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user