Add busy state support for calendar item view models (#810)
This commit is contained in:
@@ -902,6 +902,21 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCalendarItemBusyState(Guid calendarItemId, bool isBusy)
|
||||
{
|
||||
var calendarItems = DayRanges
|
||||
.SelectMany(a => a.CalendarDays)
|
||||
.Select(b => b.EventsCollection.GetCalendarItem(calendarItemId))
|
||||
.Where(c => c != null)
|
||||
.OfType<CalendarItemViewModel>()
|
||||
.Distinct();
|
||||
|
||||
foreach (var item in calendarItems)
|
||||
{
|
||||
item.IsBusy = isBusy;
|
||||
}
|
||||
}
|
||||
|
||||
public void Receive(CalendarItemTappedMessage message)
|
||||
{
|
||||
if (message.CalendarItemViewModel == null) return;
|
||||
@@ -970,6 +985,15 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
if (source == CalendarItemUpdateSource.ClientUpdated)
|
||||
{
|
||||
UpdateCalendarItemBusyState(calendarItem.Id, true);
|
||||
}
|
||||
else if (source == CalendarItemUpdateSource.ClientReverted || source == CalendarItemUpdateSource.Server)
|
||||
{
|
||||
UpdateCalendarItemBusyState(calendarItem.Id, false);
|
||||
}
|
||||
|
||||
// Update existing items in-place where the item should remain
|
||||
foreach (var calendarDay in currentDaysWithItem)
|
||||
{
|
||||
@@ -977,6 +1001,15 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
{
|
||||
// Item should stay in this day - update in-place
|
||||
calendarDay.EventsCollection.UpdateCalendarItem(calendarItem);
|
||||
|
||||
if (source == CalendarItemUpdateSource.Server)
|
||||
{
|
||||
var existingViewModel = calendarDay.EventsCollection.GetCalendarItem(calendarItem.Id) as CalendarItemViewModel;
|
||||
if (existingViewModel != null)
|
||||
{
|
||||
existingViewModel.IsBusy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1069,7 +1102,10 @@ public partial class CalendarPageViewModel : CalendarBaseViewModel,
|
||||
|
||||
foreach (var calendarDay in allDaysForEvent)
|
||||
{
|
||||
var calendarItemViewModel = new CalendarItemViewModel(calendarItem);
|
||||
var calendarItemViewModel = new CalendarItemViewModel(calendarItem)
|
||||
{
|
||||
IsBusy = string.IsNullOrEmpty(calendarItem.RemoteEventId)
|
||||
};
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
|
||||
@@ -74,6 +74,9 @@ public partial class CalendarItemViewModel : ObservableObject, ICalendarItem, IC
|
||||
[ObservableProperty]
|
||||
public partial bool IsSelected { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsBusy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The period of the day where this item is currently being displayed.
|
||||
/// Used for multi-day event title formatting.
|
||||
|
||||
@@ -191,7 +191,10 @@ public partial class EventDetailsPageViewModel : CalendarBaseViewModel
|
||||
if (source == CalendarItemUpdateSource.ClientUpdated || source == CalendarItemUpdateSource.ClientReverted)
|
||||
{
|
||||
var previousAttendees = CurrentEvent?.Attendees?.ToList() ?? [];
|
||||
CurrentEvent = new CalendarItemViewModel(calendarItem);
|
||||
CurrentEvent = new CalendarItemViewModel(calendarItem)
|
||||
{
|
||||
IsBusy = source == CalendarItemUpdateSource.ClientUpdated
|
||||
};
|
||||
|
||||
foreach (var attendee in previousAttendees)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@ public interface ICalendarItemViewModel
|
||||
{
|
||||
bool IsSelected { get; set; }
|
||||
|
||||
bool IsBusy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The period of the day where this item is currently being displayed.
|
||||
/// </summary>
|
||||
|
||||
@@ -77,6 +77,18 @@
|
||||
Text="{x:Bind CalendarItem.DisplayTitle, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
|
||||
|
||||
<muxc:ProgressRing
|
||||
x:Name="BusyRing"
|
||||
Width="14"
|
||||
Height="14"
|
||||
Grid.Column="2"
|
||||
Margin="0,2,2,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
IsActive="False"
|
||||
Visibility="Collapsed" />
|
||||
|
||||
<!-- TODO: Event attributes -->
|
||||
<StackPanel
|
||||
x:Name="AttributeStack"
|
||||
@@ -126,6 +138,20 @@
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup x:Name="BusyStates">
|
||||
<VisualState x:Name="NotBusy" />
|
||||
<VisualState x:Name="Busy">
|
||||
<VisualState.StateTriggers>
|
||||
<StateTrigger IsActive="{x:Bind CalendarItem.IsBusy, Mode=OneWay, FallbackValue=False}" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="MainBackground.Opacity" Value="0.55" />
|
||||
<Setter Target="BusyRing.IsActive" Value="True" />
|
||||
<Setter Target="BusyRing.Visibility" Value="Visible" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
||||
<VisualStateGroup x:Name="EventDurationStates">
|
||||
<!-- Regular event template in the panel. -->
|
||||
<VisualState x:Name="RegularEvent" />
|
||||
|
||||
Reference in New Issue
Block a user