@ebarooni/capacitor-calendar 8.2.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +219 -93
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +42 -7
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +33 -19
  4. package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +88 -21
  5. package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventDeleteInfo.kt +8 -0
  6. package/android/src/main/java/dev/barooni/capacitor/calendar/models/enums/EventSpan.kt +13 -0
  7. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CheckPermissionInput.kt +0 -4
  8. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CreateCalendarInput.kt +3 -1
  9. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteCalendarInput.kt +4 -1
  10. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventInput.kt +4 -1
  11. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventWithPromptInput.kt +4 -1
  12. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventsByIdInput.kt +2 -0
  13. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetDefaultCalendarInput.kt +9 -0
  14. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ModifyCalendarInput.kt +10 -1
  15. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/RequestPermissionInput.kt +3 -5
  16. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/CheckAllPermissionsResult.kt +3 -2
  17. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/RequestAllPermissionsResult.kt +1 -1
  18. package/android/src/main/java/dev/barooni/capacitor/calendar/models/templates/PluginCompletion.kt +8 -0
  19. package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +340 -35
  20. package/dist/docs.json +616 -88
  21. package/dist/esm/index.d.ts +8 -1
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/schemas/enums/calendar-permission-scope.d.ts +8 -0
  24. package/dist/esm/schemas/enums/calendar-permission-scope.js +8 -0
  25. package/dist/esm/schemas/enums/calendar-permission-scope.js.map +1 -1
  26. package/dist/esm/schemas/enums/event-span.d.ts +4 -0
  27. package/dist/esm/schemas/enums/event-span.js +4 -0
  28. package/dist/esm/schemas/enums/event-span.js.map +1 -1
  29. package/dist/esm/schemas/interfaces/calendar-source.d.ts +3 -0
  30. package/dist/esm/schemas/interfaces/calendar-source.js.map +1 -1
  31. package/dist/esm/schemas/interfaces/calendar.d.ts +12 -2
  32. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  33. package/dist/esm/schemas/interfaces/check-permission-options.d.ts +19 -0
  34. package/dist/esm/schemas/interfaces/check-permission-options.js +2 -0
  35. package/dist/esm/schemas/interfaces/check-permission-options.js.map +1 -0
  36. package/dist/esm/schemas/interfaces/create-calendar-options.d.ts +16 -5
  37. package/dist/esm/schemas/interfaces/create-calendar-options.js.map +1 -1
  38. package/dist/esm/schemas/interfaces/create-calendar-result.d.ts +12 -0
  39. package/dist/esm/schemas/interfaces/create-calendar-result.js +2 -0
  40. package/dist/esm/schemas/interfaces/create-calendar-result.js.map +1 -0
  41. package/dist/esm/schemas/interfaces/delete-calendar-options.d.ts +1 -0
  42. package/dist/esm/schemas/interfaces/delete-calendar-options.js.map +1 -1
  43. package/dist/esm/schemas/interfaces/delete-event-options.d.ts +28 -3
  44. package/dist/esm/schemas/interfaces/delete-event-options.js.map +1 -1
  45. package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.d.ts +38 -13
  46. package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.js.map +1 -1
  47. package/dist/esm/schemas/interfaces/delete-events-by-id-options.d.ts +15 -3
  48. package/dist/esm/schemas/interfaces/delete-events-by-id-options.js.map +1 -1
  49. package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.d.ts +13 -0
  50. package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js +2 -0
  51. package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js.map +1 -0
  52. package/dist/esm/schemas/interfaces/get-default-calendar-options.d.ts +13 -0
  53. package/dist/esm/schemas/interfaces/get-default-calendar-options.js +2 -0
  54. package/dist/esm/schemas/interfaces/get-default-calendar-options.js.map +1 -0
  55. package/dist/esm/schemas/interfaces/list-calendars-result.d.ts +13 -0
  56. package/dist/esm/schemas/interfaces/list-calendars-result.js +2 -0
  57. package/dist/esm/schemas/interfaces/list-calendars-result.js.map +1 -0
  58. package/dist/esm/schemas/interfaces/list-events-in-range-options.d.ts +7 -2
  59. package/dist/esm/schemas/interfaces/list-events-in-range-options.js.map +1 -1
  60. package/dist/esm/schemas/interfaces/modify-calendar-options.d.ts +8 -1
  61. package/dist/esm/schemas/interfaces/modify-calendar-options.js.map +1 -1
  62. package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +5 -1
  63. package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
  64. package/dist/esm/schemas/interfaces/request-permission-options.d.ts +16 -0
  65. package/dist/esm/schemas/interfaces/request-permission-options.js +2 -0
  66. package/dist/esm/schemas/interfaces/request-permission-options.js.map +1 -0
  67. package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.d.ts +14 -0
  68. package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js +2 -0
  69. package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js.map +1 -0
  70. package/dist/esm/sub-definitions/calendar-access.d.ts +22 -10
  71. package/dist/esm/sub-definitions/calendar-access.js.map +1 -1
  72. package/dist/esm/sub-definitions/calendar-operations.d.ts +62 -15
  73. package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
  74. package/dist/esm/sub-definitions/event-operations.d.ts +15 -1
  75. package/dist/esm/sub-definitions/event-operations.js.map +1 -1
  76. package/dist/esm/sub-definitions/reminders-access.d.ts +4 -0
  77. package/dist/esm/sub-definitions/reminders-access.js.map +1 -1
  78. package/dist/esm/web.d.ts +15 -21
  79. package/dist/esm/web.js +1 -1
  80. package/dist/esm/web.js.map +1 -1
  81. package/dist/plugin.cjs.js +13 -1
  82. package/dist/plugin.cjs.js.map +1 -1
  83. package/dist/plugin.js +13 -1
  84. package/dist/plugin.js.map +1 -1
  85. package/ios/Plugin/CapacitorCalendarPlugin.swift +19 -16
  86. package/ios/Plugin/Implementation/CapacitorCalendar.swift +67 -37
  87. package/ios/Plugin/Models/Enums/EventSpan.swift +8 -0
  88. package/ios/Plugin/Models/Inputs/CreateCalendarInput.swift +4 -5
  89. package/ios/Plugin/Models/Inputs/DeleteCalendarInput.swift +1 -1
  90. package/ios/Plugin/Models/Inputs/DeleteEventInput.swift +9 -4
  91. package/ios/Plugin/Models/Inputs/DeleteEventWithPromptInput.swift +9 -4
  92. package/ios/Plugin/Models/Inputs/DeleteEventsByIdInput.swift +9 -4
  93. package/ios/Plugin/Models/Inputs/GetDefaultCalendarInput.swift +13 -0
  94. package/ios/Plugin/Models/Inputs/ModifyCalendarInput.swift +4 -1
  95. package/ios/Plugin/PluginError.swift +68 -56
  96. package/ios/Plugin/Utils/ImplementationHelper.swift +22 -14
  97. package/package.json +1 -1
@@ -19,6 +19,7 @@ import dev.barooni.capacitor.calendar.models.inputs.DeleteCalendarInput
19
19
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventInput
20
20
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventWithPromptInput
21
21
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventsByIdInput
22
+ import dev.barooni.capacitor.calendar.models.inputs.GetDefaultCalendarInput
22
23
  import dev.barooni.capacitor.calendar.models.inputs.ListEventsInRangeInput
23
24
  import dev.barooni.capacitor.calendar.models.inputs.ModifyCalendarInput
24
25
  import dev.barooni.capacitor.calendar.models.inputs.ModifyEvent
@@ -30,6 +31,7 @@ import dev.barooni.capacitor.calendar.models.results.CreateEventWithPromptResult
30
31
  import dev.barooni.capacitor.calendar.models.results.ModifyEventWithPromptResult
31
32
  import dev.barooni.capacitor.calendar.models.results.RequestAllPermissionsResult
32
33
  import dev.barooni.capacitor.calendar.models.results.RequestPermissionResult
34
+ import dev.barooni.capacitor.calendar.models.templates.JSResult
33
35
 
34
36
  @CapacitorPlugin(
35
37
  name = "CapacitorCalendar",
@@ -284,13 +286,18 @@ class CapacitorCalendarPlugin : Plugin() {
284
286
  call.unimplemented(PluginError.Unimplemented(::fetchAllCalendarSources.name).message)
285
287
  }
286
288
 
287
- @PluginMethod
289
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
288
290
  fun listCalendars(call: PluginCall) {
289
291
  try {
290
- val result = implementation.listCalendars()
291
- call.resolve(result.toJSON())
292
+ implementation.listCalendars { result, error ->
293
+ if (error != null) {
294
+ rejectCall(call, error)
295
+ return@listCalendars
296
+ }
297
+ resolveCall(call, result)
298
+ }
292
299
  } catch (error: Exception) {
293
- call.reject(error.message)
300
+ rejectCall(call, error)
294
301
  }
295
302
  }
296
303
 
@@ -307,10 +314,16 @@ class CapacitorCalendarPlugin : Plugin() {
307
314
  @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
308
315
  fun getDefaultCalendar(call: PluginCall) {
309
316
  try {
310
- val result = implementation.getDefaultCalendar()
311
- call.resolve(result.toJSON())
317
+ val input = GetDefaultCalendarInput(call)
318
+ implementation.getDefaultCalendar(input) { result, error ->
319
+ if (error != null) {
320
+ rejectCall(call, error)
321
+ return@getDefaultCalendar
322
+ }
323
+ resolveCall(call, result)
324
+ }
312
325
  } catch (error: Exception) {
313
- call.reject(error.message)
326
+ rejectCall(call, error)
314
327
  }
315
328
  }
316
329
 
@@ -455,4 +468,26 @@ class CapacitorCalendarPlugin : Plugin() {
455
468
  fun updateRemindersList(call: PluginCall) {
456
469
  call.unimplemented(PluginError.Unimplemented(::updateRemindersList.name).message)
457
470
  }
471
+
472
+ private fun rejectCall(
473
+ call: PluginCall,
474
+ error: Exception?,
475
+ ) {
476
+ call.reject(error?.message ?: PluginError.CustomError("An unknown error has occurred.").message)
477
+ }
478
+
479
+ private fun resolveCall(call: PluginCall) {
480
+ resolveCall(call, null)
481
+ }
482
+
483
+ private fun resolveCall(
484
+ call: PluginCall,
485
+ result: JSResult?,
486
+ ) {
487
+ if (result != null) {
488
+ call.resolve(result.toJSON())
489
+ } else {
490
+ call.resolve()
491
+ }
492
+ }
458
493
  }
@@ -3,47 +3,61 @@ package dev.barooni.capacitor.calendar
3
3
  sealed class PluginError(
4
4
  localizedDescription: String,
5
5
  ) : Exception(localizedDescription) {
6
- data object MissingScope : PluginError("Scope Must be provided.")
6
+ data object AccountNameMissing : PluginError("Account name must be provided.")
7
7
 
8
- data object InvalidScope : PluginError("Invalid scope.")
8
+ data object AttendeeEmailMissing : PluginError("Attendee email must be provided.")
9
9
 
10
- data object UnhandledPermissionState : PluginError("Unhandled permission state.")
10
+ data object CalendarIdMissing : PluginError("Calendar ID must be provided.")
11
11
 
12
- data object InvalidInvitees : PluginError("Invalid invitees. Array must contain only strings.")
12
+ data object CalendarNotFound : PluginError("Calendar not found.")
13
13
 
14
- data object MissingId : PluginError("Event ID must be provided.")
14
+ data object ColorMissing : PluginError("Color must be provided.")
15
15
 
16
- data object TitleMissing : PluginError("Title must be provided.")
16
+ data class CustomError(
17
+ val details: String,
18
+ ) : PluginError(details)
17
19
 
18
- data object FailedToRetrieveEventId : PluginError("Failed to retrieve event ID.")
20
+ data object FailedToDelete : PluginError("Failed to delete.")
21
+
22
+ data object FailedToModify : PluginError("Failed to modify.")
19
23
 
20
24
  data object FailedToRetrieveCalendarId : PluginError("Failed to retrieve calendar ID.")
21
25
 
22
- data object AttendeeEmailMissing : PluginError("Attendee email must be provided.")
26
+ data object FailedToRetrieveEventId : PluginError("Failed to retrieve event ID.")
23
27
 
24
- data object NoCalendarsAvailable : PluginError("No calendars available.")
28
+ data object FromDateMissing : PluginError("From date must be provided.")
25
29
 
26
- data object ColorMissing : PluginError("Color must be provided.")
30
+ data object InstanceDateMissing : PluginError(
31
+ "Instance date must be provided for this span on recurring events.",
32
+ )
27
33
 
28
- data object AccountNameMissing : PluginError("Account name must be provided.")
34
+ data object InvalidCalendarId : PluginError("Invalid calendar ID.")
29
35
 
30
- data object OwnerAccountMissing : PluginError("Owner account must be provided.")
36
+ data object InvalidColor : PluginError("Invalid color format.")
31
37
 
32
- data object FailedToDelete : PluginError("Failed to delete.")
38
+ data object InvalidInvitees : PluginError("Invalid invitees. Array must contain only strings.")
39
+
40
+ data object InvalidScope : PluginError("Invalid scope.")
33
41
 
34
42
  data object MessageMissing : PluginError("Message must be provided.")
35
43
 
36
- data object FromDateMissing : PluginError("From date must be provided.")
44
+ data object MissingId : PluginError("Event ID must be provided.")
45
+
46
+ data object MissingScope : PluginError("Scope must be provided.")
47
+
48
+ data object NoCalendarsAvailable : PluginError("No calendars available.")
49
+
50
+ data object NoFieldsToModify : PluginError("At least one of title or color must be provided.")
51
+
52
+ data object OwnerAccountMissing : PluginError("Owner account must be provided.")
53
+
54
+ data object TitleMissing : PluginError("Title must be provided.")
37
55
 
38
56
  data object ToDateMissing : PluginError("To date must be provided.")
39
57
 
40
- data object FailedToModify : PluginError("Failed to modify.")
58
+ data object UnhandledPermissionState : PluginError("Unhandled permission state.")
41
59
 
42
60
  data class Unimplemented(
43
61
  val methodName: String,
44
62
  ) : PluginError("$methodName is not implemented on Android.")
45
-
46
- data class CustomError(
47
- val details: String,
48
- ) : PluginError(details)
49
63
  }
@@ -20,6 +20,7 @@ import dev.barooni.capacitor.calendar.models.inputs.DeleteCalendarInput
20
20
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventInput
21
21
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventWithPromptInput
22
22
  import dev.barooni.capacitor.calendar.models.inputs.DeleteEventsByIdInput
23
+ import dev.barooni.capacitor.calendar.models.inputs.GetDefaultCalendarInput
23
24
  import dev.barooni.capacitor.calendar.models.inputs.ListEventsInRangeInput
24
25
  import dev.barooni.capacitor.calendar.models.inputs.ModifyCalendarInput
25
26
  import dev.barooni.capacitor.calendar.models.inputs.ModifyEvent
@@ -36,13 +37,14 @@ import dev.barooni.capacitor.calendar.models.results.DeleteEventsByIdResult
36
37
  import dev.barooni.capacitor.calendar.models.results.GetDefaultCalendarResult
37
38
  import dev.barooni.capacitor.calendar.models.results.ListCalendarsResult
38
39
  import dev.barooni.capacitor.calendar.models.results.ListEventsInRangeResult
40
+ import dev.barooni.capacitor.calendar.models.templates.PluginCompletion
39
41
  import dev.barooni.capacitor.calendar.utils.ImplementationHelper
40
42
 
41
43
  class CapacitorCalendar(
42
44
  private val plugin: CapacitorCalendarPlugin,
43
45
  ) {
44
46
  fun checkPermission(input: CheckPermissionInput): CheckPermissionResult {
45
- val state = plugin.getPermissionState(input.scope.value) ?: throw PluginError.UnhandledPermissionState
47
+ val state = plugin.getPermissionState(input.scope.value) ?: PermissionState.PROMPT
46
48
  val result = CheckPermissionResult(state)
47
49
  return result
48
50
  }
@@ -138,17 +140,29 @@ class CapacitorCalendar(
138
140
  }
139
141
  }
140
142
 
141
- fun listCalendars(): ListCalendarsResult {
142
- val cr = plugin.context.contentResolver
143
- val calendars = ImplementationHelper.listCalendars(cr)
144
- return ListCalendarsResult(calendars)
143
+ fun listCalendars(completion: PluginCompletion<ListCalendarsResult>) {
144
+ try {
145
+ val cr = plugin.context.contentResolver
146
+ val calendars = ImplementationHelper.listCalendars(cr)
147
+ completion(ListCalendarsResult(calendars), null)
148
+ } catch (error: Exception) {
149
+ completion(null, error)
150
+ }
145
151
  }
146
152
 
147
- fun getDefaultCalendar(): GetDefaultCalendarResult {
148
- val cr = plugin.context.contentResolver
149
- val calendars = ImplementationHelper.listCalendars(cr)
150
- val primaryCalendar = calendars.find { it.isPrimary == true }
151
- return GetDefaultCalendarResult(primaryCalendar)
153
+ fun getDefaultCalendar(
154
+ input: GetDefaultCalendarInput,
155
+ completion: PluginCompletion<GetDefaultCalendarResult>,
156
+ ) {
157
+ try {
158
+ val cr = plugin.context.contentResolver
159
+ val calendars = ImplementationHelper.listCalendars(cr)
160
+ val defaultCalendar =
161
+ ImplementationHelper.resolveDefaultCalendar(calendars, input.useFallbackCalendar)
162
+ completion(GetDefaultCalendarResult(defaultCalendar), null)
163
+ } catch (error: Exception) {
164
+ completion(null, error)
165
+ }
152
166
  }
153
167
 
154
168
  fun openCalendar(input: OpenCalendarInput) {
@@ -188,12 +202,39 @@ class CapacitorCalendar(
188
202
  }
189
203
 
190
204
  fun deleteCalendar(input: DeleteCalendarInput) {
191
- val uri: Uri = ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, input.id)
192
205
  val cr = plugin.context.contentResolver
193
- val rowsDeleted = cr.delete(uri, null, null)
206
+ val calendarUri = ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, input.id)
207
+ val projection =
208
+ arrayOf(
209
+ CalendarContract.Calendars.ACCOUNT_NAME,
210
+ CalendarContract.Calendars.ACCOUNT_TYPE,
211
+ )
194
212
 
213
+ val (accountName, accountType) =
214
+ cr.query(calendarUri, projection, null, null, null)?.use { cursor ->
215
+ if (!cursor.moveToFirst()) {
216
+ throw PluginError.CalendarNotFound
217
+ }
218
+ val name =
219
+ cursor.getString(cursor.getColumnIndexOrThrow(CalendarContract.Calendars.ACCOUNT_NAME))
220
+ ?: throw PluginError.CalendarNotFound
221
+ val type =
222
+ cursor.getString(cursor.getColumnIndexOrThrow(CalendarContract.Calendars.ACCOUNT_TYPE))
223
+ ?: throw PluginError.CalendarNotFound
224
+ name to type
225
+ } ?: throw PluginError.CalendarNotFound
226
+
227
+ val deleteUri =
228
+ calendarUri
229
+ .buildUpon()
230
+ .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
231
+ .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accountName)
232
+ .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, accountType)
233
+ .build()
234
+
235
+ val rowsDeleted = cr.delete(deleteUri, null, null)
195
236
  if (rowsDeleted < 1) {
196
- throw PluginError.FailedToDelete
237
+ throw PluginError.CalendarNotFound
197
238
  }
198
239
  }
199
240
 
@@ -201,10 +242,18 @@ class CapacitorCalendar(
201
242
  val cr = plugin.context.contentResolver
202
243
  val result = DeleteEventsByIdResult()
203
244
  input.ids.forEach { id ->
204
- val deleted = ImplementationHelper.deleteEvent(cr, id)
205
- if (deleted) {
206
- result.deleted(id)
207
- } else {
245
+ try {
246
+ if (ImplementationHelper.requiresInstanceDateForDelete(cr, id, input.span)) {
247
+ result.failed(id)
248
+ return@forEach
249
+ }
250
+ val deleted = ImplementationHelper.deleteEvent(cr, id, input.span, null)
251
+ if (deleted) {
252
+ result.deleted(id)
253
+ } else {
254
+ result.failed(id)
255
+ }
256
+ } catch (_: Exception) {
208
257
  result.failed(id)
209
258
  }
210
259
  }
@@ -213,7 +262,13 @@ class CapacitorCalendar(
213
262
 
214
263
  fun deleteEvent(input: DeleteEventInput) {
215
264
  val cr = plugin.context.contentResolver
216
- val deleted = ImplementationHelper.deleteEvent(cr, input.id)
265
+ ImplementationHelper.ensureInstanceDatePresentIfRequired(
266
+ cr,
267
+ input.id,
268
+ input.span,
269
+ input.instanceDate,
270
+ )
271
+ val deleted = ImplementationHelper.deleteEvent(cr, input.id, input.span, input.instanceDate)
217
272
  if (!deleted) {
218
273
  throw PluginError.FailedToDelete
219
274
  }
@@ -224,6 +279,12 @@ class CapacitorCalendar(
224
279
  onComplete: (DeleteEventWithPromptResult) -> Unit,
225
280
  ) {
226
281
  val cr = plugin.context.contentResolver
282
+ ImplementationHelper.ensureInstanceDatePresentIfRequired(
283
+ cr,
284
+ input.id,
285
+ input.span,
286
+ input.instanceDate,
287
+ )
227
288
  val builder =
228
289
  AlertDialog
229
290
  .Builder(plugin.context)
@@ -234,7 +295,10 @@ class CapacitorCalendar(
234
295
  val result = DeleteEventWithPromptResult(false)
235
296
  onComplete(result)
236
297
  }.setPositiveButton(input.confirmButtonText) { _, _ ->
237
- val result = DeleteEventWithPromptResult(ImplementationHelper.deleteEvent(cr, input.id))
298
+ val result =
299
+ DeleteEventWithPromptResult(
300
+ ImplementationHelper.deleteEvent(cr, input.id, input.span, input.instanceDate),
301
+ )
238
302
  onComplete(result)
239
303
  }
240
304
 
@@ -380,13 +444,16 @@ class CapacitorCalendar(
380
444
  val cr = plugin.context.contentResolver
381
445
  val values =
382
446
  ContentValues().apply {
383
- input.title?.let { put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, it) }
447
+ input.title?.let {
448
+ put(CalendarContract.Calendars.NAME, it)
449
+ put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, it)
450
+ }
384
451
  input.color?.let { put(CalendarContract.Calendars.CALENDAR_COLOR, it) }
385
452
  }
386
453
  val uri: Uri = ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, input.id)
387
454
  val rowsUpdated = cr.update(uri, values, null, null)
388
455
  if (rowsUpdated < 1) {
389
- throw PluginError.FailedToModify
456
+ throw PluginError.CalendarNotFound
390
457
  }
391
458
  }
392
459
  }
@@ -0,0 +1,8 @@
1
+ package dev.barooni.capacitor.calendar.models.data
2
+
3
+ data class EventDeleteInfo(
4
+ val dtStart: Long?,
5
+ val originalId: Long?,
6
+ val originalInstanceTime: Long?,
7
+ val rrule: String?,
8
+ )
@@ -0,0 +1,13 @@
1
+ package dev.barooni.capacitor.calendar.models.enums
2
+
3
+ enum class EventSpan(
4
+ val value: Int,
5
+ ) {
6
+ THIS_EVENT(0),
7
+ THIS_AND_FUTURE_EVENTS(1),
8
+ ;
9
+
10
+ companion object {
11
+ fun fromInt(value: Int): EventSpan? = entries.find { it.value == value }
12
+ }
13
+ }
@@ -12,9 +12,5 @@ data class CheckPermissionInput(
12
12
  init {
13
13
  val rawScope = call.getString("scope") ?: throw PluginError.MissingScope
14
14
  scope = CalendarPermissionScope.fromValue(rawScope) ?: throw PluginError.InvalidScope
15
-
16
- if (scope == CalendarPermissionScope.WRITE_REMINDERS || scope == CalendarPermissionScope.READ_REMINDERS) {
17
- throw PluginError.InvalidScope
18
- }
19
15
  }
20
16
  }
@@ -9,7 +9,9 @@ data class CreateCalendarInput(
9
9
  private val call: PluginCall,
10
10
  ) {
11
11
  val title = call.getString("title") ?: throw PluginError.TitleMissing
12
- val color = call.getString("color").let { ImplementationHelper.hexToColorInt(it) } ?: throw PluginError.ColorMissing
12
+ val color =
13
+ ImplementationHelper.hexToColorInt(call.getString("color"))
14
+ ?: ImplementationHelper.DEFAULT_CALENDAR_COLOR
13
15
  val accountName = call.getString("accountName") ?: throw PluginError.AccountNameMissing
14
16
  val ownerAccount = call.getString("ownerAccount") ?: throw PluginError.OwnerAccountMissing
15
17
  val accountType = CalendarContract.ACCOUNT_TYPE_LOCAL
@@ -6,5 +6,8 @@ import dev.barooni.capacitor.calendar.PluginError
6
6
  data class DeleteCalendarInput(
7
7
  private val call: PluginCall,
8
8
  ) {
9
- val id = call.getString("id")?.toLong() ?: throw PluginError.MissingId
9
+ val id: Long =
10
+ call.getString("id")?.let { idString ->
11
+ idString.toLongOrNull() ?: throw PluginError.InvalidCalendarId
12
+ } ?: throw PluginError.CalendarIdMissing
10
13
  }
@@ -2,9 +2,12 @@ package dev.barooni.capacitor.calendar.models.inputs
2
2
 
3
3
  import com.getcapacitor.PluginCall
4
4
  import dev.barooni.capacitor.calendar.PluginError
5
+ import dev.barooni.capacitor.calendar.models.enums.EventSpan
5
6
 
6
7
  data class DeleteEventInput(
7
8
  private val call: PluginCall,
8
9
  ) {
9
- val id = call.getString("id")?.toLong() ?: throw PluginError.MissingId
10
+ val id = call.getString("id")?.toLongOrNull() ?: throw PluginError.MissingId
11
+ val instanceDate: Long? = call.getLong("instanceDate")
12
+ val span: EventSpan = call.getInt("span")?.let { EventSpan.fromInt(it) } ?: EventSpan.THIS_EVENT
10
13
  }
@@ -2,13 +2,16 @@ package dev.barooni.capacitor.calendar.models.inputs
2
2
 
3
3
  import com.getcapacitor.PluginCall
4
4
  import dev.barooni.capacitor.calendar.PluginError
5
+ import dev.barooni.capacitor.calendar.models.enums.EventSpan
5
6
 
6
7
  data class DeleteEventWithPromptInput(
7
8
  private val call: PluginCall,
8
9
  ) {
9
- val id: Long = call.getString("id")?.toLong() ?: throw PluginError.MissingId
10
+ val id: Long = call.getString("id")?.toLongOrNull() ?: throw PluginError.MissingId
10
11
  val title: String = call.getString("title") ?: throw PluginError.TitleMissing
11
12
  val message: String = call.getString("message") ?: throw PluginError.MessageMissing
12
13
  val confirmButtonText: String = call.getString("confirmButtonText") ?: "Delete"
13
14
  val cancelButtonText: String = call.getString("cancelButtonText") ?: "Cancel"
15
+ val instanceDate: Long? = call.getLong("instanceDate")
16
+ val span: EventSpan = call.getInt("span")?.let { EventSpan.fromInt(it) } ?: EventSpan.THIS_EVENT
14
17
  }
@@ -2,10 +2,12 @@ package dev.barooni.capacitor.calendar.models.inputs
2
2
 
3
3
  import com.getcapacitor.PluginCall
4
4
  import dev.barooni.capacitor.calendar.PluginError
5
+ import dev.barooni.capacitor.calendar.models.enums.EventSpan
5
6
  import dev.barooni.capacitor.calendar.utils.ImplementationHelper
6
7
 
7
8
  data class DeleteEventsByIdInput(
8
9
  private val call: PluginCall,
9
10
  ) {
10
11
  var ids = call.getArray("ids")?.let { ImplementationHelper.jsArrayToLongArray(it) } ?: throw PluginError.MissingId
12
+ val span: EventSpan = call.getInt("span")?.let { EventSpan.fromInt(it) } ?: EventSpan.THIS_EVENT
11
13
  }
@@ -0,0 +1,9 @@
1
+ package dev.barooni.capacitor.calendar.models.inputs
2
+
3
+ import com.getcapacitor.PluginCall
4
+
5
+ data class GetDefaultCalendarInput(
6
+ private val call: PluginCall,
7
+ ) {
8
+ val useFallbackCalendar: Boolean = call.getBoolean("useFallbackCalendar", false) ?: false
9
+ }
@@ -7,7 +7,16 @@ import dev.barooni.capacitor.calendar.utils.ImplementationHelper
7
7
  data class ModifyCalendarInput(
8
8
  private val call: PluginCall,
9
9
  ) {
10
- val id = call.getString("id")?.toLong() ?: throw PluginError.MissingId
10
+ val id: Long =
11
+ call.getString("id")?.let { idString ->
12
+ idString.toLongOrNull() ?: throw PluginError.InvalidCalendarId
13
+ } ?: throw PluginError.CalendarIdMissing
11
14
  val title = call.getString("title")
12
15
  val color = call.getString("color")?.let { ImplementationHelper.hexToColorInt(it) }
16
+
17
+ init {
18
+ if (title == null && color == null) {
19
+ throw PluginError.NoFieldsToModify
20
+ }
21
+ }
13
22
  }
@@ -13,13 +13,11 @@ sealed class RequestPermissionInput {
13
13
  override val call: PluginCall,
14
14
  override val callbackName: String,
15
15
  ) : RequestPermissionInput() {
16
- override val scope: CalendarPermissionScope =
17
- call
18
- .getString("scope")
19
- ?.let { CalendarPermissionScope.fromValue(it) }
20
- ?: throw PluginError.MissingScope
16
+ override val scope: CalendarPermissionScope
21
17
 
22
18
  init {
19
+ val rawScope = call.getString("scope") ?: throw PluginError.MissingScope
20
+ scope = CalendarPermissionScope.fromValue(rawScope) ?: throw PluginError.InvalidScope
23
21
  if (scope == CalendarPermissionScope.WRITE_REMINDERS || scope == CalendarPermissionScope.READ_REMINDERS) {
24
22
  throw PluginError.InvalidScope
25
23
  }
@@ -9,9 +9,10 @@ data class CheckAllPermissionsResult(
9
9
  val permissionStates: Map<CalendarPermissionScope, PermissionState>,
10
10
  ) : JSResult {
11
11
  override fun toJSON(): JSObject {
12
+ val permissions = JSObject()
13
+ permissionStates.forEach { (scope, state) -> permissions.put(scope.value, state.toString()) }
12
14
  val result = JSObject()
13
- permissionStates.forEach { (scope, state) -> result.put(scope.value, state.toString()) }
14
- result.put("result", permissionStates)
15
+ result.put("result", permissions)
15
16
  return result
16
17
  }
17
18
  }
@@ -16,7 +16,7 @@ data class RequestAllPermissionsResult(
16
16
  getPermissionState(CalendarPermissionScope.WRITE_CALENDAR.value) ?: throw PluginError.UnhandledPermissionState
17
17
  permissions.put(CalendarPermissionScope.WRITE_CALENDAR.value, writeCalendarState.toString())
18
18
  val readCalendarState =
19
- getPermissionState(CalendarPermissionScope.WRITE_CALENDAR.value) ?: throw PluginError.UnhandledPermissionState
19
+ getPermissionState(CalendarPermissionScope.READ_CALENDAR.value) ?: throw PluginError.UnhandledPermissionState
20
20
  permissions.put(CalendarPermissionScope.READ_CALENDAR.value, readCalendarState.toString())
21
21
  permissions.put(CalendarPermissionScope.WRITE_REMINDERS.value, PermissionState.PROMPT.toString())
22
22
  permissions.put(CalendarPermissionScope.READ_REMINDERS.value, PermissionState.PROMPT.toString())
@@ -0,0 +1,8 @@
1
+ package dev.barooni.capacitor.calendar.models.templates
2
+
3
+ /**
4
+ * Completion handler matching the `(Result?, Error?) -> Void` pattern.
5
+ *
6
+ * Call with a result and `null` error on success, or `null` result and an error on failure.
7
+ */
8
+ typealias PluginCompletion<T> = (T?, Exception?) -> Unit