Skip to content

Commit

Permalink
Disable delete calendar (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfversluis authored Sep 19, 2023
1 parent 3ff3c5e commit bca5dc2
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 112 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ Creates a new calendar on the device with the specified name and optionally colo

Updates the calendar, specified by the unique identifier, with the given values.

##### `DeleteCalendar(string calendarId)`
<!--##### `DeleteCalendar(string calendarId)`
Removes a calendar, specified by the unique identifier, from the device.
##### `DeleteCalendar(Calendar calendarToDelete)`
Removes a calendar from the device.
This is basically just a convenience method that calls `DeleteCalendar` with `calendarToDelete.Id`.
This is basically just a convenience method that calls `DeleteCalendar` with `calendarToDelete.Id`.-->

##### `IEnumerable<CalendarEvent> GetEvents(string? calendarId = null, DateTimeOffset? startDate = null, DateTimeOffset? endDate = null)`

Expand Down
5 changes: 3 additions & 2 deletions samples/Plugin.Maui.CalendarStore.Sample/CalendarsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
Clicked="Update_Clicked"
VerticalOptions="Center"/>

<Button Text="Delete"
<!-- TODO -->
<!--<Button Text="Delete"
Clicked="Delete_Clicked"
VerticalOptions="Center"/>
VerticalOptions="Center"/>-->
</VerticalStackLayout>
</Grid>
</DataTemplate>
Expand Down
34 changes: 18 additions & 16 deletions samples/Plugin.Maui.CalendarStore.Sample/CalendarsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,28 @@ await DisplayAlert("Calendar Updated",

async void Delete_Clicked(object sender, EventArgs e)
{
if ((sender as BindableObject)?.
BindingContext is not Calendar calendarToRemove)
{
await DisplayAlert("Error", "Could not determine calendar to delete.", "OK");
return;
}
await DisplayAlert("Oops", "This is still being worked on!", "OK");

var promptResult = await DisplayActionSheet(
$"Are you sure you want to delete calendar \"{calendarToRemove.Name}\"?",
"Cancel", "Remove");
//if ((sender as BindableObject)?.
// BindingContext is not Calendar calendarToRemove)
//{
// await DisplayAlert("Error", "Could not determine calendar to delete.", "OK");
// return;
//}

if (promptResult.Equals("Cancel", StringComparison.OrdinalIgnoreCase))
{
return;
}
//var promptResult = await DisplayActionSheet(
// $"Are you sure you want to delete calendar \"{calendarToRemove.Name}\"?",
// "Cancel", "Remove");

//if (promptResult.Equals("Cancel", StringComparison.OrdinalIgnoreCase))
//{
// return;
//}

await CalendarStore.Default.DeleteCalendar(calendarToRemove.Id);
Calendars.Remove(calendarToRemove);
//await CalendarStore.Default.DeleteCalendar(calendarToRemove.Id);
//Calendars.Remove(calendarToRemove);

await DisplayAlert("Success", "Calendar deleted!", "OK");
//await DisplayAlert("Success", "Calendar deleted!", "OK");
}

async Task LoadCalendars()
Expand Down
56 changes: 28 additions & 28 deletions src/Plugin.Maui.CalendarStore/CalendarStore.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,34 +150,34 @@ public async Task UpdateCalendar(string calendarId, string newName, Color? newCo
}
}

/// <inheritdoc/>
public async Task DeleteCalendar(string calendarId)
{
await EnsureWriteCalendarPermission();

// Android ids are always integers
if (string.IsNullOrEmpty(calendarId) ||
!long.TryParse(calendarId, out long platformCalendarId))
{
throw CalendarStore.InvalidCalendar(calendarId);
}

// We just want to know a calendar with this ID exists
_ = await GetPlatformCalendar(calendarId);

var deleteEventUri = ContentUris.WithAppendedId(calendarsTableUri, platformCalendarId);
var deleteCount = platformContentResolver?.Delete(deleteEventUri, null, null);

if (deleteCount != 1)
{
throw new CalendarStore.CalendarStoreException(
"There was an error deleting the calendar.");
}
}

/// <inheritdoc/>
public Task DeleteCalendar(Calendar calendarToDelete) =>
DeleteCalendar(calendarToDelete.Id);
///// <inheritdoc/>
//public async Task DeleteCalendar(string calendarId)
//{
// await EnsureWriteCalendarPermission();

// // Android ids are always integers
// if (string.IsNullOrEmpty(calendarId) ||
// !long.TryParse(calendarId, out long platformCalendarId))
// {
// throw CalendarStore.InvalidCalendar(calendarId);
// }

// // We just want to know a calendar with this ID exists
// _ = await GetPlatformCalendar(calendarId);

// var deleteEventUri = ContentUris.WithAppendedId(calendarsTableUri, platformCalendarId);
// var deleteCount = platformContentResolver?.Delete(deleteEventUri, null, null);

// if (deleteCount != 1)
// {
// throw new CalendarStore.CalendarStoreException(
// "There was an error deleting the calendar.");
// }
//}

///// <inheritdoc/>
//public Task DeleteCalendar(Calendar calendarToDelete) =>
// DeleteCalendar(calendarToDelete.Id);

/// <inheritdoc/>
public async Task<IEnumerable<CalendarEvent>> GetEvents(
Expand Down
49 changes: 25 additions & 24 deletions src/Plugin.Maui.CalendarStore/CalendarStore.macios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,31 @@ public async Task UpdateCalendar(string calendarId, string newName, Color? newCo
}
}

public async Task DeleteCalendar(string calendarId)
{
await EnsureWriteCalendarPermission();

var calendar = await GetPlatformCalendar(calendarId)
?? throw InvalidCalendar(calendarId);

var removeResult = EventStore.RemoveCalendar(calendar, true, out var error);

if (!removeResult || error is not null)
{
if (error is not null)
{
throw new CalendarStoreException($"Error occurred while deleting calendar: " +
$"{error.LocalizedDescription}");
}

throw new CalendarStoreException("Deleting the calendar was unsuccessful.");
}
}

/// <inheritdoc/>
public Task DeleteCalendar(Calendar calendarToDelete) =>
DeleteCalendar(calendarToDelete.Id);
///// <inheritdoc/>
//public async Task DeleteCalendar(string calendarId)
//{
// await EnsureWriteCalendarPermission();

// var calendar = await GetPlatformCalendar(calendarId)
// ?? throw InvalidCalendar(calendarId);

// var removeResult = EventStore.RemoveCalendar(calendar, true, out var error);

// if (!removeResult || error is not null)
// {
// if (error is not null)
// {
// throw new CalendarStoreException($"Error occurred while deleting calendar: " +
// $"{error.LocalizedDescription}");
// }

// throw new CalendarStoreException("Deleting the calendar was unsuccessful.");
// }
//}

///// <inheritdoc/>
//public Task DeleteCalendar(Calendar calendarToDelete) =>
// DeleteCalendar(calendarToDelete.Id);

/// <inheritdoc/>
public async Task<IEnumerable<CalendarEvent>> GetEvents(string? calendarId = null,
Expand Down
16 changes: 8 additions & 8 deletions src/Plugin.Maui.CalendarStore/CalendarStore.net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public Task CreateCalendar(string name, Color? color = null)
throw new NotImplementedException();
}

public Task DeleteCalendar(string calendarId)
{
throw new NotImplementedException();
}
//public Task DeleteCalendar(string calendarId)
//{
// throw new NotImplementedException();
//}

public Task DeleteCalendar(Calendar calendarToDelete)
{
throw new NotImplementedException();
}
//public Task DeleteCalendar(Calendar calendarToDelete)
//{
// throw new NotImplementedException();
//}

public Task<CalendarEvent> GetEvent(string eventId)
{
Expand Down
10 changes: 7 additions & 3 deletions src/Plugin.Maui.CalendarStore/CalendarStore.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ public static async Task UpdateCalendar(string calendarId, string newName,
Color? newColor = null) =>
await Default.UpdateCalendar(calendarId, newName, newColor);

/// <inheritdoc cref="ICalendarStore.DeleteCalendar(string)"/>
public static async Task DeleteCalendar(string calendarId) =>
await Default.DeleteCalendar(calendarId);
///// <inheritdoc cref="ICalendarStore.DeleteCalendar(string)"/>
//public static async Task DeleteCalendar(string calendarId) =>
// await Default.DeleteCalendar(calendarId);

///// <inheritdoc cref="ICalendarStore.DeleteCalendar(Calendar)"/>
//public static async Task DeleteCalendar(Calendar calendarToDelete) =>
// await Default.DeleteCalendar(calendarToDelete);

/// <inheritdoc cref="ICalendarStore.GetEvents(string?, DateTimeOffset?, DateTimeOffset?)"/>
public static async Task<IEnumerable<CalendarEvent>> GetEvents(string? calendarId = null,
Expand Down
30 changes: 15 additions & 15 deletions src/Plugin.Maui.CalendarStore/CalendarStore.windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ await calendarToUpdate.SaveAsync()
.AsTask().ConfigureAwait(false);
}

/// <inheritdoc/>
public async Task DeleteCalendar(string calendarId)
{
await EnsureWriteCalendarPermission();
///// <inheritdoc/>
//public async Task DeleteCalendar(string calendarId)
//{
// await EnsureWriteCalendarPermission();

var platformCalendarManager = await GetAppointmentStore(true)
.ConfigureAwait(false);
// var platformCalendarManager = await GetAppointmentStore(true)
// .ConfigureAwait(false);

var calendarToDelete =
await platformCalendarManager.GetAppointmentCalendarAsync(calendarId)
.AsTask().ConfigureAwait(false);
// var calendarToDelete =
// await platformCalendarManager.GetAppointmentCalendarAsync(calendarId)
// .AsTask().ConfigureAwait(false);

await calendarToDelete.DeleteAsync()
.AsTask().ConfigureAwait(false);
}
// await calendarToDelete.DeleteAsync()
// .AsTask().ConfigureAwait(false);
//}

/// <inheritdoc/>
public Task DeleteCalendar(Calendar calendarToDelete) =>
DeleteCalendar(calendarToDelete.Id);
///// <inheritdoc/>
//public Task DeleteCalendar(Calendar calendarToDelete) =>
// DeleteCalendar(calendarToDelete.Id);

/// <inheritdoc/>
public async Task<IEnumerable<CalendarEvent>> GetEvents(string? calendarId = null,
Expand Down
28 changes: 14 additions & 14 deletions src/Plugin.Maui.CalendarStore/ICalendarStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public interface ICalendarStore
/// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
Task UpdateCalendar(string calendarId, string newName, Color? newColor = null);

/// <summary>
/// Deletes a calendar, specified by its unique ID, from the device.
/// </summary>
/// <param name="calendarId">The unique identifier of the calendar to be deleted.</param>
/// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
/// <remarks>If the calendar is part of a cloud service, the calendar might also be deleted from all other devices where the calendar is used.</remarks>
Task DeleteCalendar(string calendarId);
///// <summary>
///// Deletes a calendar, specified by its unique ID, from the device.
///// </summary>
///// <param name="calendarId">The unique identifier of the calendar to be deleted.</param>
///// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
///// <remarks>If the calendar is part of a cloud service, the calendar might also be deleted from all other devices where the calendar is used.</remarks>
//Task DeleteCalendar(string calendarId);

/// <summary>
/// Deletes the given calendar from the device.
/// </summary>
/// <param name="calendarToDelete">The calendar object that is to be deleted.</param>
/// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
/// <remarks>If the calendar is part of a cloud service, the calendar might also be deleted from all other devices where the calendar is used.</remarks>
Task DeleteCalendar(Calendar calendarToDelete);
///// <summary>
///// Deletes the given calendar from the device.
///// </summary>
///// <param name="calendarToDelete">The calendar object that is to be deleted.</param>
///// <returns>A <see cref="Task"/> object with the current status of the asynchronous operation.</returns>
///// <remarks>If the calendar is part of a cloud service, the calendar might also be deleted from all other devices where the calendar is used.</remarks>
//Task DeleteCalendar(Calendar calendarToDelete);

/// <summary>
/// Retrieves events from a specific calendar or all calendars from the device.
Expand Down

0 comments on commit bca5dc2

Please sign in to comment.