Event compose implementation.
This commit is contained in:
@@ -35,9 +35,6 @@ public partial class CalendarAccountSettingsPageViewModel : CalendarBaseViewMode
|
||||
[ObservableProperty]
|
||||
public partial bool IsSyncEnabled { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsPrimaryCalendar { get; set; }
|
||||
|
||||
public ObservableCollection<ShowAsOption> ShowAsOptions { get; } = new ObservableCollection<ShowAsOption>();
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -82,7 +79,6 @@ public partial class CalendarAccountSettingsPageViewModel : CalendarBaseViewMode
|
||||
// Initialize properties from AccountCalendar
|
||||
AccountColorHex = AccountCalendar.BackgroundColorHex ?? "#0078D4";
|
||||
IsSyncEnabled = AccountCalendar.IsSynchronizationEnabled;
|
||||
IsPrimaryCalendar = AccountCalendar.IsPrimary;
|
||||
SelectedDefaultShowAsOption = ShowAsOptions.FirstOrDefault(o => o.ShowAs == AccountCalendar.DefaultShowAs) ?? ShowAsOptions[2];
|
||||
}
|
||||
|
||||
@@ -104,15 +100,6 @@ public partial class CalendarAccountSettingsPageViewModel : CalendarBaseViewMode
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnIsPrimaryCalendarChanged(bool value)
|
||||
{
|
||||
if (AccountCalendar != null)
|
||||
{
|
||||
AccountCalendar.IsPrimary = value;
|
||||
SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnSelectedDefaultShowAsOptionChanged(ShowAsOption value)
|
||||
{
|
||||
if (AccountCalendar != null && value != null)
|
||||
|
||||
@@ -9,6 +9,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Serilog;
|
||||
using Wino.Calendar.ViewModels.Data;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Calendar.ViewModels.Interfaces;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Collections;
|
||||
@@ -122,12 +123,14 @@ public partial class CalendarAppShellViewModel : CalendarBaseViewModel,
|
||||
if (mode == NavigationMode.Back)
|
||||
{
|
||||
await InitializeAccountCalendarsAsync();
|
||||
ValidateConfiguredNewEventCalendar();
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateDateNavigationHeaderItems();
|
||||
|
||||
await InitializeAccountCalendarsAsync();
|
||||
ValidateConfiguredNewEventCalendar();
|
||||
|
||||
await ShowWhatIsNewIfNeededAsync();
|
||||
|
||||
@@ -311,25 +314,31 @@ public partial class CalendarAppShellViewModel : CalendarBaseViewModel,
|
||||
[RelayCommand]
|
||||
private async Task NewEventAsync()
|
||||
{
|
||||
var availableGroups = AccountCalendarStateService.GroupedAccountCalendars
|
||||
.Where(group => group.AccountCalendars.Count > 0)
|
||||
.Select(group => new CalendarPickerAccountGroup
|
||||
{
|
||||
Account = group.Account,
|
||||
Calendars = group.AccountCalendars.Select(calendar => calendar.AccountCalendar).ToList()
|
||||
})
|
||||
.ToList();
|
||||
var pickedCalendar = TryResolveConfiguredNewEventCalendar();
|
||||
|
||||
if (availableGroups.Count == 0)
|
||||
if (pickedCalendar == null)
|
||||
{
|
||||
_dialogService.InfoBarMessage(
|
||||
Translator.CalendarEventCompose_NoCalendarsTitle,
|
||||
Translator.CalendarEventCompose_NoCalendarsMessage,
|
||||
InfoBarMessageType.Warning);
|
||||
return;
|
||||
var availableGroups = AccountCalendarStateService.GroupedAccountCalendars
|
||||
.Where(group => group.AccountCalendars.Count > 0)
|
||||
.Select(group => new CalendarPickerAccountGroup
|
||||
{
|
||||
Account = group.Account,
|
||||
Calendars = group.AccountCalendars.Select(calendar => calendar.AccountCalendar).ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (availableGroups.Count == 0)
|
||||
{
|
||||
_dialogService.InfoBarMessage(
|
||||
Translator.CalendarEventCompose_NoCalendarsTitle,
|
||||
Translator.CalendarEventCompose_NoCalendarsMessage,
|
||||
InfoBarMessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
pickedCalendar = await _dialogService.ShowSingleCalendarPickerDialogAsync(availableGroups);
|
||||
}
|
||||
|
||||
var pickedCalendar = await _dialogService.ShowSingleCalendarPickerDialogAsync(availableGroups);
|
||||
if (pickedCalendar == null)
|
||||
return;
|
||||
|
||||
@@ -472,7 +481,43 @@ public partial class CalendarAppShellViewModel : CalendarBaseViewModel,
|
||||
}
|
||||
|
||||
public async void Receive(AccountRemovedMessage message)
|
||||
=> await InitializeAccountCalendarsAsync();
|
||||
{
|
||||
await InitializeAccountCalendarsAsync();
|
||||
ValidateConfiguredNewEventCalendar();
|
||||
}
|
||||
|
||||
private AccountCalendar TryResolveConfiguredNewEventCalendar()
|
||||
{
|
||||
ValidateConfiguredNewEventCalendar();
|
||||
|
||||
if (PreferencesService.NewEventButtonBehavior != NewEventButtonBehavior.AlwaysUseSpecificCalendar
|
||||
|| !PreferencesService.DefaultNewEventCalendarId.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return AccountCalendarStateService.AllCalendars
|
||||
.FirstOrDefault(calendar => calendar.Id == PreferencesService.DefaultNewEventCalendarId.Value)?
|
||||
.AccountCalendar;
|
||||
}
|
||||
|
||||
private void ValidateConfiguredNewEventCalendar()
|
||||
{
|
||||
if (PreferencesService.NewEventButtonBehavior != NewEventButtonBehavior.AlwaysUseSpecificCalendar
|
||||
|| !PreferencesService.DefaultNewEventCalendarId.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var exists = AccountCalendarStateService.AllCalendars
|
||||
.Any(calendar => calendar.Id == PreferencesService.DefaultNewEventCalendarId.Value);
|
||||
|
||||
if (exists)
|
||||
return;
|
||||
|
||||
PreferencesService.NewEventButtonBehavior = NewEventButtonBehavior.AskEachTime;
|
||||
PreferencesService.DefaultNewEventCalendarId = null;
|
||||
}
|
||||
|
||||
private static (DateTime StartDate, DateTime EndDate) GetDefaultComposeDateRange()
|
||||
{
|
||||
|
||||
@@ -6,18 +6,20 @@ using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using EmailValidation;
|
||||
using Wino.Calendar.ViewModels.Data;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Calendar;
|
||||
using Wino.Core.Domain.Models.Navigation;
|
||||
using Wino.Core.Domain.Validation;
|
||||
using Wino.Core.ViewModels;
|
||||
|
||||
namespace Wino.Calendar.ViewModels;
|
||||
@@ -31,10 +33,12 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
private readonly IContactService _contactService;
|
||||
private readonly IPreferencesService _preferencesService;
|
||||
private readonly IUnderlyingThemeService _underlyingThemeService;
|
||||
private readonly CalendarEventComposeResultValidator _composeResultValidator = new();
|
||||
|
||||
public Func<Task<string>> GetHtmlNotesAsync { get; set; }
|
||||
|
||||
public ObservableCollection<AccountCalendarViewModel> AvailableCalendars { get; } = [];
|
||||
public ObservableCollection<GroupedAccountCalendarViewModel> AvailableCalendarGroups { get; } = [];
|
||||
public ObservableCollection<CalendarComposeAttendeeViewModel> Attendees { get; } = [];
|
||||
public ObservableCollection<CalendarComposeAttachmentViewModel> Attachments { get; } = [];
|
||||
public ObservableCollection<ShowAsOption> ShowAsOptions { get; } = [];
|
||||
@@ -97,6 +101,8 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
public CalendarSettings CurrentSettings { get; }
|
||||
public string TimePickerClockIdentifier => CurrentSettings.DayHeaderDisplayType == DayHeaderDisplayType.TwentyFourHour ? "24HourClock" : "12HourClock";
|
||||
public bool HasAttachments => Attachments.Count > 0;
|
||||
public string SelectedCalendarDisplayText => SelectedCalendar?.Name ?? Translator.CalendarEventCompose_SelectCalendar;
|
||||
public string SelectedCalendarAccountText => SelectedCalendar?.Account?.Address ?? string.Empty;
|
||||
|
||||
public CalendarEventComposePageViewModel(IAccountService accountService,
|
||||
ICalendarService calendarService,
|
||||
@@ -169,11 +175,13 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
|
||||
partial void OnSelectedCalendarChanged(AccountCalendarViewModel value)
|
||||
{
|
||||
if (value == null || SelectedShowAsOption != null)
|
||||
if (value == null)
|
||||
return;
|
||||
|
||||
SelectedShowAsOption = ShowAsOptions.FirstOrDefault(option => option.ShowAs == value.DefaultShowAs)
|
||||
?? ShowAsOptions.FirstOrDefault();
|
||||
OnPropertyChanged(nameof(SelectedCalendarDisplayText));
|
||||
OnPropertyChanged(nameof(SelectedCalendarAccountText));
|
||||
}
|
||||
|
||||
partial void OnIsAllDayChanged(bool value)
|
||||
@@ -263,36 +271,24 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
[RelayCommand]
|
||||
private async Task CreateAsync()
|
||||
{
|
||||
if (!await ValidateAsync())
|
||||
return;
|
||||
|
||||
var uniqueAttendees = Attendees
|
||||
.GroupBy(attendee => attendee.Email, StringComparer.OrdinalIgnoreCase)
|
||||
.Select(group => group.First())
|
||||
.ToList();
|
||||
|
||||
var htmlNotes = GetHtmlNotesAsync == null ? string.Empty : await GetHtmlNotesAsync();
|
||||
var effectiveStart = GetEffectiveStartDateTime();
|
||||
var effectiveEnd = GetEffectiveEndDateTime();
|
||||
var createdResult = await BuildResultAsync(uniqueAttendees);
|
||||
|
||||
LastCreatedResult = new CalendarEventComposeResult
|
||||
try
|
||||
{
|
||||
CalendarId = SelectedCalendar!.Id,
|
||||
AccountId = SelectedCalendar.Account.Id,
|
||||
Title = Title.Trim(),
|
||||
Location = Location?.Trim() ?? string.Empty,
|
||||
HtmlNotes = htmlNotes,
|
||||
StartDate = effectiveStart,
|
||||
EndDate = effectiveEnd,
|
||||
IsAllDay = IsAllDay,
|
||||
TimeZoneId = TimeZoneInfo.Local.Id,
|
||||
ShowAs = SelectedShowAsOption?.ShowAs ?? SelectedCalendar.DefaultShowAs,
|
||||
SelectedReminders = BuildSelectedReminders(),
|
||||
Attendees = BuildAttendees(uniqueAttendees),
|
||||
Attachments = Attachments.Select(attachment => attachment.ToDraftModel()).ToList(),
|
||||
Recurrence = BuildRecurrenceRule(),
|
||||
RecurrenceSummary = RecurrenceSummary
|
||||
};
|
||||
_composeResultValidator.Validate(createdResult);
|
||||
}
|
||||
catch (CalendarEventComposeValidationException ex)
|
||||
{
|
||||
ShowValidationMessage(ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
LastCreatedResult = createdResult;
|
||||
|
||||
_navigationService.GoBack();
|
||||
}
|
||||
@@ -307,7 +303,7 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
|
||||
public async Task<CalendarComposeAttendeeViewModel> GetAttendeeAsync(string tokenText)
|
||||
{
|
||||
if (!IsValidEmailAddress(tokenText))
|
||||
if (!EmailValidator.Validate(tokenText))
|
||||
return null;
|
||||
|
||||
var existing = Attendees.Any(attendee => attendee.Email.Equals(tokenText, StringComparison.OrdinalIgnoreCase));
|
||||
@@ -359,26 +355,38 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
private async Task LoadAvailableCalendarsAsync()
|
||||
{
|
||||
var accountCalendars = new List<AccountCalendarViewModel>();
|
||||
var groupedCalendars = new List<GroupedAccountCalendarViewModel>();
|
||||
var accounts = await _accountService.GetAccountsAsync().ConfigureAwait(false);
|
||||
|
||||
foreach (var account in accounts)
|
||||
{
|
||||
var calendars = await _calendarService.GetAccountCalendarsAsync(account.Id).ConfigureAwait(false);
|
||||
var viewModels = calendars
|
||||
.Select(calendar => new AccountCalendarViewModel(account, calendar))
|
||||
.ToList();
|
||||
|
||||
foreach (var calendar in calendars)
|
||||
accountCalendars.AddRange(viewModels);
|
||||
|
||||
if (viewModels.Count > 0)
|
||||
{
|
||||
accountCalendars.Add(new AccountCalendarViewModel(account, calendar));
|
||||
groupedCalendars.Add(new GroupedAccountCalendarViewModel(account, viewModels));
|
||||
}
|
||||
}
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
AvailableCalendars.Clear();
|
||||
AvailableCalendarGroups.Clear();
|
||||
|
||||
foreach (var calendar in accountCalendars.OrderBy(calendar => calendar.Account.Name).ThenBy(calendar => calendar.Name))
|
||||
{
|
||||
AvailableCalendars.Add(calendar);
|
||||
}
|
||||
|
||||
foreach (var group in groupedCalendars.OrderBy(group => group.Account.Name))
|
||||
{
|
||||
AvailableCalendarGroups.Add(group);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -424,68 +432,35 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
AllDayEndDate = new DateTimeOffset((isAllDay ? endDate.Date : startDate.Date.AddDays(1)));
|
||||
}
|
||||
|
||||
private async Task<bool> ValidateAsync()
|
||||
private async Task<CalendarEventComposeResult> BuildResultAsync(List<CalendarComposeAttendeeViewModel> uniqueAttendees)
|
||||
{
|
||||
if (SelectedCalendar == null)
|
||||
{
|
||||
ShowValidationMessage(Translator.CalendarEventCompose_ValidationMissingCalendar);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Title))
|
||||
{
|
||||
ShowValidationMessage(Translator.CalendarEventCompose_ValidationMissingTitle);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsAllDay)
|
||||
{
|
||||
if (AllDayEndDate.Date <= StartDate.Date)
|
||||
{
|
||||
ShowValidationMessage(Translator.CalendarEventCompose_ValidationInvalidAllDayRange);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (GetEffectiveEndDateTime() <= GetEffectiveStartDateTime())
|
||||
{
|
||||
ShowValidationMessage(Translator.CalendarEventCompose_ValidationInvalidTimeRange);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (RecurrenceEndDate.HasValue && RecurrenceEndDate.Value.Date < StartDate.Date)
|
||||
{
|
||||
ShowValidationMessage(Translator.CalendarEventCompose_ValidationInvalidRecurrenceEnd);
|
||||
return false;
|
||||
throw new CalendarEventComposeValidationException(Translator.CalendarEventCompose_ValidationInvalidRecurrenceEnd);
|
||||
}
|
||||
|
||||
var missingAttachments = Attachments
|
||||
.Where(attachment => !File.Exists(attachment.FilePath))
|
||||
.Select(attachment => attachment.FileName)
|
||||
.ToList();
|
||||
var htmlNotes = GetHtmlNotesAsync == null ? string.Empty : await GetHtmlNotesAsync();
|
||||
var effectiveStart = GetEffectiveStartDateTime();
|
||||
var effectiveEnd = GetEffectiveEndDateTime();
|
||||
|
||||
if (missingAttachments.Count > 0)
|
||||
return new CalendarEventComposeResult
|
||||
{
|
||||
ShowValidationMessage(string.Format(Translator.CalendarEventCompose_ValidationMissingAttachment, string.Join(", ", missingAttachments)));
|
||||
return false;
|
||||
}
|
||||
|
||||
var normalizedAttendees = Attendees
|
||||
.Where(attendee => !string.IsNullOrWhiteSpace(attendee.Email))
|
||||
.Select(attendee => attendee.Email.Trim())
|
||||
.ToList();
|
||||
|
||||
if (normalizedAttendees.Any(address => !IsValidEmailAddress(address)))
|
||||
{
|
||||
ShowValidationMessage(Translator.CalendarEventCompose_ValidationInvalidAttendee);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GetHtmlNotesAsync != null)
|
||||
{
|
||||
await GetHtmlNotesAsync();
|
||||
}
|
||||
|
||||
return true;
|
||||
CalendarId = SelectedCalendar?.Id ?? Guid.Empty,
|
||||
AccountId = SelectedCalendar?.Account.Id ?? Guid.Empty,
|
||||
Title = Title.Trim(),
|
||||
Location = Location?.Trim() ?? string.Empty,
|
||||
HtmlNotes = htmlNotes,
|
||||
StartDate = effectiveStart,
|
||||
EndDate = effectiveEnd,
|
||||
IsAllDay = IsAllDay,
|
||||
TimeZoneId = TimeZoneInfo.Local.Id,
|
||||
ShowAs = SelectedShowAsOption?.ShowAs ?? SelectedCalendar?.DefaultShowAs ?? CalendarItemShowAs.Busy,
|
||||
SelectedReminders = BuildSelectedReminders(),
|
||||
Attendees = BuildAttendees(uniqueAttendees),
|
||||
Attachments = Attachments.Select(attachment => attachment.ToDraftModel()).ToList(),
|
||||
Recurrence = BuildRecurrenceRule(),
|
||||
RecurrenceSummary = RecurrenceSummary
|
||||
};
|
||||
}
|
||||
|
||||
private List<Reminder> BuildSelectedReminders()
|
||||
@@ -676,18 +651,6 @@ public partial class CalendarEventComposePageViewModel : CalendarBaseViewModel
|
||||
OnPropertyChanged(nameof(HasAttachments));
|
||||
}
|
||||
|
||||
private static bool IsValidEmailAddress(string address)
|
||||
{
|
||||
try
|
||||
{
|
||||
var parsedAddress = new MailAddress(address);
|
||||
return parsedAddress.Address.Equals(address, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CalendarComposeFrequencyOption : ObservableObject
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Calendar.ViewModels.Data;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Translations;
|
||||
using Wino.Core.ViewModels;
|
||||
using Wino.Messaging.Client.Calendar;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
|
||||
namespace Wino.Calendar.ViewModels;
|
||||
|
||||
@@ -56,12 +53,21 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
[ObservableProperty]
|
||||
public partial int SelectedDefaultSnoozeIndex { get; set; }
|
||||
|
||||
public ObservableCollection<MailAccount> Accounts { get; } = [];
|
||||
public ObservableCollection<CalendarNewEventBehaviorOption> NewEventBehaviorOptions { get; } = [];
|
||||
public ObservableCollection<AccountCalendarViewModel> AvailableNewEventCalendars { get; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
public partial CalendarNewEventBehaviorOption SelectedNewEventBehaviorOption { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial AccountCalendarViewModel SelectedNewEventCalendar { get; set; }
|
||||
|
||||
public bool ShouldShowSpecificNewEventCalendar => SelectedNewEventBehaviorOption?.Behavior == NewEventButtonBehavior.AlwaysUseSpecificCalendar;
|
||||
|
||||
public IPreferencesService PreferencesService { get; }
|
||||
private readonly ICalendarService _calendarService;
|
||||
private readonly IAccountService _accountService;
|
||||
|
||||
public ObservableCollection<MailAccount> Accounts { get; } = new ObservableCollection<MailAccount>();
|
||||
|
||||
private readonly bool _isLoaded = false;
|
||||
|
||||
public CalendarSettingsPageViewModel(IPreferencesService preferencesService, ICalendarService calendarService, IAccountService accountService)
|
||||
@@ -71,10 +77,8 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
_accountService = accountService;
|
||||
|
||||
var currentLanguageLanguageCode = WinoTranslationDictionary.GetLanguageFileNameRelativePath(preferencesService.CurrentLanguage);
|
||||
|
||||
var cultureInfo = new CultureInfo(currentLanguageLanguageCode);
|
||||
|
||||
// Populate the day names list
|
||||
for (var i = 0; i < 7; i++)
|
||||
{
|
||||
DayNames.Add(cultureInfo.DateTimeFormat.DayNames[i]);
|
||||
@@ -89,7 +93,6 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
WorkingDayStartIndex = DayNames.IndexOf(cultureInfo.DateTimeFormat.GetDayName(preferencesService.WorkingDayStart));
|
||||
WorkingDayEndIndex = DayNames.IndexOf(cultureInfo.DateTimeFormat.GetDayName(preferencesService.WorkingDayEnd));
|
||||
|
||||
// Initialize reminder options
|
||||
var predefinedMinutes = _calendarService.GetPredefinedReminderMinutes();
|
||||
ReminderOptions.Add("None");
|
||||
foreach (var minutes in predefinedMinutes)
|
||||
@@ -102,10 +105,9 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
ReminderOptions.Add(displayText);
|
||||
}
|
||||
|
||||
// Set selected index based on current default reminder setting
|
||||
if (preferencesService.DefaultReminderDurationInSeconds == 0)
|
||||
{
|
||||
SelectedDefaultReminderIndex = 0; // None
|
||||
SelectedDefaultReminderIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -123,35 +125,47 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
var selectedSnoozeIndex = Array.IndexOf(supportedSnoozeMinutes, preferencesService.DefaultSnoozeDurationInMinutes);
|
||||
SelectedDefaultSnoozeIndex = selectedSnoozeIndex >= 0 ? selectedSnoozeIndex : 0;
|
||||
|
||||
NewEventBehaviorOptions.Add(new CalendarNewEventBehaviorOption(NewEventButtonBehavior.AskEachTime, Translator.CalendarSettings_NewEventBehavior_AskEachTime));
|
||||
NewEventBehaviorOptions.Add(new CalendarNewEventBehaviorOption(NewEventButtonBehavior.AlwaysUseSpecificCalendar, Translator.CalendarSettings_NewEventBehavior_AlwaysUseSpecificCalendar));
|
||||
SelectedNewEventBehaviorOption = NewEventBehaviorOptions.FirstOrDefault(option => option.Behavior == preferencesService.NewEventButtonBehavior)
|
||||
?? NewEventBehaviorOptions.First();
|
||||
|
||||
_isLoaded = true;
|
||||
|
||||
// Load accounts with calendar support
|
||||
LoadAccountsAsync();
|
||||
}
|
||||
|
||||
private async void LoadAccountsAsync()
|
||||
{
|
||||
var accounts = await _accountService.GetAccountsAsync();
|
||||
|
||||
var accounts = await _accountService.GetAccountsAsync().ConfigureAwait(false);
|
||||
var calendarsByAccount = new List<(MailAccount Account, List<AccountCalendarViewModel> Calendars)>();
|
||||
|
||||
foreach (var account in accounts)
|
||||
{
|
||||
var calendars = await _calendarService.GetAccountCalendarsAsync(account.Id).ConfigureAwait(false);
|
||||
calendarsByAccount.Add((account, calendars.Select(calendar => new AccountCalendarViewModel(account, calendar)).ToList()));
|
||||
}
|
||||
|
||||
await Dispatcher.ExecuteOnUIThread(() =>
|
||||
{
|
||||
Accounts.Clear();
|
||||
AvailableNewEventCalendars.Clear();
|
||||
|
||||
foreach (var account in accounts)
|
||||
{
|
||||
Accounts.Add(account);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateToAccountSettings(MailAccount account)
|
||||
{
|
||||
if (account == null) return;
|
||||
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(
|
||||
string.Format(Translator.CalendarAccountSettings_Description, account.Name),
|
||||
WinoPage.CalendarAccountSettingsPage,
|
||||
account.Id));
|
||||
foreach (var accountCalendars in calendarsByAccount)
|
||||
{
|
||||
foreach (var calendar in accountCalendars.Calendars)
|
||||
{
|
||||
AvailableNewEventCalendars.Add(calendar);
|
||||
}
|
||||
}
|
||||
|
||||
ApplyStoredNewEventCalendarPreference();
|
||||
});
|
||||
}
|
||||
|
||||
partial void OnCellHourHeightChanged(double oldValue, double newValue) => SaveSettings();
|
||||
@@ -163,10 +177,17 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
partial void OnWorkingDayEndIndexChanged(int value) => SaveSettings();
|
||||
partial void OnSelectedDefaultReminderIndexChanged(int value) => SaveSettings();
|
||||
partial void OnSelectedDefaultSnoozeIndexChanged(int value) => SaveSettings();
|
||||
partial void OnSelectedNewEventBehaviorOptionChanged(CalendarNewEventBehaviorOption value)
|
||||
{
|
||||
OnPropertyChanged(nameof(ShouldShowSpecificNewEventCalendar));
|
||||
SaveSettings();
|
||||
}
|
||||
partial void OnSelectedNewEventCalendarChanged(AccountCalendarViewModel value) => SaveSettings();
|
||||
|
||||
public void SaveSettings()
|
||||
{
|
||||
if (!_isLoaded) return;
|
||||
if (!_isLoaded)
|
||||
return;
|
||||
|
||||
PreferencesService.FirstDayOfWeek = SelectedFirstDayOfWeekIndex switch
|
||||
{
|
||||
@@ -209,10 +230,9 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
PreferencesService.WorkingHourEnd = WorkingHourEnd;
|
||||
PreferencesService.HourHeight = CellHourHeight;
|
||||
|
||||
// Save default reminder setting
|
||||
if (SelectedDefaultReminderIndex == 0)
|
||||
{
|
||||
PreferencesService.DefaultReminderDurationInSeconds = 0; // None
|
||||
PreferencesService.DefaultReminderDurationInSeconds = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -228,6 +248,47 @@ public partial class CalendarSettingsPageViewModel : CalendarBaseViewModel
|
||||
PreferencesService.DefaultSnoozeDurationInMinutes = supportedSnoozeMinutes[selectedIndex];
|
||||
}
|
||||
|
||||
Messenger.Send(new CalendarSettingsUpdatedMessage());
|
||||
var newEventBehavior = SelectedNewEventBehaviorOption?.Behavior ?? NewEventButtonBehavior.AskEachTime;
|
||||
if (newEventBehavior == NewEventButtonBehavior.AlwaysUseSpecificCalendar && SelectedNewEventCalendar != null)
|
||||
{
|
||||
PreferencesService.NewEventButtonBehavior = NewEventButtonBehavior.AlwaysUseSpecificCalendar;
|
||||
PreferencesService.DefaultNewEventCalendarId = SelectedNewEventCalendar.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
PreferencesService.NewEventButtonBehavior = NewEventButtonBehavior.AskEachTime;
|
||||
PreferencesService.DefaultNewEventCalendarId = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyStoredNewEventCalendarPreference()
|
||||
{
|
||||
var configuredCalendarId = PreferencesService.DefaultNewEventCalendarId;
|
||||
var configuredCalendar = configuredCalendarId.HasValue
|
||||
? AvailableNewEventCalendars.FirstOrDefault(calendar => calendar.Id == configuredCalendarId.Value)
|
||||
: null;
|
||||
|
||||
if (PreferencesService.NewEventButtonBehavior == NewEventButtonBehavior.AlwaysUseSpecificCalendar && configuredCalendar == null)
|
||||
{
|
||||
SelectedNewEventBehaviorOption = NewEventBehaviorOptions.First(option => option.Behavior == NewEventButtonBehavior.AskEachTime);
|
||||
SelectedNewEventCalendar = null;
|
||||
return;
|
||||
}
|
||||
|
||||
SelectedNewEventCalendar = configuredCalendar
|
||||
?? AvailableNewEventCalendars.FirstOrDefault(calendar => calendar.IsPrimary)
|
||||
?? AvailableNewEventCalendars.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CalendarNewEventBehaviorOption
|
||||
{
|
||||
public NewEventButtonBehavior Behavior { get; }
|
||||
public string DisplayText { get; }
|
||||
|
||||
public CalendarNewEventBehaviorOption(NewEventButtonBehavior behavior, string displayText)
|
||||
{
|
||||
Behavior = behavior;
|
||||
DisplayText = displayText;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TimePeriodLibrary.NET" />
|
||||
<PackageReference Include="TimePeriodLibrary.NET" />
|
||||
<PackageReference Include="EmailValidation" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Wino.Core.Domain.Enums;
|
||||
|
||||
public enum NewEventButtonBehavior
|
||||
{
|
||||
AskEachTime = 0,
|
||||
AlwaysUseSpecificCalendar = 1
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Wino.Core.Domain.Exceptions;
|
||||
|
||||
public sealed class CalendarEventComposeValidationException : Exception
|
||||
{
|
||||
public CalendarEventComposeValidationException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public interface ICalendarService
|
||||
Task DeleteAccountCalendarAsync(AccountCalendar accountCalendar);
|
||||
Task InsertAccountCalendarAsync(AccountCalendar accountCalendar);
|
||||
Task UpdateAccountCalendarAsync(AccountCalendar accountCalendar);
|
||||
Task SetPrimaryCalendarAsync(Guid accountId, Guid accountCalendarId);
|
||||
Task CreateNewCalendarItemAsync(CalendarItem calendarItem, List<CalendarEventAttendee> attendees);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -227,6 +227,16 @@ public interface IPreferencesService : INotifyPropertyChanged
|
||||
/// </summary>
|
||||
int DefaultSnoozeDurationInMinutes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Setting: How the New Event button chooses a calendar.
|
||||
/// </summary>
|
||||
NewEventButtonBehavior NewEventButtonBehavior { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Setting: Default calendar used when New Event is configured to always use a specific calendar.
|
||||
/// </summary>
|
||||
Guid? DefaultNewEventCalendarId { get; set; }
|
||||
|
||||
CalendarSettings GetCurrentCalendarSettings();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1049,6 +1049,10 @@
|
||||
"CalendarAccountSettings_DefaultShowAsDescription": "Default availability status for new events created with this account",
|
||||
"CalendarAccountSettings_PrimaryCalendar": "Primary Calendar",
|
||||
"CalendarAccountSettings_PrimaryCalendarDescription": "Mark this calendar as the primary calendar for the account",
|
||||
"CalendarSettings_NewEventBehavior_Header": "New Event button behavior",
|
||||
"CalendarSettings_NewEventBehavior_Description": "Choose whether the New Event button should ask for a calendar each time or always open a specific calendar.",
|
||||
"CalendarSettings_NewEventBehavior_AskEachTime": "Ask each time.",
|
||||
"CalendarSettings_NewEventBehavior_AlwaysUseSpecificCalendar": "Always use specific calendar.",
|
||||
"WhatIsNew_GetStartedButton": "Get Started",
|
||||
"WhatIsNew_ContinueAnywayButton": "Continue anyway",
|
||||
"WhatIsNew_PreparingForNewVersionButton": "Preparing for new version...",
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain.Models.Calendar;
|
||||
|
||||
namespace Wino.Core.Domain.Validation;
|
||||
|
||||
public sealed class CalendarEventComposeResultValidator
|
||||
{
|
||||
public void Validate(CalendarEventComposeResult result)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(result);
|
||||
|
||||
if (result.CalendarId == Guid.Empty)
|
||||
throw new CalendarEventComposeValidationException(Translator.CalendarEventCompose_ValidationMissingCalendar);
|
||||
|
||||
if (result.AccountId == Guid.Empty)
|
||||
throw new CalendarEventComposeValidationException(Translator.CalendarEventCompose_ValidationMissingCalendar);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(result.Title))
|
||||
throw new CalendarEventComposeValidationException(Translator.CalendarEventCompose_ValidationMissingTitle);
|
||||
|
||||
if (result.EndDate <= result.StartDate)
|
||||
{
|
||||
var message = result.IsAllDay
|
||||
? Translator.CalendarEventCompose_ValidationInvalidAllDayRange
|
||||
: Translator.CalendarEventCompose_ValidationInvalidTimeRange;
|
||||
|
||||
throw new CalendarEventComposeValidationException(message);
|
||||
}
|
||||
|
||||
var missingAttachments = result.Attachments
|
||||
.Where(attachment => string.IsNullOrWhiteSpace(attachment.FilePath) || !File.Exists(attachment.FilePath))
|
||||
.Select(attachment => attachment.FileName)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
|
||||
if (missingAttachments.Count > 0)
|
||||
{
|
||||
throw new CalendarEventComposeValidationException(
|
||||
string.Format(Translator.CalendarEventCompose_ValidationMissingAttachment, string.Join(", ", missingAttachments)));
|
||||
}
|
||||
|
||||
var invalidAttendee = result.Attendees
|
||||
.FirstOrDefault(attendee => string.IsNullOrWhiteSpace(attendee.Email) || !IsValidEmailAddress(attendee.Email.Trim()));
|
||||
|
||||
if (invalidAttendee != null)
|
||||
throw new CalendarEventComposeValidationException(Translator.CalendarEventCompose_ValidationInvalidAttendee);
|
||||
|
||||
var duplicateAttendeeGroups = result.Attendees
|
||||
.Where(attendee => !string.IsNullOrWhiteSpace(attendee.Email))
|
||||
.GroupBy(attendee => attendee.Email.Trim(), StringComparer.OrdinalIgnoreCase)
|
||||
.FirstOrDefault(group => group.Count() > 1);
|
||||
|
||||
if (duplicateAttendeeGroups != null)
|
||||
throw new CalendarEventComposeValidationException(Translator.CalendarEventCompose_ValidationInvalidAttendee);
|
||||
}
|
||||
|
||||
private static bool IsValidEmailAddress(string address)
|
||||
{
|
||||
try
|
||||
{
|
||||
var parsedAddress = new MailAddress(address);
|
||||
return parsedAddress.Address.Equals(address, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
using FluentAssertions;
|
||||
using System.IO;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain.Models.Calendar;
|
||||
using Wino.Core.Domain.Validation;
|
||||
using Xunit;
|
||||
|
||||
namespace Wino.Core.Tests.Services;
|
||||
|
||||
public sealed class CalendarEventComposeResultValidatorTests
|
||||
{
|
||||
private readonly CalendarEventComposeResultValidator _validator = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenResultIsValid_DoesNotThrow()
|
||||
{
|
||||
var tempFilePath = Path.GetTempFileName();
|
||||
|
||||
try
|
||||
{
|
||||
var result = CreateValidResult();
|
||||
result.Attachments.Add(new CalendarEventComposeAttachmentDraft
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
FileName = Path.GetFileName(tempFilePath),
|
||||
FilePath = tempFilePath,
|
||||
FileExtension = ".tmp",
|
||||
Size = 12
|
||||
});
|
||||
|
||||
Action act = () => _validator.Validate(result);
|
||||
|
||||
act.Should().NotThrow();
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(tempFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenEndDateIsBeforeStartDate_ThrowsValidationException()
|
||||
{
|
||||
var result = CreateValidResult();
|
||||
result.EndDate = result.StartDate.AddMinutes(-30);
|
||||
|
||||
Action act = () => _validator.Validate(result);
|
||||
|
||||
act.Should()
|
||||
.Throw<CalendarEventComposeValidationException>()
|
||||
.WithMessage(Translator.CalendarEventCompose_ValidationInvalidTimeRange);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAllDayEndDateMatchesStartDate_ThrowsValidationException()
|
||||
{
|
||||
var result = CreateValidResult();
|
||||
result.IsAllDay = true;
|
||||
result.EndDate = result.StartDate;
|
||||
|
||||
Action act = () => _validator.Validate(result);
|
||||
|
||||
act.Should()
|
||||
.Throw<CalendarEventComposeValidationException>()
|
||||
.WithMessage(Translator.CalendarEventCompose_ValidationInvalidAllDayRange);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAttachmentDoesNotExist_ThrowsValidationException()
|
||||
{
|
||||
var result = CreateValidResult();
|
||||
result.Attachments.Add(new CalendarEventComposeAttachmentDraft
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
FileName = "missing.txt",
|
||||
FilePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}.txt"),
|
||||
FileExtension = ".txt",
|
||||
Size = 42
|
||||
});
|
||||
|
||||
Action act = () => _validator.Validate(result);
|
||||
|
||||
act.Should()
|
||||
.Throw<CalendarEventComposeValidationException>()
|
||||
.WithMessage(string.Format(Translator.CalendarEventCompose_ValidationMissingAttachment, "missing.txt"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAttendeeEmailIsInvalid_ThrowsValidationException()
|
||||
{
|
||||
var result = CreateValidResult();
|
||||
result.Attendees.Add(new CalendarEventAttendee
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CalendarItemId = Guid.Empty,
|
||||
Email = "not-an-email"
|
||||
});
|
||||
|
||||
Action act = () => _validator.Validate(result);
|
||||
|
||||
act.Should()
|
||||
.Throw<CalendarEventComposeValidationException>()
|
||||
.WithMessage(Translator.CalendarEventCompose_ValidationInvalidAttendee);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAttendeeEmailIsDuplicated_ThrowsValidationException()
|
||||
{
|
||||
var result = CreateValidResult();
|
||||
result.Attendees.Add(new CalendarEventAttendee
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CalendarItemId = Guid.Empty,
|
||||
Email = "person@example.com"
|
||||
});
|
||||
result.Attendees.Add(new CalendarEventAttendee
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CalendarItemId = Guid.Empty,
|
||||
Email = "PERSON@example.com"
|
||||
});
|
||||
|
||||
Action act = () => _validator.Validate(result);
|
||||
|
||||
act.Should()
|
||||
.Throw<CalendarEventComposeValidationException>()
|
||||
.WithMessage(Translator.CalendarEventCompose_ValidationInvalidAttendee);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCalendarIdIsMissing_ThrowsValidationException()
|
||||
{
|
||||
var result = CreateValidResult();
|
||||
result.CalendarId = Guid.Empty;
|
||||
|
||||
Action act = () => _validator.Validate(result);
|
||||
|
||||
act.Should()
|
||||
.Throw<CalendarEventComposeValidationException>()
|
||||
.WithMessage(Translator.CalendarEventCompose_ValidationMissingCalendar);
|
||||
}
|
||||
|
||||
private static CalendarEventComposeResult CreateValidResult()
|
||||
{
|
||||
return new CalendarEventComposeResult
|
||||
{
|
||||
CalendarId = Guid.NewGuid(),
|
||||
AccountId = Guid.NewGuid(),
|
||||
Title = "Design review",
|
||||
StartDate = new DateTime(2026, 3, 7, 13, 30, 0),
|
||||
EndDate = new DateTime(2026, 3, 7, 14, 0, 0),
|
||||
TimeZoneId = TimeZoneInfo.Local.Id,
|
||||
SelectedReminders =
|
||||
[
|
||||
new Reminder
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
DurationInSeconds = 900
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
@@ -33,6 +33,11 @@ public partial class AccountDetailsPageViewModel : MailBaseViewModel
|
||||
public MailAccount Account { get; set; }
|
||||
public ObservableCollection<IMailItemFolder> CurrentFolders { get; set; } = [];
|
||||
public ObservableCollection<AccountCalendar> AccountCalendars { get; set; } = [];
|
||||
public ObservableCollection<AccountCalendarSettingsItemViewModel> AccountCalendarSettingsItems { get; } = [];
|
||||
public ObservableCollection<AccountCalendarShowAsOption> ShowAsOptions { get; } = [];
|
||||
|
||||
[ObservableProperty]
|
||||
public partial AccountCalendar SelectedPrimaryCalendar { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial int SelectedTabIndex { get; set; } = 1; // Default to Mail tab
|
||||
@@ -70,6 +75,12 @@ public partial class AccountDetailsPageViewModel : MailBaseViewModel
|
||||
_folderService = folderService;
|
||||
_calendarService = calendarService;
|
||||
_statePersistanceService = statePersistanceService;
|
||||
|
||||
ShowAsOptions.Add(new AccountCalendarShowAsOption(CalendarItemShowAs.Free, Translator.CalendarShowAs_Free));
|
||||
ShowAsOptions.Add(new AccountCalendarShowAsOption(CalendarItemShowAs.Tentative, Translator.CalendarShowAs_Tentative));
|
||||
ShowAsOptions.Add(new AccountCalendarShowAsOption(CalendarItemShowAs.Busy, Translator.CalendarShowAs_Busy));
|
||||
ShowAsOptions.Add(new AccountCalendarShowAsOption(CalendarItemShowAs.OutOfOffice, Translator.CalendarShowAs_OutOfOffice));
|
||||
ShowAsOptions.Add(new AccountCalendarShowAsOption(CalendarItemShowAs.WorkingElsewhere, Translator.CalendarShowAs_WorkingElsewhere));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -164,21 +175,41 @@ public partial class AccountDetailsPageViewModel : MailBaseViewModel
|
||||
private async Task LoadAccountCalendarsAsync()
|
||||
{
|
||||
var calendars = await _calendarService.GetAccountCalendarsAsync(Account.Id);
|
||||
|
||||
AccountCalendars.Clear();
|
||||
foreach (var calendar in calendars)
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
AccountCalendars.Add(calendar);
|
||||
}
|
||||
AccountCalendars.Clear();
|
||||
AccountCalendarSettingsItems.Clear();
|
||||
|
||||
foreach (var calendar in calendars)
|
||||
{
|
||||
AccountCalendars.Add(calendar);
|
||||
AccountCalendarSettingsItems.Add(new AccountCalendarSettingsItemViewModel(calendar, ShowAsOptions));
|
||||
}
|
||||
});
|
||||
|
||||
SelectedPrimaryCalendar = AccountCalendars.FirstOrDefault(calendar => calendar.IsPrimary) ?? AccountCalendars.FirstOrDefault();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CalendarItemClicked(AccountCalendar calendar)
|
||||
{
|
||||
if (calendar == null) return;
|
||||
public AccountCalendarShowAsOption GetShowAsOption(CalendarItemShowAs showAs)
|
||||
=> ShowAsOptions.FirstOrDefault(option => option.ShowAs == showAs) ?? ShowAsOptions.First();
|
||||
|
||||
// Navigate to calendar settings page with breadcrumb
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(calendar.Name, WinoPage.CalendarAccountSettingsPage, calendar));
|
||||
public async Task UpdateCalendarSynchronizationAsync(AccountCalendar calendar, bool isEnabled)
|
||||
{
|
||||
if (calendar == null || calendar.IsSynchronizationEnabled == isEnabled)
|
||||
return;
|
||||
|
||||
calendar.IsSynchronizationEnabled = isEnabled;
|
||||
await _calendarService.UpdateAccountCalendarAsync(calendar);
|
||||
}
|
||||
|
||||
public async Task UpdateCalendarDefaultShowAsAsync(AccountCalendar calendar, AccountCalendarShowAsOption option)
|
||||
{
|
||||
if (calendar == null || option == null || calendar.DefaultShowAs == option.ShowAs)
|
||||
return;
|
||||
|
||||
calendar.DefaultShowAs = option.ShowAs;
|
||||
await _calendarService.UpdateAccountCalendarAsync(calendar);
|
||||
}
|
||||
|
||||
protected override async void OnPropertyChanged(PropertyChangedEventArgs e)
|
||||
@@ -209,6 +240,50 @@ public partial class AccountDetailsPageViewModel : MailBaseViewModel
|
||||
Account.Preferences.IsTaskbarBadgeEnabled = IsTaskbarBadgeEnabled;
|
||||
await _accountService.UpdateAccountAsync(Account);
|
||||
break;
|
||||
case nameof(SelectedPrimaryCalendar) when SelectedPrimaryCalendar != null:
|
||||
foreach (var calendar in AccountCalendars)
|
||||
{
|
||||
calendar.IsPrimary = calendar.Id == SelectedPrimaryCalendar.Id;
|
||||
}
|
||||
|
||||
await _calendarService.SetPrimaryCalendarAsync(Account.Id, SelectedPrimaryCalendar.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AccountCalendarShowAsOption
|
||||
{
|
||||
public CalendarItemShowAs ShowAs { get; }
|
||||
public string DisplayText { get; }
|
||||
|
||||
public AccountCalendarShowAsOption(CalendarItemShowAs showAs, string displayText)
|
||||
{
|
||||
ShowAs = showAs;
|
||||
DisplayText = displayText;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class AccountCalendarSettingsItemViewModel : ObservableObject
|
||||
{
|
||||
public AccountCalendar Calendar { get; }
|
||||
public ObservableCollection<AccountCalendarShowAsOption> ShowAsOptions { get; }
|
||||
|
||||
public string Name => Calendar.Name;
|
||||
public string TimeZone => Calendar.TimeZone;
|
||||
public string BackgroundColorHex => Calendar.BackgroundColorHex;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsSynchronizationEnabled { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial AccountCalendarShowAsOption SelectedShowAsOption { get; set; }
|
||||
|
||||
public AccountCalendarSettingsItemViewModel(AccountCalendar calendar, ObservableCollection<AccountCalendarShowAsOption> showAsOptions)
|
||||
{
|
||||
Calendar = calendar;
|
||||
ShowAsOptions = showAsOptions;
|
||||
IsSynchronizationEnabled = calendar.IsSynchronizationEnabled;
|
||||
SelectedShowAsOption = showAsOptions.FirstOrDefault(option => option.ShowAs == calendar.DefaultShowAs) ?? showAsOptions.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
<ScrollViewer Margin="0,8,0,0">
|
||||
<ItemsControl ItemsSource="{x:Bind AvailableGroups}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DataTemplate x:DataType="calendar:CalendarPickerAccountGroup">
|
||||
<StackPanel Margin="0,0,0,12" Spacing="6">
|
||||
<TextBlock FontWeight="SemiBold">
|
||||
<Run Text="{Binding Account.Name}" />
|
||||
<Run Text="{x:Bind Account.Name}" />
|
||||
<Run Text=" (" />
|
||||
<Run Text="{Binding Account.Address}" />
|
||||
<Run Text="{x:Bind Account.Address}" />
|
||||
<Run Text=")" />
|
||||
</TextBlock>
|
||||
|
||||
@@ -41,10 +41,10 @@
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="CalendarClicked"
|
||||
ItemContainerStyle="{StaticResource CalendarPickerListItemStyle}"
|
||||
ItemsSource="{Binding Calendars}"
|
||||
ItemsSource="{x:Bind Calendars}"
|
||||
SelectionMode="None">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DataTemplate x:DataType="sharedCalendar:AccountCalendar">
|
||||
<Grid ColumnSpacing="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@@ -55,12 +55,12 @@
|
||||
Width="14"
|
||||
Height="14"
|
||||
VerticalAlignment="Center"
|
||||
Fill="{ThemeResource AccentFillColorDefaultBrush}" />
|
||||
Fill="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(BackgroundColorHex), Mode=OneWay}" />
|
||||
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding Name}" />
|
||||
Text="{x:Bind Name}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
|
||||
@@ -157,6 +157,7 @@
|
||||
<coreControls:WinoFontIcon Icon="NewMail" />
|
||||
</muxc:NavigationViewItem.Icon>
|
||||
<TextBlock
|
||||
Margin="0,-2,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="16"
|
||||
Style="{StaticResource FlyoutPickerTitleTextBlockStyle}"
|
||||
|
||||
@@ -290,6 +290,18 @@ public class PreferencesService(IConfigurationService configurationService) : Ob
|
||||
set => SaveProperty(propertyName: nameof(DefaultSnoozeDurationInMinutes), value);
|
||||
}
|
||||
|
||||
public NewEventButtonBehavior NewEventButtonBehavior
|
||||
{
|
||||
get => _configurationService.Get(nameof(NewEventButtonBehavior), NewEventButtonBehavior.AskEachTime);
|
||||
set => SetPropertyAndSave(nameof(NewEventButtonBehavior), value);
|
||||
}
|
||||
|
||||
public Guid? DefaultNewEventCalendarId
|
||||
{
|
||||
get => _configurationService.Get<Guid?>(nameof(DefaultNewEventCalendarId), null);
|
||||
set => SetPropertyAndSave(nameof(DefaultNewEventCalendarId), value);
|
||||
}
|
||||
|
||||
public int EmailSyncIntervalMinutes
|
||||
{
|
||||
get => _configurationService.Get(nameof(EmailSyncIntervalMinutes), 3);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:WebViewEditorControl">
|
||||
<Grid CornerRadius="3">
|
||||
<Grid CornerRadius="{StaticResource ControlCornerRadius}">
|
||||
<Grid Background="White" Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=IsEditorDarkMode, Mode=OneWay, Converter={StaticResource ReverseBooleanToVisibilityConverter}}" />
|
||||
<WebView2 x:Name="WebView" />
|
||||
</Grid>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:interfaces="using:Wino.Core.Domain.Interfaces"
|
||||
xmlns:local="using:Wino.Views"
|
||||
xmlns:mailViewModels="using:Wino.Mail.ViewModels"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||
@@ -50,7 +51,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Checked="SyncFolderToggled"
|
||||
IsChecked="{x:Bind IsSynchronizationEnabled, Mode=OneWay}"
|
||||
Tag="{Binding}"
|
||||
Tag="{x:Bind}"
|
||||
Unchecked="SyncFolderToggled"
|
||||
Visibility="{x:Bind IsMoveTarget}" />
|
||||
|
||||
@@ -61,7 +62,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Checked="UnreadBadgeCheckboxToggled"
|
||||
IsChecked="{x:Bind ShowUnreadCount, Mode=OneWay}"
|
||||
Tag="{Binding}"
|
||||
Tag="{x:Bind}"
|
||||
Unchecked="UnreadBadgeCheckboxToggled"
|
||||
Visibility="{x:Bind IsMoveTarget}" />
|
||||
</Grid>
|
||||
@@ -296,27 +297,72 @@
|
||||
Visibility="Collapsed">
|
||||
<StackPanel MaxWidth="900" Spacing="12">
|
||||
|
||||
<controls:SettingsCard Description="{x:Bind domain:Translator.CalendarAccountSettings_PrimaryCalendarDescription, Mode=OneTime}" Header="{x:Bind domain:Translator.CalendarAccountSettings_PrimaryCalendar, Mode=OneTime}">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<FontIcon Glyph="" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<ComboBox ItemsSource="{x:Bind ViewModel.AccountCalendars, Mode=OneWay}" SelectedItem="{x:Bind ViewModel.SelectedPrimaryCalendar, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="calendar:AccountCalendar">
|
||||
<TextBlock Text="{x:Bind Name}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</controls:SettingsCard>
|
||||
|
||||
<!-- Calendars List -->
|
||||
<ItemsControl ItemsSource="{x:Bind ViewModel.AccountCalendars, Mode=OneWay}">
|
||||
<ItemsControl ItemsSource="{x:Bind ViewModel.AccountCalendarSettingsItems, Mode=OneWay}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="calendar:AccountCalendar">
|
||||
<controls:SettingsCard
|
||||
Margin="0,0,0,4"
|
||||
ActionIcon="{ui:FontIcon Glyph=}"
|
||||
Click="CalendarItemClicked"
|
||||
CommandParameter="{x:Bind}"
|
||||
<DataTemplate x:DataType="mailViewModels:AccountCalendarSettingsItemViewModel">
|
||||
<controls:SettingsExpander
|
||||
Margin="0,0,0,8"
|
||||
Description="{x:Bind TimeZone, Mode=OneWay}"
|
||||
Header="{x:Bind Name, Mode=OneWay}"
|
||||
IsClickEnabled="True">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<FontIcon Glyph="" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<Border
|
||||
Width="32"
|
||||
Height="32"
|
||||
Background="{x:Bind BackgroundColorHex, Mode=OneWay}"
|
||||
CornerRadius="4" />
|
||||
</controls:SettingsCard>
|
||||
IsExpanded="False">
|
||||
<controls:SettingsExpander.HeaderIcon>
|
||||
<SymbolIcon Foreground="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(BackgroundColorHex), Mode=OneWay}" Symbol="Calendar" />
|
||||
</controls:SettingsExpander.HeaderIcon>
|
||||
<controls:SettingsExpander.Items>
|
||||
|
||||
<controls:SettingsCard Description="{x:Bind domain:Translator.CalendarAccountSettings_AccountColorDescription, Mode=OneTime}" Header="{x:Bind domain:Translator.CalendarAccountSettings_AccountColor, Mode=OneTime}">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<FontIcon Glyph="" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<Border
|
||||
Width="32"
|
||||
Height="32"
|
||||
Background="{x:Bind helpers:XamlHelpers.GetSolidColorBrushFromHex(BackgroundColorHex), Mode=OneWay}"
|
||||
CornerRadius="4" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
<controls:SettingsCard Description="{x:Bind domain:Translator.CalendarAccountSettings_SyncEnabledDescription, Mode=OneTime}" Header="{x:Bind domain:Translator.CalendarAccountSettings_SyncEnabled, Mode=OneTime}">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<FontIcon Glyph="" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<ToggleSwitch
|
||||
IsOn="{x:Bind IsSynchronizationEnabled, Mode=OneWay}"
|
||||
Tag="{x:Bind}"
|
||||
Toggled="CalendarSynchronizationToggled" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
<controls:SettingsCard Description="{x:Bind domain:Translator.CalendarAccountSettings_DefaultShowAsDescription, Mode=OneTime}" Header="{x:Bind domain:Translator.CalendarAccountSettings_DefaultShowAs, Mode=OneTime}">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<FontIcon Glyph="" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<ComboBox
|
||||
ItemsSource="{x:Bind ShowAsOptions, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind SelectedShowAsOption, Mode=OneWay}"
|
||||
SelectionChanged="CalendarShowAsSelectionChanged"
|
||||
Tag="{x:Bind}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="mailViewModels:AccountCalendarShowAsOption">
|
||||
<TextBlock Text="{x:Bind DisplayText}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</controls:SettingsCard>
|
||||
</controls:SettingsExpander.Items>
|
||||
</controls:SettingsExpander>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Wino.Core.Domain.Entities.Calendar;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
using Wino.Mail.ViewModels;
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
namespace Wino.Views;
|
||||
@@ -37,11 +37,21 @@ public sealed partial class AccountDetailsPage : AccountDetailsPageAbstract
|
||||
}
|
||||
}
|
||||
|
||||
private void CalendarItemClicked(object sender, RoutedEventArgs e)
|
||||
private async void CalendarSynchronizationToggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is CommunityToolkit.WinUI.Controls.SettingsCard settingsCard && settingsCard.CommandParameter is AccountCalendar calendar)
|
||||
if (sender is ToggleSwitch { Tag: AccountCalendarSettingsItemViewModel calendarItem } toggleSwitch)
|
||||
{
|
||||
ViewModel.CalendarItemClickedCommand?.Execute(calendar);
|
||||
calendarItem.IsSynchronizationEnabled = toggleSwitch.IsOn;
|
||||
await ViewModel.UpdateCalendarSynchronizationAsync(calendarItem.Calendar, toggleSwitch.IsOn);
|
||||
}
|
||||
}
|
||||
|
||||
private async void CalendarShowAsSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ComboBox { Tag: AccountCalendarSettingsItemViewModel calendarItem, SelectedItem: AccountCalendarShowAsOption option })
|
||||
{
|
||||
calendarItem.SelectedShowAsOption = option;
|
||||
await ViewModel.UpdateCalendarDefaultShowAsAsync(calendarItem.Calendar, option);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:abstract="using:Wino.Mail.WinUI.Views.Abstract"
|
||||
xmlns:calendarViewModels="using:Wino.Calendar.ViewModels"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:domain="using:Wino.Core.Domain"
|
||||
@@ -56,16 +57,6 @@
|
||||
<ToggleSwitch IsOn="{x:Bind ViewModel.IsSyncEnabled, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
<!-- Primary Calendar -->
|
||||
<controls:SettingsCard
|
||||
Description="{x:Bind domain:Translator.CalendarAccountSettings_PrimaryCalendarDescription, Mode=OneTime}"
|
||||
Header="{x:Bind domain:Translator.CalendarAccountSettings_PrimaryCalendar, Mode=OneTime}">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<FontIcon Glyph="" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<ToggleSwitch IsOn="{x:Bind ViewModel.IsPrimaryCalendar, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
<!-- Default Show As Status -->
|
||||
<controls:SettingsCard
|
||||
Description="{x:Bind domain:Translator.CalendarAccountSettings_DefaultShowAsDescription, Mode=OneTime}"
|
||||
@@ -75,9 +66,14 @@
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<ComboBox
|
||||
MinWidth="150"
|
||||
DisplayMemberPath="DisplayText"
|
||||
ItemsSource="{x:Bind ViewModel.ShowAsOptions, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind ViewModel.SelectedDefaultShowAsOption, Mode=TwoWay}" />
|
||||
SelectedItem="{x:Bind ViewModel.SelectedDefaultShowAsOption, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="calendarViewModels:ShowAsOption">
|
||||
<TextBlock Text="{x:Bind DisplayText}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</controls:SettingsCard>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
@@ -82,10 +82,10 @@
|
||||
VerticalAlignment="Center"
|
||||
HorizontalContentAlignment="Left"
|
||||
Background="Transparent"
|
||||
DisplayType="{x:Bind ViewModel.StatePersistenceService.CalendarDisplayType, Mode=OneWay}"
|
||||
FontSize="14"
|
||||
FontWeight="Normal"
|
||||
IsHitTestVisible="False"
|
||||
DisplayType="{x:Bind ViewModel.StatePersistenceService.CalendarDisplayType, Mode=OneWay}"
|
||||
ItemsSource="{x:Bind ViewModel.DateNavigationHeaderItems}"
|
||||
SelectedIndex="{x:Bind ViewModel.SelectedDateNavigationHeaderIndex, Mode=OneWay}">
|
||||
<FlipView.ItemTemplate>
|
||||
@@ -156,13 +156,24 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button
|
||||
Margin="14,12,14,0"
|
||||
Margin="10,12,10,0"
|
||||
Padding="4,12"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{x:Bind ViewModel.NewEventCommand}"
|
||||
Style="{StaticResource AccentButtonStyle}">
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="8">
|
||||
HorizontalContentAlignment="Left"
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
Command="{x:Bind ViewModel.NewEventCommand}">
|
||||
<StackPanel
|
||||
HorizontalAlignment="Center"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<coreControls:WinoFontIcon FontSize="16" Icon="NewMail" />
|
||||
<TextBlock Text="{x:Bind domain:Translator.CalendarEventCompose_NewEventButton}" />
|
||||
<TextBlock
|
||||
Margin="10,-2,0,0"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="16"
|
||||
Style="{StaticResource FlyoutPickerTitleTextBlockStyle}"
|
||||
Text="{x:Bind domain:Translator.CalendarEventCompose_NewEventButton}" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
@@ -279,7 +290,10 @@
|
||||
<ListView.Items>
|
||||
<ListViewItem>
|
||||
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="16" Glyph="" />
|
||||
<FontIcon
|
||||
FontFamily="{StaticResource SymbolThemeFontFamily}"
|
||||
FontSize="16"
|
||||
Glyph="" />
|
||||
|
||||
<TextBlock VerticalAlignment="Center" Text="{x:Bind domain:Translator.MenuManageAccounts}" />
|
||||
</StackPanel>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -137,6 +137,14 @@ public sealed partial class CalendarEventComposePage : CalendarEventComposePageA
|
||||
}
|
||||
}
|
||||
|
||||
private void ComposeCalendarClicked(object sender, ItemClickEventArgs e)
|
||||
{
|
||||
if (e.ClickedItem is AccountCalendarViewModel calendar)
|
||||
{
|
||||
ViewModel.SelectedCalendar = calendar;
|
||||
}
|
||||
}
|
||||
|
||||
public void Receive(ApplicationThemeChanged message)
|
||||
{
|
||||
ViewModel.IsDarkWebviewRenderer = message.IsUnderlyingThemeDark;
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:abstract="using:Wino.Mail.WinUI.Views.Abstract"
|
||||
xmlns:calendarViewModels="using:Wino.Calendar.ViewModels"
|
||||
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:controls1="using:Microsoft.UI.Xaml.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:data="using:Wino.Calendar.ViewModels.Data"
|
||||
xmlns:domain="using:Wino.Core.Domain"
|
||||
xmlns:entities="using:Wino.Core.Domain.Entities.Shared"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -236,9 +238,7 @@
|
||||
</controls:SettingsCard.Content>
|
||||
</controls:SettingsCard>
|
||||
|
||||
<controls:SettingsCard
|
||||
Description="{x:Bind domain:Translator.CalendarSettings_DefaultSnoozeDuration_Description}"
|
||||
Header="{x:Bind domain:Translator.CalendarSettings_DefaultSnoozeDuration_Header}">
|
||||
<controls:SettingsCard Description="{x:Bind domain:Translator.CalendarSettings_DefaultSnoozeDuration_Description}" Header="{x:Bind domain:Translator.CalendarSettings_DefaultSnoozeDuration_Header}">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<PathIcon Data="F1 M 10 1.25 C 10.456706 1.25 10.889486 1.337565 11.298339 1.512695 C 11.707192 1.687826 12.072591 1.927409 12.394531 2.231445 C 12.716471 2.535482 12.97656 2.892253 13.173828 3.301758 C 13.371096 3.711263 13.481771 4.146484 13.505859 4.607422 L 13.505859 5 C 13.969401 5.028646 14.386068 5.16276 14.755859 5.402344 C 15.125651 5.641927 15.414713 5.947917 15.623047 6.320312 C 15.83138 6.692709 15.9349 7.096355 15.933594 7.53125 L 15.933594 8.75 L 16.25 8.75 C 16.822917 8.75 17.317057 8.95638 17.732422 9.369141 C 18.147787 9.781901 18.357422 10.273437 18.359375 10.84375 L 18.359375 16.40625 C 18.359375 16.979167 18.153971 17.473308 17.743164 17.888672 C 17.332357 18.304037 16.839844 18.511719 16.265625 18.511719 L 3.734375 18.511719 C 3.164062 18.511719 2.671549 18.304037 2.256836 17.888672 C 1.842122 17.473308 1.634114 16.979167 1.630859 16.40625 L 1.630859 10.84375 C 1.630859 10.273437 1.837565 9.781901 2.250977 9.369141 C 2.664388 8.95638 3.156901 8.75 3.728516 8.75 L 4.0625 8.75 L 4.0625 7.53125 C 4.0625 7.09375 4.166341 6.689453 4.374023 6.314453 C 4.581706 5.939453 4.86914 5.632486 5.236328 5.393555 C 5.603516 5.154623 6.019532 5.021485 6.484375 4.994141 L 6.484375 4.607422 C 6.506511 4.148438 6.617838 3.714518 6.818359 3.305664 C 7.01888 2.896811 7.282877 2.539063 7.610352 2.232422 C 7.937826 1.92578 8.308268 1.685222 8.721679 1.510742 C 9.135091 1.336264 9.56575 1.249024 10.013672 1.249024 Z M 10.013672 2.5 C 9.441406 2.5 8.947916 2.706381 8.533203 3.119141 C 8.118489 3.531901 7.911459 4.023437 7.912109 4.59375 L 7.912109 6.25 L 12.089844 6.25 L 12.089844 4.59375 C 12.089844 4.023438 11.882161 3.531902 11.466797 3.119141 C 11.051433 2.706382 10.557292 2.5 9.984375 2.5 Z M 5.3125 7.53125 L 5.3125 8.75 L 14.6875 8.75 L 14.6875 7.53125 C 14.6875 7.303385 14.605144 7.107747 14.440429 6.944336 C 14.275714 6.780925 14.080729 6.69987 13.855469 6.703125 L 6.142578 6.703125 C 5.914713 6.703125 5.71875 6.785482 5.552734 6.950195 C 5.386719 7.114909 5.30339 7.310547 5.300781 7.537109 Z M 16.25 10 L 3.75 10 C 3.540365 10 3.361328 10.071615 3.212891 10.214844 C 3.064453 10.358073 2.989258 10.534505 2.986328 10.744141 L 2.986328 16.40625 C 2.986328 16.618489 3.058595 16.797526 3.203125 16.943359 C 3.347656 17.089193 3.526693 17.161458 3.740234 17.15625 L 16.25 17.15625 C 16.458333 17.15625 16.636067 17.082683 16.783203 16.935547 C 16.930339 16.788411 17.003906 16.609375 17.003906 16.398437 L 17.003906 10.742187 C 17.003906 10.536459 16.932942 10.359049 16.791016 10.209961 C 16.64909 10.060873 16.469401 9.986328 16.257812 9.986328 Z M 10 11.5625 C 10.227865 11.5625 10.423502 11.644856 10.586914 11.809571 C 10.750325 11.974285 10.83138 12.16862 10.830078 12.393555 L 10.830078 13.427734 L 11.855469 13.427734 C 12.080404 13.427734 12.273437 13.509115 12.434571 13.671875 C 12.595704 13.834636 12.675781 14.026693 12.675781 14.248047 C 12.675781 14.46224 12.596354 14.653321 12.4375 14.813477 C 12.278646 14.973633 12.089192 15.053711 11.869141 15.053711 L 10.830078 15.053711 L 10.830078 16.074219 C 10.830078 16.296224 10.748372 16.486981 10.584961 16.646484 C 10.42155 16.805989 10.229818 16.885742 10.005859 16.885742 C 9.781901 16.885742 9.590495 16.806315 9.431641 16.647461 C 9.272786 16.488607 9.193359 16.296875 9.193359 16.072266 L 9.193359 15.053711 L 8.15625 15.053711 C 7.931314 15.053711 7.738934 14.972331 7.579102 14.80957 C 7.419269 14.646809 7.339192 14.454753 7.338867 14.233399 C 7.338867 14.008464 7.419921 13.815755 7.582031 13.655274 C 7.744141 13.494793 7.935872 13.414551 8.157227 13.414551 L 9.193359 13.414551 L 9.193359 12.394531 C 9.193359 12.166667 9.275715 11.971029 9.440429 11.807618 C 9.605144 11.644206 9.799479 11.562825 10.023437 11.5625 Z" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
@@ -246,6 +246,40 @@
|
||||
<ComboBox ItemsSource="{x:Bind ViewModel.SnoozeOptions, Mode=OneWay}" SelectedIndex="{x:Bind ViewModel.SelectedDefaultSnoozeIndex, Mode=TwoWay}" />
|
||||
</controls:SettingsCard.Content>
|
||||
</controls:SettingsCard>
|
||||
|
||||
<controls:SettingsCard Description="{x:Bind domain:Translator.CalendarSettings_NewEventBehavior_Description}" Header="{x:Bind domain:Translator.CalendarSettings_NewEventBehavior_Header}">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<FontIcon Glyph="" />
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<controls:SettingsCard.Content>
|
||||
<StackPanel Spacing="12">
|
||||
<ComboBox ItemsSource="{x:Bind ViewModel.NewEventBehaviorOptions, Mode=OneWay}" SelectedItem="{x:Bind ViewModel.SelectedNewEventBehaviorOption, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="calendarViewModels:CalendarNewEventBehaviorOption">
|
||||
<TextBlock Text="{x:Bind DisplayText}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<ComboBox
|
||||
ItemsSource="{x:Bind ViewModel.AvailableNewEventCalendars, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind ViewModel.SelectedNewEventCalendar, Mode=TwoWay}"
|
||||
Visibility="{x:Bind ViewModel.ShouldShowSpecificNewEventCalendar, Mode=OneWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="data:AccountCalendarViewModel">
|
||||
<StackPanel Orientation="Vertical" Spacing="2">
|
||||
<TextBlock Text="{x:Bind Name}" />
|
||||
<TextBlock
|
||||
FontSize="12"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
Text="{x:Bind Account.Address}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</controls:SettingsCard.Content>
|
||||
</controls:SettingsCard>
|
||||
</StackPanel>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="ClockIdentifierStates">
|
||||
|
||||
@@ -179,9 +179,14 @@
|
||||
<ComboBox
|
||||
Width="150"
|
||||
VerticalAlignment="Center"
|
||||
DisplayMemberPath="DisplayText"
|
||||
ItemsSource="{x:Bind ViewModel.ShowAsOptions}"
|
||||
SelectedItem="{x:Bind ViewModel.SelectedShowAsOption, Mode=TwoWay}" />
|
||||
SelectedItem="{x:Bind ViewModel.SelectedShowAsOption, Mode=TwoWay}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="calendarViewModels:ShowAsOption">
|
||||
<TextBlock Text="{x:Bind DisplayText}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Reminder -->
|
||||
|
||||
@@ -54,11 +54,41 @@ public class CalendarService : BaseDatabaseService, ICalendarService
|
||||
|
||||
public async Task UpdateAccountCalendarAsync(AccountCalendar accountCalendar)
|
||||
{
|
||||
if (accountCalendar.IsPrimary)
|
||||
{
|
||||
await Connection.ExecuteAsync(
|
||||
"UPDATE AccountCalendar SET IsPrimary = 0 WHERE AccountId = ? AND Id != ?",
|
||||
accountCalendar.AccountId,
|
||||
accountCalendar.Id);
|
||||
}
|
||||
|
||||
await Connection.UpdateAsync(accountCalendar, typeof(AccountCalendar));
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new CalendarListUpdated(accountCalendar));
|
||||
}
|
||||
|
||||
public async Task SetPrimaryCalendarAsync(Guid accountId, Guid accountCalendarId)
|
||||
{
|
||||
await Connection.RunInTransactionAsync(connection =>
|
||||
{
|
||||
connection.Execute(
|
||||
"UPDATE AccountCalendar SET IsPrimary = 0 WHERE AccountId = ?",
|
||||
accountId);
|
||||
|
||||
connection.Execute(
|
||||
"UPDATE AccountCalendar SET IsPrimary = 1 WHERE AccountId = ? AND Id = ?",
|
||||
accountId,
|
||||
accountCalendarId);
|
||||
});
|
||||
|
||||
var calendars = await GetAccountCalendarsAsync(accountId).ConfigureAwait(false);
|
||||
|
||||
foreach (var calendar in calendars)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new CalendarListUpdated(calendar));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAccountCalendarAsync(AccountCalendar accountCalendar)
|
||||
{
|
||||
await Connection.ExecuteAsync(
|
||||
|
||||
Reference in New Issue
Block a user