diff --git a/Samples/Samples/ViewModel/CalendarEventAddViewModel.cs b/Samples/Samples/ViewModel/CalendarEventAddViewModel.cs index dd69ccfe5..16e734008 100644 --- a/Samples/Samples/ViewModel/CalendarEventAddViewModel.cs +++ b/Samples/Samples/ViewModel/CalendarEventAddViewModel.cs @@ -278,7 +278,7 @@ public TimeSpan EndTime public bool DisplayTimeInformation => !AllDay && !CanAlterRecurrence; // Recurrence Setup - public bool CanAlterRecurrence => SelectedRecurrenceType != null; + public bool CanAlterRecurrence => SelectedRecurrenceType != null && SelectedRecurrenceType != RecurrenceFrequency.None; public bool IsDaily => SelectedRecurrenceType == RecurrenceFrequency.Daily; @@ -348,6 +348,7 @@ public bool IsMonthDaySpecific public List RecurrenceTypes { get; } = new List() { + RecurrenceFrequency.None, RecurrenceFrequency.Daily, RecurrenceFrequency.Weekly, RecurrenceFrequency.Monthly, diff --git a/Xamarin.Essentials/Calendars/Calendars.android.cs b/Xamarin.Essentials/Calendars/Calendars.android.cs index 856f74ed7..7dff83827 100644 --- a/Xamarin.Essentials/Calendars/Calendars.android.cs +++ b/Xamarin.Essentials/Calendars/Calendars.android.cs @@ -60,7 +60,7 @@ static bool IsCalendarReadOnly(CalendarAccess accessLevel) return false; } } - + static async Task> PlatformGetEventsAsync(string calendarId = null, DateTimeOffset? startDate = null, DateTimeOffset? endDate = null) { await Permissions.RequestAsync(); @@ -84,7 +84,7 @@ static async Task> PlatformGetEventsAsync(string cale var instancesUri = instanceUriBuilder.Build(); var calendarSpecificEvent = string.Empty; - + if (!string.IsNullOrEmpty(calendarId)) { // Android event ids are always integers @@ -383,7 +383,7 @@ static async Task PlatformUpdateCalendarEvent(CalendarEvent eventToUpdate) var thisEvent = await GetEventByIdAsync(eventToUpdate.Id); var eventUri = CalendarContract.Events.ContentUri; - var eventValues = SetupContentValues(eventToUpdate); + var eventValues = SetupContentValues(eventToUpdate, true); if (string.IsNullOrEmpty(eventToUpdate.CalendarId) || thisEvent == null) { @@ -405,7 +405,7 @@ static async Task PlatformUpdateCalendarEvent(CalendarEvent eventToUpdate) throw new ArgumentException("[Android]: Could not update appointment with supplied parameters"); } - static ContentValues SetupContentValues(CalendarEvent newEvent) + static ContentValues SetupContentValues(CalendarEvent newEvent, bool existingEvent = false) { var eventValues = new ContentValues(); eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, newEvent.CalendarId); @@ -418,8 +418,17 @@ static ContentValues SetupContentValues(CalendarEvent newEvent) eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, newEvent.EndDate.HasValue ? newEvent.EndDate.Value.ToUnixTimeMilliseconds().ToString() : newEvent.StartDate.AddDays(1).ToUnixTimeMilliseconds().ToString()); eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, TimeZoneInfo.Local.Id); eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, TimeZoneInfo.Local.Id); - eventValues.Put(CalendarContract.Events.InterfaceConsts.Deleted, 0); - eventValues.Put(CalendarContract.Events.InterfaceConsts.Rrule, newEvent.RecurrancePattern.ConvertRule()); + if (newEvent.RecurrancePattern != null) + { + eventValues.Put(CalendarContract.Events.InterfaceConsts.Rrule, newEvent.RecurrancePattern.ConvertRule()); + } + else if (existingEvent) + { + eventValues.PutNull(CalendarContract.Events.InterfaceConsts.Rrule); + eventValues.PutNull(CalendarContract.Events.InterfaceConsts.Duration); + eventValues.Put(CalendarContract.Events.InterfaceConsts.Deleted, 0); + } + return eventValues; } diff --git a/Xamarin.Essentials/Types/Calendar.shared.cs b/Xamarin.Essentials/Types/Calendar.shared.cs index 471074740..5f2e8ad30 100644 --- a/Xamarin.Essentials/Types/Calendar.shared.cs +++ b/Xamarin.Essentials/Types/Calendar.shared.cs @@ -92,6 +92,7 @@ public class RecurrenceRule public enum RecurrenceFrequency { + None = -1, Daily = 0, Weekly = 1, Monthly = 2,