Listing account calendars on the shell, some visual state updates and reacting to calendar setting changes properly.

This commit is contained in:
Burak Kaan Köse
2024-12-29 17:41:54 +01:00
parent 8d8d7d0f8c
commit eef2ee1baa
16 changed files with 484 additions and 83 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CommunityToolkit.Diagnostics;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Gmail.v1.Data;
using MimeKit;
@@ -9,6 +10,7 @@ using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Calendar;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Enums;
using Wino.Core.Misc;
using Wino.Services;
using Wino.Services.Extensions;
@@ -170,7 +172,7 @@ namespace Wino.Core.Extensions
public static AccountCalendar AsCalendar(this CalendarListEntry calendarListEntry, Guid accountId)
{
return new AccountCalendar()
var calendar = new AccountCalendar()
{
RemoteCalendarId = calendarListEntry.Id,
AccountId = accountId,
@@ -179,6 +181,25 @@ namespace Wino.Core.Extensions
TimeZone = calendarListEntry.TimeZone,
IsPrimary = calendarListEntry.Primary.GetValueOrDefault(),
};
// Optional background color.
if (calendarListEntry.BackgroundColor != null) calendar.BackgroundColorHex = calendarListEntry.BackgroundColor;
if (!string.IsNullOrEmpty(calendarListEntry.ForegroundColor))
{
calendar.TextColorHex = calendarListEntry.ForegroundColor;
}
else
{
// Calendars must have text color assigned.
// Generate one if not provided.
var randomColor = RandomFlatColorGenerator.Generate();
calendar.TextColorHex = randomColor.ToHexString();
}
return calendar;
}
/// <summary>

View File

@@ -0,0 +1,44 @@
using System;
using System.Drawing;
namespace Wino.Core.Misc
{
public static class RandomFlatColorGenerator
{
public static Color Generate()
{
Random random = new();
int hue = random.Next(0, 360); // Full hue range
int saturation = 70 + random.Next(30); // High saturation (70-100%)
int lightness = 50 + random.Next(20); // Bright colors (50-70%)
return FromHsl(hue, saturation, lightness);
}
private static Color FromHsl(int h, int s, int l)
{
double hue = h / 360.0;
double saturation = s / 100.0;
double lightness = l / 100.0;
// Conversion from HSL to RGB
var chroma = (1 - Math.Abs(2 * lightness - 1)) * saturation;
var x = chroma * (1 - Math.Abs((hue * 6) % 2 - 1));
var m = lightness - chroma / 2;
double r = 0, g = 0, b = 0;
if (hue < 1.0 / 6.0) { r = chroma; g = x; b = 0; }
else if (hue < 2.0 / 6.0) { r = x; g = chroma; b = 0; }
else if (hue < 3.0 / 6.0) { r = 0; g = chroma; b = x; }
else if (hue < 4.0 / 6.0) { r = 0; g = x; b = chroma; }
else if (hue < 5.0 / 6.0) { r = x; g = 0; b = chroma; }
else { r = chroma; g = 0; b = x; }
return Color.FromArgb(
(int)((r + m) * 255),
(int)((g + m) * 255),
(int)((b + m) * 255));
}
}
}