Ground work for Wino Calendar. (#475)

Wino Calendar abstractions.
This commit is contained in:
Burak Kaan Köse
2024-11-10 23:28:25 +01:00
committed by GitHub
parent a979e8430f
commit d1d6f12f05
486 changed files with 7969 additions and 2708 deletions

View File

@@ -11,7 +11,7 @@ namespace Wino.Core.Domain.Models.Accounts
public string Description { get; }
public string ProviderImage => $"ms-appx:///Assets/Providers/{Type}.png";
public string ProviderImage => $"ms-appx:///Wino.Core.UWP/Assets/Providers/{Type}.png";
public bool IsSupported => Type == MailProviderType.Outlook || Type == MailProviderType.Gmail || Type == MailProviderType.IMAP4;

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Core.Domain.Models.AutoDiscovery
{

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.ObjectModel;
using Itenso.TimePeriod;
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.Domain.Models.Calendar
{
/// <summary>
/// Represents a day in the calendar.
/// Can hold events, appointments, wheather status etc.
/// </summary>
public class CalendarDayModel
{
public TimeRange Period { get; }
public ObservableCollection<ICalendarItem> Events { get; } = new ObservableCollection<ICalendarItem>();
public CalendarDayModel(DateTime representingDate, CalendarRenderOptions calendarRenderOptions)
{
RepresentingDate = representingDate;
Period = new TimeRange(representingDate, representingDate.AddDays(1));
CalendarRenderOptions = calendarRenderOptions;
}
public DateTime RepresentingDate { get; }
public CalendarRenderOptions CalendarRenderOptions { get; }
}
}

View File

@@ -0,0 +1,24 @@
using System;
using Itenso.TimePeriod;
using Wino.Core.Domain.Interfaces;
namespace Wino.Core.Domain.Models.Calendar
{
public class CalendarItem : ICalendarItem
{
public string Name { get; set; }
public CalendarItem(DateTime startTime, DateTime endTime)
{
StartTime = startTime;
EndTime = endTime;
Period = new TimeRange(startTime, endTime);
}
public DateTime StartTime { get; }
public DateTime EndTime { get; }
public Guid Id { get; } = Guid.NewGuid();
public TimeRange Period { get; }
}
}

View File

@@ -0,0 +1,10 @@
namespace Wino.Core.Domain.Models.Calendar
{
public class CalendarPageNavigationArgs
{
/// <summary>
/// When the app launches, automatically request the default calendar navigation options.
/// </summary>
public bool RequestDefaultNavigation { get; set; }
}
}

View File

@@ -0,0 +1,14 @@
namespace Wino.Core.Domain.Models.Calendar
{
public class CalendarRenderOptions
{
public CalendarRenderOptions(DateRange dateRange, CalendarSettings calendarSettings)
{
DateRange = dateRange;
CalendarSettings = calendarSettings;
}
public int TotalDayCount => DateRange.TotalDays;
public DateRange DateRange { get; }
public CalendarSettings CalendarSettings { get; }
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.Calendar
{
public record CalendarSettings(DayOfWeek FirstDayOfWeek,
List<DayOfWeek> WorkingDays,
TimeSpan WorkingHourStart,
TimeSpan WorkingHourEnd,
double HourHeight,
DayHeaderDisplayType DayHeaderDisplayType,
CultureInfo CultureInfo);
}

View File

@@ -0,0 +1,38 @@
using System;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Calendar;
namespace Wino.Calendar.Models.CalendarTypeStrategies
{
public abstract class BaseCalendarTypeDrawingStrategy
{
public CalendarSettings Settings { get; }
public CalendarDisplayType HandlingType { get; }
/// <summary>
/// Day range of the pre-rendered items.
/// </summary>
public abstract DateRange GetRenderDateRange(DateTime DisplayDate, int DayDisplayCount);
/// <summary>
/// Gets the previous date range for rendering.
/// For example, 1 week view with 7 days will return -7 <> 0 days.
/// </summary>
/// <param name="CurrentDateRange">Current displayed date range.</param>
/// <param name="DayDisplayCount">Day display count/</param>
public abstract DateRange GetPreviousDateRange(DateRange CurrentDateRange, int DayDisplayCount);
public abstract DateRange GetNextDateRange(DateRange CurrentDateRange, int DayDisplayCount);
/// <summary>
/// How many items should be placed in 1 FlipViewItem.
/// </summary>
public abstract int GetRenderDayCount(DateTime DisplayDate, int DayDisplayCount);
protected BaseCalendarTypeDrawingStrategy(CalendarSettings settings, CalendarDisplayType handlingType)
{
Settings = settings;
HandlingType = handlingType;
}
}
}

View File

@@ -0,0 +1,36 @@
using System;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Calendar;
namespace Wino.Calendar.Models.CalendarTypeStrategies
{
public class DayCalendarDrawingStrategy : BaseCalendarTypeDrawingStrategy
{
public DayCalendarDrawingStrategy(CalendarSettings settings) : base(settings, CalendarDisplayType.Day)
{
}
public override DateRange GetNextDateRange(DateRange CurrentDateRange, int DayDisplayCount)
{
return new DateRange(CurrentDateRange.EndDate, CurrentDateRange.EndDate.AddDays(DayDisplayCount * 5));
}
public override DateRange GetPreviousDateRange(DateRange CurrentDateRange, int DayDisplayCount)
{
return new DateRange(CurrentDateRange.StartDate.AddDays(-DayDisplayCount * 5), CurrentDateRange.StartDate);
}
public override DateRange GetRenderDateRange(DateTime DisplayDate, int DayDisplayCount)
{
// Add good amount of days to the left and right of the DisplayDate.
var start = DisplayDate.AddDays(-4 * DayDisplayCount);
var end = DisplayDate.AddDays(4 * DayDisplayCount);
return new DateRange(start, end);
}
public override int GetRenderDayCount(DateTime DisplayDate, int DayDisplayCount) => DayDisplayCount;
}
}

View File

@@ -0,0 +1,35 @@
using System;
using Wino.Core.Domain.Models.Calendar;
namespace Wino.Calendar.Models.CalendarTypeStrategies
{
public class WeekCalendarDrawingStrategy : BaseCalendarTypeDrawingStrategy
{
public WeekCalendarDrawingStrategy(CalendarSettings settings) : base(settings, Core.Domain.Enums.CalendarDisplayType.Week) { }
public override DateRange GetNextDateRange(DateRange CurrentDateRange, int DayDisplayCount)
=> new DateRange(CurrentDateRange.EndDate, CurrentDateRange.EndDate.AddDays(7 * 2));
public override DateRange GetPreviousDateRange(DateRange CurrentDateRange, int DayDisplayCount)
=> new DateRange(CurrentDateRange.StartDate.AddDays(-7 * 2), CurrentDateRange.StartDate);
public override DateRange GetRenderDateRange(DateTime DisplayDate, int DayDisplayCount)
{
// Detect the first day of the week that contains the selected date.
DayOfWeek firstDayOfWeek = Settings.FirstDayOfWeek;
int diff = (7 + (DisplayDate.DayOfWeek - Settings.FirstDayOfWeek)) % 7;
// Start loading from this date instead of visible date.
var weekStartDate = DisplayDate.AddDays(-diff).Date;
// Load -+ 14 days
var startDate = weekStartDate.AddDays(-14);
var endDte = weekStartDate.AddDays(14);
return new DateRange(startDate, endDte);
}
public override int GetRenderDayCount(DateTime DisplayDate, int DayDisplayCount) => 7;
}
}

View File

@@ -0,0 +1,10 @@
using System;
namespace Wino.Core.Domain.Models.Calendar
{
/// <summary>
/// Contains the clicked date on the calendar view.
/// </summary>
/// <param name="ClickedDate">Requested date.</param>
public record CalendarViewDayClickedEventArgs(DateTime ClickedDate);
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Linq;
namespace Wino.Core.Domain.Models.Calendar
{
public class DateRange
{
public DateRange(DateTime startDate, DateTime endDate)
{
StartDate = startDate;
EndDate = endDate;
}
public DateTime StartDate { get; }
public DateTime EndDate { get; }
public int TotalDays => (EndDate - StartDate).Days;
public override string ToString() => $"{StartDate.ToString("dd MMMM")} - {EndDate.ToString("dd MMMM")}";
public bool IsInRange(DateTime date)
{
return date >= StartDate && date <= EndDate;
}
/// <summary>
/// Gets the most visible month index in the visible date range.
/// </summary>
public int GetMostVisibleMonthIndex()
{
var dateRange = Enumerable.Range(0, (EndDate - StartDate).Days + 1).Select(offset => StartDate.AddDays(offset));
var groupedByMonth = dateRange.GroupBy(date => date.Month)
.Select(g => new { Month = g.Key, DayCount = g.Count() });
// Find the month with the maximum count of days
var mostVisibleMonth = groupedByMonth.OrderByDescending(g => g.DayCount).FirstOrDefault();
return mostVisibleMonth?.Month ?? -1;
}
}
}

View File

@@ -0,0 +1,14 @@
namespace Wino.Core.Domain.Models.Calendar
{
public class DayHeaderRenderModel
{
public DayHeaderRenderModel(string dayHeader, double hourHeight)
{
DayHeader = dayHeader;
HourHeight = hourHeight;
}
public string DayHeader { get; }
public double HourHeight { get; }
}
}

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Linq;
using Itenso.TimePeriod;
using Wino.Core.Domain.Enums;
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.
/// </summary>
public class DayRangeRenderModel
{
ITimePeriod Period { get; }
public List<CalendarDayModel> CalendarDays { get; } = new List<CalendarDayModel>();
public List<DayHeaderRenderModel> DayHeaders { get; } = new List<DayHeaderRenderModel>();
public CalendarRenderOptions CalendarRenderOptions { get; }
public DayRangeRenderModel(CalendarRenderOptions calendarRenderOptions)
{
CalendarRenderOptions = calendarRenderOptions;
for (var i = 0; i < CalendarRenderOptions.TotalDayCount; i++)
{
var representingDate = calendarRenderOptions.DateRange.StartDate.AddDays(i);
var calendarDayModel = new CalendarDayModel(representingDate, calendarRenderOptions);
CalendarDays.Add(calendarDayModel);
}
Period = new TimeRange(CalendarDays.First().RepresentingDate, CalendarDays.Last().RepresentingDate.AddDays(1));
// Create day headers based on culture info.
for (var i = 0; i < 24; i++)
{
var representingDate = calendarRenderOptions.DateRange.StartDate.Date.AddHours(i);
string dayHeader = calendarRenderOptions.CalendarSettings.DayHeaderDisplayType switch
{
DayHeaderDisplayType.TwelveHour => representingDate.ToString("h tt", calendarRenderOptions.CalendarSettings.CultureInfo),
DayHeaderDisplayType.TwentyFourHour => representingDate.ToString("HH", calendarRenderOptions.CalendarSettings.CultureInfo),
_ => "N/A"
};
DayHeaders.Add(new DayHeaderRenderModel(dayHeader, calendarRenderOptions.CalendarSettings.HourHeight));
}
}
}
}

View File

@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
namespace Wino.Core.Domain.Models.Comparers
{

View File

@@ -1,5 +1,5 @@
using System.IO;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Core.Domain.Models.Connectivity
{

View File

@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.Folders

View File

@@ -1,4 +1,4 @@
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.Folders

View File

@@ -0,0 +1,10 @@
using Wino.Core.Domain.Entities.Mail;
namespace Wino.Core.Domain.Models.Folders
{
public record SystemFolderConfiguration(MailItemFolder SentFolder,
MailItemFolder DraftFolder,
MailItemFolder ArchiveFolder,
MailItemFolder TrashFolder,
MailItemFolder JunkFolder);
}

View File

@@ -1,5 +1,5 @@
using MimeKit;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Launch;

View File

@@ -1,7 +1,8 @@
using System;
using System.Text.Json.Serialization;
using MimeKit;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Extensions;

View File

@@ -1,5 +1,6 @@
using System;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Core.Domain.Models.MailItem
{

View File

@@ -1,5 +1,5 @@
using MimeKit;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
namespace Wino.Core.Domain.Models.MailItem
{

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.Folders;

View File

@@ -1,6 +1,7 @@
using System.Text.Json.Serialization;
using MimeKit;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Extensions;
namespace Wino.Core.Domain.Models.MailItem

View File

@@ -2,7 +2,8 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Core.Domain.Models.MailItem
{

View File

@@ -3,6 +3,7 @@
public enum NavigationTransitionType
{
None, // Supress
DrillIn
DrillIn,
Entrance,
}
}

View File

@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;

View File

@@ -0,0 +1,6 @@
using Wino.Core.Domain.Enums;
namespace Wino.Core.Domain.Models.Settings
{
public record SettingOption(string Title, string Description, WinoPage NavigationPage, string PathIcon);
}