Bunch of interaction updates for the calendar item control.

This commit is contained in:
Burak Kaan Köse
2025-01-02 00:18:34 +01:00
parent 215dc6ea6d
commit 8a9265eb79
24 changed files with 333 additions and 102 deletions

View File

@@ -29,6 +29,8 @@ namespace Wino.Calendar.ViewModels
IRecipient<NavigateManageAccountsRequested>,
IRecipient<CalendarDisplayTypeChangedMessage>
{
public IPreferencesService PreferencesService { get; }
public IStatePersistanceService StatePersistenceService { get; }
public IAccountCalendarStateService AccountCalendarStateService { get; }
@@ -65,6 +67,9 @@ namespace Wino.Calendar.ViewModels
[ObservableProperty]
private int _selectedDateNavigationHeaderIndex;
public bool IsVerticalCalendar => StatePersistenceService.CalendarDisplayType == CalendarDisplayType.Month;
// For updating account calendars asynchronously.
@@ -93,6 +98,11 @@ namespace Wino.Calendar.ViewModels
StatePersistenceService.StatePropertyChanged += PrefefencesChanged;
}
private void SelectedCalendarItemsChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
throw new NotImplementedException();
}
private void PrefefencesChanged(object sender, string e)
{
if (e == nameof(StatePersistenceService.CalendarDisplayType))

View File

@@ -12,6 +12,7 @@ using MoreLinq;
using Serilog;
using Wino.Calendar.ViewModels.Data;
using Wino.Calendar.ViewModels.Interfaces;
using Wino.Calendar.ViewModels.Messages;
using Wino.Core.Domain.Collections;
using Wino.Core.Domain.Entities.Calendar;
using Wino.Core.Domain.Enums;
@@ -26,7 +27,10 @@ namespace Wino.Calendar.ViewModels
{
public partial class CalendarPageViewModel : CalendarBaseViewModel,
IRecipient<LoadCalendarMessage>,
IRecipient<CalendarSettingsUpdatedMessage>
IRecipient<CalendarSettingsUpdatedMessage>,
IRecipient<CalendarItemTappedMessage>,
IRecipient<CalendarItemDoubleTappedMessage>,
IRecipient<CalendarItemRightTappedMessage>
{
#region Quick Event Creation
@@ -101,6 +105,7 @@ namespace Wino.Calendar.ViewModels
private const int maxDayRangeSize = 10;
private readonly ICalendarService _calendarService;
private readonly IKeyPressService _keyPressService;
private readonly IPreferencesService _preferencesService;
// Store latest rendered options.
@@ -116,6 +121,7 @@ namespace Wino.Calendar.ViewModels
public CalendarPageViewModel(IStatePersistanceService statePersistanceService,
ICalendarService calendarService,
IKeyPressService keyPressService,
IAccountCalendarStateService accountCalendarStateService,
IPreferencesService preferencesService)
{
@@ -123,6 +129,7 @@ namespace Wino.Calendar.ViewModels
AccountCalendarStateService = accountCalendarStateService;
_calendarService = calendarService;
_keyPressService = keyPressService;
_preferencesService = preferencesService;
AccountCalendarStateService.AccountCalendarSelectionStateChanged += UpdateAccountCalendarRequested;
@@ -179,7 +186,7 @@ namespace Wino.Calendar.ViewModels
var testCalendarItem = new CalendarItem
{
CalendarId = Guid.Parse("40aa0bf0-9ea7-40d8-b426-9c78281723c9"),
CalendarId = SelectedQuickEventAccountCalendar.Id,
StartDate = QuickEventStartTime,
DurationInSeconds = durationSeconds,
CreatedAt = DateTime.UtcNow,
@@ -522,10 +529,6 @@ namespace Wino.Calendar.ViewModels
{
base.OnCalendarItemAdded(calendarItem);
// test
var calendar = await _calendarService.GetAccountCalendarAsync(Guid.Parse("40aa0bf0-9ea7-40d8-b426-9c78281723c9"));
calendarItem.AssignedCalendar = calendar;
// Check if event falls into the current date range.
var loadedDateRange = GetLoadedDateRange();
@@ -733,5 +736,72 @@ namespace Wino.Calendar.ViewModels
// Messenger.Send(new LoadCalendarMessage(DateTime.UtcNow.Date, CalendarInitInitiative.App, true));
}
private IEnumerable<CalendarItemViewModel> GetCalendarItems(Guid calendarItemId)
{
// Multi-day events are sprated in multiple days.
// We need to find the day that the event is in, and then select the event.
return DayRanges
.SelectMany(a => a.CalendarDays)
.Select(b => b.EventsCollection.GetCalendarItem(calendarItemId))
.Where(c => c != null)
.Cast<CalendarItemViewModel>()
.Distinct();
}
private void ResetSelectedItems()
{
foreach (var item in AccountCalendarStateService.SelectedItems)
{
var items = GetCalendarItems(item.Id);
foreach (var childItem in items)
{
childItem.IsSelected = false;
}
}
AccountCalendarStateService.SelectedItems.Clear();
}
public async void Receive(CalendarItemTappedMessage message)
{
if (message.CalendarItemViewModel == null) return;
await ExecuteUIThread(() =>
{
var calendarItems = GetCalendarItems(message.CalendarItemViewModel.Id);
if (!_keyPressService.IsCtrlKeyPressed())
{
ResetSelectedItems();
}
foreach (var item in calendarItems)
{
item.IsSelected = !item.IsSelected;
// Multi-select logic.
if (item.IsSelected && !AccountCalendarStateService.SelectedItems.Contains(item))
{
AccountCalendarStateService.SelectedItems.Add(message.CalendarItemViewModel);
}
else if (!item.IsSelected && AccountCalendarStateService.SelectedItems.Contains(item))
{
AccountCalendarStateService.SelectedItems.Remove(item);
}
}
});
}
public void Receive(CalendarItemDoubleTappedMessage message)
{
// TODO: Navigate to the event details page.
}
public void Receive(CalendarItemRightTappedMessage message)
{
}
}
}

View File

@@ -28,6 +28,11 @@ namespace Wino.Calendar.ViewModels.Data
public bool IsMultiDayEvent => ((ICalendarItem)CalendarItem).IsMultiDayEvent;
public bool IsRecurringEvent => !string.IsNullOrEmpty(CalendarItem.Recurrence);
[ObservableProperty]
private bool _isSelected;
public CalendarItemViewModel(CalendarItem calendarItem)
{
CalendarItem = calendarItem;

View File

@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using Wino.Calendar.ViewModels.Data;
using Wino.Core.Domain.Entities.Shared;
namespace Wino.Calendar.ViewModels.Interfaces
{
public interface IAccountCalendarStateService
public interface IAccountCalendarStateService : INotifyPropertyChanged
{
ReadOnlyObservableCollection<GroupedAccountCalendarViewModel> GroupedAccountCalendars { get; }
@@ -21,6 +22,9 @@ namespace Wino.Calendar.ViewModels.Interfaces
public void AddAccountCalendar(AccountCalendarViewModel accountCalendar);
public void RemoveAccountCalendar(AccountCalendarViewModel accountCalendar);
ObservableCollection<CalendarItemViewModel> SelectedItems { get; }
bool HasMultipleSelectedItems { get; }
/// <summary>
/// Enumeration of currently selected calendars.
/// </summary>

View File

@@ -0,0 +1,14 @@
using Wino.Calendar.ViewModels.Data;
namespace Wino.Calendar.ViewModels.Messages
{
public class CalendarItemDoubleTappedMessage
{
public CalendarItemDoubleTappedMessage(CalendarItemViewModel calendarItemViewModel)
{
CalendarItemViewModel = calendarItemViewModel;
}
public CalendarItemViewModel CalendarItemViewModel { get; }
}
}

View File

@@ -0,0 +1,14 @@
using Wino.Calendar.ViewModels.Data;
namespace Wino.Calendar.ViewModels.Messages
{
public class CalendarItemRightTappedMessage
{
public CalendarItemRightTappedMessage(CalendarItemViewModel calendarItemViewModel)
{
CalendarItemViewModel = calendarItemViewModel;
}
public CalendarItemViewModel CalendarItemViewModel { get; }
}
}

View File

@@ -0,0 +1,14 @@
using Wino.Calendar.ViewModels.Data;
namespace Wino.Calendar.ViewModels.Messages
{
public class CalendarItemTappedMessage
{
public CalendarItemTappedMessage(CalendarItemViewModel calendarItemViewModel)
{
CalendarItemViewModel = calendarItemViewModel;
}
public CalendarItemViewModel CalendarItemViewModel { get; }
}
}