Skip to content

Commit

Permalink
Merge pull request #79 from builttoroam/feature/66-remove-not-require…
Browse files Browse the repository at this point in the history
…d-deleted-flag

#66 Remove not needed Deleted flag from create+update event
  • Loading branch information
ScottBTR authored Jan 30, 2020
2 parents db7e9a6 + bee89be commit ca626cd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Samples/Samples/ViewModel/CalendarEventAddViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -348,6 +348,7 @@ public bool IsMonthDaySpecific

public List<RecurrenceFrequency> RecurrenceTypes { get; } = new List<RecurrenceFrequency>()
{
RecurrenceFrequency.None,
RecurrenceFrequency.Daily,
RecurrenceFrequency.Weekly,
RecurrenceFrequency.Monthly,
Expand Down
21 changes: 15 additions & 6 deletions Xamarin.Essentials/Calendars/Calendars.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static bool IsCalendarReadOnly(CalendarAccess accessLevel)
return false;
}
}

static async Task<IEnumerable<CalendarEvent>> PlatformGetEventsAsync(string calendarId = null, DateTimeOffset? startDate = null, DateTimeOffset? endDate = null)
{
await Permissions.RequestAsync<Permissions.CalendarRead>();
Expand All @@ -84,7 +84,7 @@ static async Task<IEnumerable<CalendarEvent>> PlatformGetEventsAsync(string cale

var instancesUri = instanceUriBuilder.Build();
var calendarSpecificEvent = string.Empty;

if (!string.IsNullOrEmpty(calendarId))
{
// Android event ids are always integers
Expand Down Expand Up @@ -383,7 +383,7 @@ static async Task<bool> 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)
{
Expand All @@ -405,7 +405,7 @@ static async Task<bool> 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);
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions Xamarin.Essentials/Types/Calendar.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class RecurrenceRule

public enum RecurrenceFrequency
{
None = -1,
Daily = 0,
Weekly = 1,
Monthly = 2,
Expand Down

0 comments on commit ca626cd

Please sign in to comment.