@ebarooni/capacitor-calendar 8.1.0 → 8.3.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.
- package/README.md +108 -23
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +10 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +4 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +29 -6
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventDeleteInfo.kt +8 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/enums/EventSpan.kt +13 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventInput.kt +4 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventWithPromptInput.kt +4 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteEventsByIdInput.kt +2 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +272 -4
- package/dist/docs.json +414 -45
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/event-span.d.ts +4 -0
- package/dist/esm/schemas/enums/event-span.js +4 -0
- package/dist/esm/schemas/enums/event-span.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-reminders-list-options.d.ts +0 -1
- package/dist/esm/schemas/interfaces/create-reminders-list-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-reminders-list-result.d.ts +0 -1
- package/dist/esm/schemas/interfaces/create-reminders-list-result.js.map +1 -1
- package/dist/esm/schemas/interfaces/delete-event-options.d.ts +28 -3
- package/dist/esm/schemas/interfaces/delete-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.d.ts +38 -13
- package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/delete-events-by-id-options.d.ts +15 -3
- package/dist/esm/schemas/interfaces/delete-events-by-id-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/delete-reminders-list-options.d.ts +23 -0
- package/dist/esm/schemas/interfaces/delete-reminders-list-options.js +2 -0
- package/dist/esm/schemas/interfaces/delete-reminders-list-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-options.d.ts +40 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-options.js +2 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-result.d.ts +12 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-result.js +2 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-result.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-operations.d.ts +1 -1
- package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
- package/dist/esm/sub-definitions/reminders-operations.d.ts +17 -0
- package/dist/esm/sub-definitions/reminders-operations.js.map +1 -1
- package/dist/esm/web.d.ts +5 -0
- package/dist/esm/web.js +6 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +10 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +10 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +30 -0
- package/ios/Plugin/Implementation/CapacitorCalendar.swift +42 -3
- package/ios/Plugin/Models/Enums/EventSpan.swift +8 -0
- package/ios/Plugin/Models/Inputs/DeleteEventInput.swift +9 -4
- package/ios/Plugin/Models/Inputs/DeleteEventWithPromptInput.swift +9 -4
- package/ios/Plugin/Models/Inputs/DeleteEventsByIdInput.swift +9 -4
- package/ios/Plugin/Models/Inputs/DeleteRemindersListInput.swift +22 -0
- package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +55 -0
- package/ios/Plugin/Models/Results/UpdateRemindersListResult.swift +15 -0
- package/ios/Plugin/PluginConfig.swift +3 -1
- package/ios/Plugin/PluginError.swift +3 -0
- package/ios/Plugin/Utils/ImplementationHelper.swift +7 -2
- package/package.json +1 -1
|
@@ -8,9 +8,13 @@ import com.getcapacitor.JSArray
|
|
|
8
8
|
import com.getcapacitor.PluginCall
|
|
9
9
|
import dev.barooni.capacitor.calendar.PluginError
|
|
10
10
|
import dev.barooni.capacitor.calendar.models.data.CalendarInfo
|
|
11
|
+
import dev.barooni.capacitor.calendar.models.data.EventDeleteInfo
|
|
11
12
|
import dev.barooni.capacitor.calendar.models.data.EventGuest
|
|
13
|
+
import dev.barooni.capacitor.calendar.models.enums.EventSpan
|
|
12
14
|
import org.json.JSONObject
|
|
13
15
|
import java.util.Calendar
|
|
16
|
+
import java.util.Locale
|
|
17
|
+
import java.util.TimeZone
|
|
14
18
|
|
|
15
19
|
class ImplementationHelper {
|
|
16
20
|
companion object {
|
|
@@ -36,7 +40,7 @@ class ImplementationHelper {
|
|
|
36
40
|
|
|
37
41
|
fun jsArrayToLongArray(array: JSArray): List<Long> {
|
|
38
42
|
val list = array.toList<String>()
|
|
39
|
-
return list.map { it.
|
|
43
|
+
return list.map { it.toLongOrNull() ?: throw PluginError.MissingId }
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
fun hexToColorInt(hex: String?): Int? =
|
|
@@ -272,13 +276,277 @@ class ImplementationHelper {
|
|
|
272
276
|
return calendars
|
|
273
277
|
}
|
|
274
278
|
|
|
279
|
+
fun requiresInstanceDateForDelete(
|
|
280
|
+
cr: ContentResolver,
|
|
281
|
+
eventId: Long,
|
|
282
|
+
span: EventSpan,
|
|
283
|
+
): Boolean = needsInstanceDate(queryEventDeleteInfo(cr, eventId), span)
|
|
284
|
+
|
|
285
|
+
fun ensureInstanceDatePresentIfRequired(
|
|
286
|
+
cr: ContentResolver,
|
|
287
|
+
eventId: Long,
|
|
288
|
+
span: EventSpan,
|
|
289
|
+
instanceDate: Long?,
|
|
290
|
+
) {
|
|
291
|
+
if (requiresInstanceDateForDelete(cr, eventId, span) && instanceDate == null) {
|
|
292
|
+
throw PluginError.InstanceDateMissing
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
275
296
|
fun deleteEvent(
|
|
276
297
|
cr: ContentResolver,
|
|
277
298
|
eventId: Long,
|
|
299
|
+
span: EventSpan,
|
|
300
|
+
instanceDate: Long? = null,
|
|
301
|
+
): Boolean {
|
|
302
|
+
val info = queryEventDeleteInfo(cr, eventId)
|
|
303
|
+
val masterId = info.originalId ?: eventId
|
|
304
|
+
val isException = info.originalId != null
|
|
305
|
+
val isRecurringMaster = !info.rrule.isNullOrBlank() && !isException
|
|
306
|
+
|
|
307
|
+
return when (span) {
|
|
308
|
+
EventSpan.THIS_EVENT -> {
|
|
309
|
+
when {
|
|
310
|
+
isException -> {
|
|
311
|
+
deleteEventRow(cr, eventId)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
isRecurringMaster -> {
|
|
315
|
+
val date = instanceDate ?: throw PluginError.InstanceDateMissing
|
|
316
|
+
insertCanceledException(cr, masterId, date)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
else -> {
|
|
320
|
+
deleteEventRow(cr, eventId)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
EventSpan.THIS_AND_FUTURE_EVENTS -> {
|
|
326
|
+
when {
|
|
327
|
+
isRecurringMaster -> {
|
|
328
|
+
// No instanceDate → treat as deleting from series start (whole series).
|
|
329
|
+
if (instanceDate == null) {
|
|
330
|
+
deleteEventRow(cr, masterId)
|
|
331
|
+
} else {
|
|
332
|
+
deleteThisAndFuture(cr, masterId, instanceDate)
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
isException -> {
|
|
337
|
+
val date =
|
|
338
|
+
instanceDate
|
|
339
|
+
?: info.originalInstanceTime
|
|
340
|
+
?: throw PluginError.InstanceDateMissing
|
|
341
|
+
deleteThisAndFuture(cr, masterId, date)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
else -> {
|
|
345
|
+
deleteEventRow(cr, eventId)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private fun needsInstanceDate(
|
|
353
|
+
info: EventDeleteInfo,
|
|
354
|
+
span: EventSpan,
|
|
355
|
+
): Boolean {
|
|
356
|
+
val isException = info.originalId != null
|
|
357
|
+
val isRecurringMaster = !info.rrule.isNullOrBlank() && !isException
|
|
358
|
+
return when (span) {
|
|
359
|
+
// Only occurrence cancel on a series master needs an explicit instance time.
|
|
360
|
+
EventSpan.THIS_EVENT -> isRecurringMaster
|
|
361
|
+
|
|
362
|
+
// Masters fall back to whole-series delete; exceptions fall back to ORIGINAL_INSTANCE_TIME.
|
|
363
|
+
EventSpan.THIS_AND_FUTURE_EVENTS -> isException && info.originalInstanceTime == null
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private fun deleteEventRow(
|
|
368
|
+
cr: ContentResolver,
|
|
369
|
+
eventId: Long,
|
|
370
|
+
): Boolean {
|
|
371
|
+
val uri =
|
|
372
|
+
ContentUris.withAppendedId(
|
|
373
|
+
CalendarContract.Events.CONTENT_URI,
|
|
374
|
+
eventId,
|
|
375
|
+
)
|
|
376
|
+
return cr.delete(uri, null, null) > 0
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private fun insertCanceledException(
|
|
380
|
+
cr: ContentResolver,
|
|
381
|
+
masterId: Long,
|
|
382
|
+
instanceDate: Long,
|
|
383
|
+
): Boolean {
|
|
384
|
+
val values =
|
|
385
|
+
ContentValues().apply {
|
|
386
|
+
put(CalendarContract.Events.ORIGINAL_INSTANCE_TIME, instanceDate)
|
|
387
|
+
put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CANCELED)
|
|
388
|
+
}
|
|
389
|
+
val uri =
|
|
390
|
+
ContentUris.withAppendedId(
|
|
391
|
+
CalendarContract.Events.CONTENT_EXCEPTION_URI,
|
|
392
|
+
masterId,
|
|
393
|
+
)
|
|
394
|
+
return cr.insert(uri, values) != null
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
private fun deleteThisAndFuture(
|
|
398
|
+
cr: ContentResolver,
|
|
399
|
+
masterId: Long,
|
|
400
|
+
instanceDate: Long,
|
|
278
401
|
): Boolean {
|
|
279
|
-
val
|
|
280
|
-
val
|
|
281
|
-
|
|
402
|
+
val info = queryEventDeleteInfo(cr, masterId)
|
|
403
|
+
val rrule = info.rrule
|
|
404
|
+
if (rrule.isNullOrBlank()) {
|
|
405
|
+
return false
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Targeting the first occurrence (or earlier) removes the whole series.
|
|
409
|
+
val seriesStart = info.dtStart
|
|
410
|
+
if (seriesStart != null && instanceDate <= seriesStart) {
|
|
411
|
+
return deleteEventRow(cr, masterId)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
val values =
|
|
415
|
+
ContentValues().apply {
|
|
416
|
+
put(CalendarContract.Events.RRULE, rruleEndingBefore(rrule, instanceDate))
|
|
417
|
+
}
|
|
418
|
+
val uri =
|
|
419
|
+
ContentUris.withAppendedId(
|
|
420
|
+
CalendarContract.Events.CONTENT_URI,
|
|
421
|
+
masterId,
|
|
422
|
+
)
|
|
423
|
+
return cr.update(uri, values, null, null) > 0
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
private fun rruleEndingBefore(
|
|
427
|
+
rrule: String,
|
|
428
|
+
instanceDateMs: Long,
|
|
429
|
+
): String {
|
|
430
|
+
// UNTIL is inclusive; end the series one second before this occurrence.
|
|
431
|
+
val untilMs = instanceDateMs - 1000L
|
|
432
|
+
val untilPart = "UNTIL=${formatUntilUtc(untilMs)}"
|
|
433
|
+
val parts =
|
|
434
|
+
rrule
|
|
435
|
+
.split(";")
|
|
436
|
+
.filter { part ->
|
|
437
|
+
val key = part.substringBefore("=").uppercase()
|
|
438
|
+
key.isNotEmpty() && key != "UNTIL" && key != "COUNT"
|
|
439
|
+
}.toMutableList()
|
|
440
|
+
parts.add(untilPart)
|
|
441
|
+
return parts.joinToString(";")
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private fun formatUntilUtc(untilMs: Long): String {
|
|
445
|
+
val calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
|
446
|
+
calendar.timeInMillis = untilMs
|
|
447
|
+
|
|
448
|
+
val year = calendar.get(Calendar.YEAR)
|
|
449
|
+
val month = calendar.get(Calendar.MONTH) + 1
|
|
450
|
+
val day = calendar.get(Calendar.DAY_OF_MONTH)
|
|
451
|
+
val hour = calendar.get(Calendar.HOUR_OF_DAY)
|
|
452
|
+
val minute = calendar.get(Calendar.MINUTE)
|
|
453
|
+
val second = calendar.get(Calendar.SECOND)
|
|
454
|
+
|
|
455
|
+
return String.format(
|
|
456
|
+
Locale.US,
|
|
457
|
+
"%04d%02d%02dT%02d%02d%02dZ",
|
|
458
|
+
year,
|
|
459
|
+
month,
|
|
460
|
+
day,
|
|
461
|
+
hour,
|
|
462
|
+
minute,
|
|
463
|
+
second,
|
|
464
|
+
)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
private fun queryEventDeleteInfo(
|
|
468
|
+
cr: ContentResolver,
|
|
469
|
+
eventId: Long,
|
|
470
|
+
): EventDeleteInfo {
|
|
471
|
+
val uri =
|
|
472
|
+
ContentUris.withAppendedId(
|
|
473
|
+
CalendarContract.Events.CONTENT_URI,
|
|
474
|
+
eventId,
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
val projection =
|
|
478
|
+
arrayOf(
|
|
479
|
+
CalendarContract.Events.DTSTART,
|
|
480
|
+
CalendarContract.Events.ORIGINAL_ID,
|
|
481
|
+
CalendarContract.Events.ORIGINAL_INSTANCE_TIME,
|
|
482
|
+
CalendarContract.Events.RRULE,
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
cr
|
|
486
|
+
.query(
|
|
487
|
+
uri,
|
|
488
|
+
projection,
|
|
489
|
+
null,
|
|
490
|
+
null,
|
|
491
|
+
null,
|
|
492
|
+
)?.use { cursor ->
|
|
493
|
+
if (!cursor.moveToFirst()) {
|
|
494
|
+
return EventDeleteInfo(
|
|
495
|
+
dtStart = null,
|
|
496
|
+
originalId = null,
|
|
497
|
+
originalInstanceTime = null,
|
|
498
|
+
rrule = null,
|
|
499
|
+
)
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
val dtStartIndex = cursor.getColumnIndex(CalendarContract.Events.DTSTART)
|
|
503
|
+
val originalIdIndex = cursor.getColumnIndex(CalendarContract.Events.ORIGINAL_ID)
|
|
504
|
+
val originalInstanceTimeIndex =
|
|
505
|
+
cursor.getColumnIndex(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
|
|
506
|
+
val rruleIndex = cursor.getColumnIndex(CalendarContract.Events.RRULE)
|
|
507
|
+
|
|
508
|
+
val dtStart =
|
|
509
|
+
if (dtStartIndex >= 0 && !cursor.isNull(dtStartIndex)) {
|
|
510
|
+
cursor.getLong(dtStartIndex)
|
|
511
|
+
} else {
|
|
512
|
+
null
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
val originalId =
|
|
516
|
+
if (originalIdIndex >= 0 && !cursor.isNull(originalIdIndex)) {
|
|
517
|
+
cursor.getLong(originalIdIndex)
|
|
518
|
+
} else {
|
|
519
|
+
null
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
val originalInstanceTime =
|
|
523
|
+
if (originalInstanceTimeIndex >= 0 && !cursor.isNull(originalInstanceTimeIndex)) {
|
|
524
|
+
cursor.getLong(originalInstanceTimeIndex)
|
|
525
|
+
} else {
|
|
526
|
+
null
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
val rrule =
|
|
530
|
+
if (rruleIndex >= 0 && !cursor.isNull(rruleIndex)) {
|
|
531
|
+
cursor.getString(rruleIndex)
|
|
532
|
+
} else {
|
|
533
|
+
null
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return EventDeleteInfo(
|
|
537
|
+
dtStart = dtStart,
|
|
538
|
+
originalId = originalId,
|
|
539
|
+
originalInstanceTime = originalInstanceTime,
|
|
540
|
+
rrule = rrule,
|
|
541
|
+
)
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return EventDeleteInfo(
|
|
545
|
+
dtStart = null,
|
|
546
|
+
originalId = null,
|
|
547
|
+
originalInstanceTime = null,
|
|
548
|
+
rrule = null,
|
|
549
|
+
)
|
|
282
550
|
}
|
|
283
551
|
|
|
284
552
|
fun getEventAlerts(
|