@ebarooni/capacitor-calendar 8.10.0 → 8.12.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 +372 -156
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +55 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +4 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CalendarChangeObserver.kt +181 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +184 -8
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventDeleteInfo.kt +6 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventRecurrenceRule.kt +4 -3
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetEventByIdInput.kt +13 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ListEventsInRangeInput.kt +5 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/StartListeningInput.kt +20 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/GetEventByIdResult.kt +15 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/ListEventsInRangeResult.kt +47 -43
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +123 -69
- package/dist/docs.json +1594 -989
- package/dist/esm/definitions.d.ts +2 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +15 -2
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.d.ts +2 -2
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js +2 -2
- package/dist/esm/schemas/enums/capacitor-calendar-error-code.js.map +1 -1
- package/dist/esm/schemas/interfaces/calendar-changed-event.d.ts +52 -0
- package/dist/esm/schemas/interfaces/calendar-changed-event.js +2 -0
- package/dist/esm/schemas/interfaces/calendar-changed-event.js.map +1 -0
- package/dist/esm/schemas/interfaces/calendar-links.d.ts +32 -0
- package/dist/esm/schemas/interfaces/calendar-links.js +2 -0
- package/dist/esm/schemas/interfaces/calendar-links.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-event-options.d.ts +18 -0
- package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.d.ts +9 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-ics-file-options.d.ts +20 -0
- package/dist/esm/schemas/interfaces/create-ics-file-options.js +2 -0
- package/dist/esm/schemas/interfaces/create-ics-file-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/delete-event-options.d.ts +2 -1
- package/dist/esm/schemas/interfaces/delete-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.d.ts +2 -1
- package/dist/esm/schemas/interfaces/delete-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/get-event-by-id-options.d.ts +11 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-options.js +2 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-result.js +2 -0
- package/dist/esm/schemas/interfaces/get-event-by-id-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/list-events-in-range-options.d.ts +8 -0
- package/dist/esm/schemas/interfaces/list-events-in-range-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-event-options.d.ts +11 -0
- package/dist/esm/schemas/interfaces/modify-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.d.ts +10 -0
- package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +9 -0
- package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/share-ics-file-options.d.ts +17 -0
- package/dist/esm/schemas/interfaces/share-ics-file-options.js +2 -0
- package/dist/esm/schemas/interfaces/share-ics-file-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/start-listening-options.d.ts +46 -0
- package/dist/esm/schemas/interfaces/start-listening-options.js +2 -0
- package/dist/esm/schemas/interfaces/start-listening-options.js.map +1 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.d.ts +7 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.js +2 -0
- package/dist/esm/schemas/types/calendar-day-view-provider.js.map +1 -0
- package/dist/esm/schemas/types/calendar-link-provider.d.ts +6 -0
- package/dist/esm/schemas/types/calendar-link-provider.js +2 -0
- package/dist/esm/schemas/types/calendar-link-provider.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-listening.d.ts +49 -0
- package/dist/esm/sub-definitions/calendar-listening.js +2 -0
- package/dist/esm/sub-definitions/calendar-listening.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-operations.d.ts +2 -1
- package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
- package/dist/esm/sub-definitions/event-operations.d.ts +33 -0
- package/dist/esm/sub-definitions/event-operations.js.map +1 -1
- package/dist/esm/web/calendar-links.d.ts +26 -0
- package/dist/esm/web/calendar-links.js +114 -0
- package/dist/esm/web/calendar-links.js.map +1 -0
- package/dist/esm/web/create-ics-file.d.ts +21 -0
- package/dist/esm/web/create-ics-file.js +30 -0
- package/dist/esm/web/create-ics-file.js.map +1 -0
- package/dist/esm/web/ics.d.ts +11 -0
- package/dist/esm/web/ics.js +48 -32
- package/dist/esm/web/ics.js.map +1 -1
- package/dist/esm/web/share-ics-file.d.ts +21 -0
- package/dist/esm/web/share-ics-file.js +46 -0
- package/dist/esm/web/share-ics-file.js.map +1 -0
- package/dist/esm/web.d.ts +7 -1
- package/dist/esm/web.js +21 -4
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +295 -72
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +295 -72
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +36 -1
- package/ios/Plugin/Implementation/CalendarChangeObserver.swift +259 -0
- package/ios/Plugin/Implementation/CapacitorCalendar.swift +56 -8
- package/ios/Plugin/Models/Inputs/CreateEventInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/CreateEventWithPromptInput.swift +61 -70
- package/ios/Plugin/Models/Inputs/DeleteEventInput.swift +7 -0
- package/ios/Plugin/Models/Inputs/DeleteEventWithPromptInput.swift +7 -0
- package/ios/Plugin/Models/Inputs/DeleteReminderInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/DeleteReminderWithPromptInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/DeleteRemindersListInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/GetEventByIdInput.swift +16 -0
- package/ios/Plugin/Models/Inputs/GetReminderByIdInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/ListEventsInRangeInput.swift +20 -0
- package/ios/Plugin/Models/Inputs/ModifyEventInput.swift +13 -23
- package/ios/Plugin/Models/Inputs/ModifyEventWithPromptInput.swift +10 -5
- package/ios/Plugin/Models/Inputs/ModifyReminderInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/StartListeningInput.swift +26 -0
- package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +1 -1
- package/ios/Plugin/Models/Results/GetEventByIdResult.swift +27 -0
- package/ios/Plugin/Models/Structs/RecurrenceInput.swift +14 -0
- package/ios/Plugin/PluginConfig.swift +3 -0
- package/ios/Plugin/PluginError.swift +32 -3
- package/ios/Plugin/Utils/ImplementationHelper.swift +49 -32
- package/ios/Plugin/Utils/PluginCallRejecter.swift +13 -0
- package/package.json +1 -1
|
@@ -12,51 +12,55 @@ data class ListEventsInRangeResult(
|
|
|
12
12
|
val result = JSObject()
|
|
13
13
|
val array = JSArray()
|
|
14
14
|
events.forEach { event ->
|
|
15
|
-
|
|
16
|
-
obj.put("id", event.id)
|
|
17
|
-
obj.put("masterId", event.masterId)
|
|
18
|
-
obj.put("title", event.title)
|
|
19
|
-
obj.put("calendarId", event.calendarId)
|
|
20
|
-
obj.put("calendarItemExternalIdentifier", event.calendarItemExternalIdentifier)
|
|
21
|
-
obj.put("location", event.location)
|
|
22
|
-
obj.put("startDate", event.startDate)
|
|
23
|
-
obj.put("seriesStartDate", event.seriesStartDate)
|
|
24
|
-
obj.put("endDate", event.endDate)
|
|
25
|
-
obj.put("isAllDay", event.isAllDay)
|
|
26
|
-
event.alerts.let { alerts ->
|
|
27
|
-
val alertsJSArray = JSArray()
|
|
28
|
-
alerts.forEach { alert -> alertsJSArray.put(alert) }
|
|
29
|
-
obj.put("alerts", alertsJSArray)
|
|
30
|
-
}
|
|
31
|
-
obj.put("url", event.url)
|
|
32
|
-
obj.put("description", event.description)
|
|
33
|
-
obj.put("availability", event.availability)
|
|
34
|
-
obj.put("organizer", event.organizer)
|
|
35
|
-
obj.put("color", event.color)
|
|
36
|
-
obj.put("duration", event.duration)
|
|
37
|
-
obj.put("isDetached", event.isDetached)
|
|
38
|
-
obj.put("isPartOfSeries", event.isPartOfSeries)
|
|
39
|
-
obj.put("birthdayContactIdentifier", event.birthdayContactIdentifier)
|
|
40
|
-
obj.put("status", event.status)
|
|
41
|
-
obj.put("creationDate", event.creationDate)
|
|
42
|
-
obj.put("lastModifiedDate", event.lastModifiedDate)
|
|
43
|
-
event.attendees.let { attendees ->
|
|
44
|
-
val attendeesJSArray = JSArray()
|
|
45
|
-
attendees.forEach { attendee ->
|
|
46
|
-
val attendeeObj = JSObject()
|
|
47
|
-
attendeeObj.put("email", attendee.email)
|
|
48
|
-
attendeeObj.put("name", attendee.name)
|
|
49
|
-
attendeeObj.put("role", attendee.relationship)
|
|
50
|
-
attendeeObj.put("status", attendee.status)
|
|
51
|
-
attendeeObj.put("type", attendee.type)
|
|
52
|
-
attendeesJSArray.put(attendeeObj)
|
|
53
|
-
}
|
|
54
|
-
obj.put("attendees", attendeesJSArray)
|
|
55
|
-
}
|
|
56
|
-
obj.put("timezone", event.timezone)
|
|
57
|
-
array.put(obj)
|
|
15
|
+
array.put(event.toJSObject())
|
|
58
16
|
}
|
|
59
17
|
result.put("result", array)
|
|
60
18
|
return result
|
|
61
19
|
}
|
|
62
20
|
}
|
|
21
|
+
|
|
22
|
+
internal fun CalendarEvent.toJSObject(): JSObject {
|
|
23
|
+
val obj = JSObject()
|
|
24
|
+
obj.put("id", id)
|
|
25
|
+
obj.put("masterId", masterId)
|
|
26
|
+
obj.put("title", title)
|
|
27
|
+
obj.put("calendarId", calendarId)
|
|
28
|
+
obj.put("calendarItemExternalIdentifier", calendarItemExternalIdentifier)
|
|
29
|
+
obj.put("location", location)
|
|
30
|
+
obj.put("startDate", startDate)
|
|
31
|
+
obj.put("seriesStartDate", seriesStartDate)
|
|
32
|
+
obj.put("endDate", endDate)
|
|
33
|
+
obj.put("isAllDay", isAllDay)
|
|
34
|
+
alerts.let { alerts ->
|
|
35
|
+
val alertsJSArray = JSArray()
|
|
36
|
+
alerts.forEach { alert -> alertsJSArray.put(alert) }
|
|
37
|
+
obj.put("alerts", alertsJSArray)
|
|
38
|
+
}
|
|
39
|
+
obj.put("url", url)
|
|
40
|
+
obj.put("description", description)
|
|
41
|
+
obj.put("availability", availability)
|
|
42
|
+
obj.put("organizer", organizer)
|
|
43
|
+
obj.put("color", color)
|
|
44
|
+
obj.put("duration", duration)
|
|
45
|
+
obj.put("isDetached", isDetached)
|
|
46
|
+
obj.put("isPartOfSeries", isPartOfSeries)
|
|
47
|
+
obj.put("birthdayContactIdentifier", birthdayContactIdentifier)
|
|
48
|
+
obj.put("status", status)
|
|
49
|
+
obj.put("creationDate", creationDate)
|
|
50
|
+
obj.put("lastModifiedDate", lastModifiedDate)
|
|
51
|
+
attendees.let { attendees ->
|
|
52
|
+
val attendeesJSArray = JSArray()
|
|
53
|
+
attendees.forEach { attendee ->
|
|
54
|
+
val attendeeObj = JSObject()
|
|
55
|
+
attendeeObj.put("email", attendee.email)
|
|
56
|
+
attendeeObj.put("name", attendee.name)
|
|
57
|
+
attendeeObj.put("role", attendee.relationship)
|
|
58
|
+
attendeeObj.put("status", attendee.status)
|
|
59
|
+
attendeeObj.put("type", attendee.type)
|
|
60
|
+
attendeesJSArray.put(attendeeObj)
|
|
61
|
+
}
|
|
62
|
+
obj.put("attendees", attendeesJSArray)
|
|
63
|
+
}
|
|
64
|
+
obj.put("timezone", timezone)
|
|
65
|
+
return obj
|
|
66
|
+
}
|
|
@@ -87,6 +87,21 @@ class ImplementationHelper {
|
|
|
87
87
|
return Pair(start, exclusiveEnd)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Throws [PluginError.EventNotFound] when no event row has this id.
|
|
92
|
+
*/
|
|
93
|
+
fun ensureEventExists(
|
|
94
|
+
cr: ContentResolver,
|
|
95
|
+
eventId: Long,
|
|
96
|
+
) {
|
|
97
|
+
val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId)
|
|
98
|
+
val projection = arrayOf(CalendarContract.Events._ID)
|
|
99
|
+
val exists = cr.query(uri, projection, null, null, null)?.use { cursor -> cursor.moveToFirst() } ?: false
|
|
100
|
+
if (!exists) {
|
|
101
|
+
throw PluginError.EventNotFound
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
90
105
|
/**
|
|
91
106
|
* Reads [CalendarContract.Events.ALL_DAY] for an existing event.
|
|
92
107
|
* Throws [PluginError.EventNotFound] when the row is missing or unreadable,
|
|
@@ -121,9 +136,12 @@ class ImplementationHelper {
|
|
|
121
136
|
return list
|
|
122
137
|
}
|
|
123
138
|
|
|
124
|
-
fun jsArrayToLongArray(
|
|
139
|
+
fun jsArrayToLongArray(
|
|
140
|
+
array: JSArray,
|
|
141
|
+
error: PluginError = PluginError.InvalidEventId,
|
|
142
|
+
): List<Long> {
|
|
125
143
|
val list = array.toList<String>()
|
|
126
|
-
return list.map { it.toLongOrNull() ?: throw
|
|
144
|
+
return list.map { it.toLongOrNull() ?: throw error }
|
|
127
145
|
}
|
|
128
146
|
|
|
129
147
|
fun hexToColorInt(hex: String?): Int? {
|
|
@@ -455,7 +473,13 @@ class ImplementationHelper {
|
|
|
455
473
|
|
|
456
474
|
isRecurringMaster -> {
|
|
457
475
|
val date = instanceDate ?: throw PluginError.InstanceDateMissing
|
|
458
|
-
|
|
476
|
+
// The provider links exceptions to a series by its sync id.
|
|
477
|
+
// A series without a sync id loses all its instances when an exception is added.
|
|
478
|
+
if (info.syncId.isNullOrEmpty()) {
|
|
479
|
+
excludeOccurrence(cr, masterId, info, date)
|
|
480
|
+
} else {
|
|
481
|
+
insertCanceledException(cr, masterId, date)
|
|
482
|
+
}
|
|
459
483
|
}
|
|
460
484
|
|
|
461
485
|
else -> {
|
|
@@ -554,7 +578,7 @@ class ImplementationHelper {
|
|
|
554
578
|
}
|
|
555
579
|
|
|
556
580
|
val values =
|
|
557
|
-
|
|
581
|
+
recurrenceValues(info).apply {
|
|
558
582
|
put(CalendarContract.Events.RRULE, rruleEndingBefore(rrule, instanceDate))
|
|
559
583
|
}
|
|
560
584
|
val uri =
|
|
@@ -565,6 +589,58 @@ class ImplementationHelper {
|
|
|
565
589
|
return cr.update(uri, values, null, null) > 0
|
|
566
590
|
}
|
|
567
591
|
|
|
592
|
+
/**
|
|
593
|
+
* Adds the occurrence that starts at [instanceDate] to the EXDATE list of the series.
|
|
594
|
+
*/
|
|
595
|
+
private fun excludeOccurrence(
|
|
596
|
+
cr: ContentResolver,
|
|
597
|
+
masterId: Long,
|
|
598
|
+
info: EventDeleteInfo,
|
|
599
|
+
instanceDate: Long,
|
|
600
|
+
): Boolean {
|
|
601
|
+
val excluded = formatExdate(instanceDate, info.isAllDay)
|
|
602
|
+
val values =
|
|
603
|
+
recurrenceValues(info).apply {
|
|
604
|
+
put(
|
|
605
|
+
CalendarContract.Events.EXDATE,
|
|
606
|
+
listOfNotNull(info.exdate?.takeIf { it.isNotBlank() }, excluded).joinToString(","),
|
|
607
|
+
)
|
|
608
|
+
}
|
|
609
|
+
val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, masterId)
|
|
610
|
+
return cr.update(uri, values, null, null) > 0
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* The provider expands the instances of a series only from the fields in the update.
|
|
615
|
+
* Fields that are not in the update are ignored. An update of the rule must send all of them.
|
|
616
|
+
* A series must have DURATION and no DTEND.
|
|
617
|
+
*/
|
|
618
|
+
private fun recurrenceValues(info: EventDeleteInfo): ContentValues =
|
|
619
|
+
ContentValues().apply {
|
|
620
|
+
info.dtStart?.let { put(CalendarContract.Events.DTSTART, it) }
|
|
621
|
+
info.rrule?.let { put(CalendarContract.Events.RRULE, it) }
|
|
622
|
+
info.exdate?.let { put(CalendarContract.Events.EXDATE, it) }
|
|
623
|
+
info.timezone?.let { put(CalendarContract.Events.EVENT_TIMEZONE, it) }
|
|
624
|
+
put(CalendarContract.Events.ALL_DAY, if (info.isAllDay) 1 else 0)
|
|
625
|
+
val duration =
|
|
626
|
+
info.duration
|
|
627
|
+
?: info.dtStart?.let { start ->
|
|
628
|
+
info.dtEnd?.let { end -> buildDurationFromBeginEnd(start, end, info.isAllDay) }
|
|
629
|
+
}
|
|
630
|
+
if (duration != null) {
|
|
631
|
+
put(CalendarContract.Events.DURATION, duration)
|
|
632
|
+
putNull(CalendarContract.Events.DTEND)
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
private fun formatExdate(
|
|
637
|
+
instanceDate: Long,
|
|
638
|
+
isAllDay: Boolean,
|
|
639
|
+
): String {
|
|
640
|
+
val utc = formatUntilUtc(instanceDate)
|
|
641
|
+
return if (isAllDay) utc.substringBefore("T") else utc
|
|
642
|
+
}
|
|
643
|
+
|
|
568
644
|
private fun rruleEndingBefore(
|
|
569
645
|
rrule: String,
|
|
570
646
|
instanceDateMs: Long,
|
|
@@ -615,80 +691,43 @@ class ImplementationHelper {
|
|
|
615
691
|
CalendarContract.Events.CONTENT_URI,
|
|
616
692
|
eventId,
|
|
617
693
|
)
|
|
618
|
-
|
|
619
694
|
val projection =
|
|
620
695
|
arrayOf(
|
|
621
696
|
CalendarContract.Events.DTSTART,
|
|
622
697
|
CalendarContract.Events.ORIGINAL_ID,
|
|
623
698
|
CalendarContract.Events.ORIGINAL_INSTANCE_TIME,
|
|
624
699
|
CalendarContract.Events.RRULE,
|
|
700
|
+
CalendarContract.Events.DTEND,
|
|
701
|
+
CalendarContract.Events.DURATION,
|
|
702
|
+
CalendarContract.Events.EXDATE,
|
|
703
|
+
CalendarContract.Events.EVENT_TIMEZONE,
|
|
704
|
+
CalendarContract.Events.ALL_DAY,
|
|
705
|
+
CalendarContract.Events._SYNC_ID,
|
|
625
706
|
)
|
|
626
|
-
|
|
627
|
-
cr
|
|
628
|
-
.
|
|
629
|
-
|
|
630
|
-
projection,
|
|
631
|
-
null,
|
|
632
|
-
null,
|
|
633
|
-
null,
|
|
634
|
-
)?.use { cursor ->
|
|
635
|
-
if (!cursor.moveToFirst()) {
|
|
636
|
-
return EventDeleteInfo(
|
|
637
|
-
dtStart = null,
|
|
638
|
-
originalId = null,
|
|
639
|
-
originalInstanceTime = null,
|
|
640
|
-
rrule = null,
|
|
641
|
-
)
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
val dtStartIndex = cursor.getColumnIndex(CalendarContract.Events.DTSTART)
|
|
645
|
-
val originalIdIndex = cursor.getColumnIndex(CalendarContract.Events.ORIGINAL_ID)
|
|
646
|
-
val originalInstanceTimeIndex =
|
|
647
|
-
cursor.getColumnIndex(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
|
|
648
|
-
val rruleIndex = cursor.getColumnIndex(CalendarContract.Events.RRULE)
|
|
649
|
-
|
|
650
|
-
val dtStart =
|
|
651
|
-
if (dtStartIndex >= 0 && !cursor.isNull(dtStartIndex)) {
|
|
652
|
-
cursor.getLong(dtStartIndex)
|
|
653
|
-
} else {
|
|
654
|
-
null
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
val originalId =
|
|
658
|
-
if (originalIdIndex >= 0 && !cursor.isNull(originalIdIndex)) {
|
|
659
|
-
cursor.getLong(originalIdIndex)
|
|
660
|
-
} else {
|
|
661
|
-
null
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
val originalInstanceTime =
|
|
665
|
-
if (originalInstanceTimeIndex >= 0 && !cursor.isNull(originalInstanceTimeIndex)) {
|
|
666
|
-
cursor.getLong(originalInstanceTimeIndex)
|
|
667
|
-
} else {
|
|
668
|
-
null
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
val rrule =
|
|
672
|
-
if (rruleIndex >= 0 && !cursor.isNull(rruleIndex)) {
|
|
673
|
-
cursor.getString(rruleIndex)
|
|
674
|
-
} else {
|
|
675
|
-
null
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
return EventDeleteInfo(
|
|
679
|
-
dtStart = dtStart,
|
|
680
|
-
originalId = originalId,
|
|
681
|
-
originalInstanceTime = originalInstanceTime,
|
|
682
|
-
rrule = rrule,
|
|
683
|
-
)
|
|
707
|
+
val empty = EventDeleteInfo(dtStart = null, originalId = null, originalInstanceTime = null, rrule = null)
|
|
708
|
+
return cr.query(uri, projection, null, null, null)?.use { cursor ->
|
|
709
|
+
if (!cursor.moveToFirst()) {
|
|
710
|
+
return@use empty
|
|
684
711
|
}
|
|
685
712
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
713
|
+
fun column(name: String): Int? = cursor.getColumnIndex(name).takeIf { it >= 0 && !cursor.isNull(it) }
|
|
714
|
+
|
|
715
|
+
fun long(name: String): Long? = column(name)?.let { cursor.getLong(it) }
|
|
716
|
+
|
|
717
|
+
fun string(name: String): String? = column(name)?.let { cursor.getString(it) }
|
|
718
|
+
EventDeleteInfo(
|
|
719
|
+
dtStart = long(CalendarContract.Events.DTSTART),
|
|
720
|
+
originalId = long(CalendarContract.Events.ORIGINAL_ID),
|
|
721
|
+
originalInstanceTime = long(CalendarContract.Events.ORIGINAL_INSTANCE_TIME),
|
|
722
|
+
rrule = string(CalendarContract.Events.RRULE),
|
|
723
|
+
dtEnd = long(CalendarContract.Events.DTEND),
|
|
724
|
+
duration = string(CalendarContract.Events.DURATION),
|
|
725
|
+
exdate = string(CalendarContract.Events.EXDATE),
|
|
726
|
+
timezone = string(CalendarContract.Events.EVENT_TIMEZONE),
|
|
727
|
+
isAllDay = long(CalendarContract.Events.ALL_DAY) == 1L,
|
|
728
|
+
syncId = string(CalendarContract.Events._SYNC_ID),
|
|
729
|
+
)
|
|
730
|
+
} ?: empty
|
|
692
731
|
}
|
|
693
732
|
|
|
694
733
|
fun getEventAlerts(
|
|
@@ -801,6 +840,21 @@ class ImplementationHelper {
|
|
|
801
840
|
}
|
|
802
841
|
}
|
|
803
842
|
|
|
843
|
+
fun durationToMillis(duration: String): Long {
|
|
844
|
+
val match =
|
|
845
|
+
Regex("^P(?:(\\d+)W)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?$").matchEntire(duration.trim())
|
|
846
|
+
?: return 0L
|
|
847
|
+
val (weeks, days, hours, minutes, seconds) = match.destructured
|
|
848
|
+
|
|
849
|
+
fun part(value: String) = value.toLongOrNull() ?: 0L
|
|
850
|
+
return (
|
|
851
|
+
(part(weeks) * 7 + part(days)) * 24 * 3600 +
|
|
852
|
+
part(hours) * 3600 +
|
|
853
|
+
part(minutes) * 60 +
|
|
854
|
+
part(seconds)
|
|
855
|
+
) * 1000
|
|
856
|
+
}
|
|
857
|
+
|
|
804
858
|
fun mapAttendeeRelationship(relationship: Int): String =
|
|
805
859
|
when (relationship) {
|
|
806
860
|
CalendarContract.Attendees.RELATIONSHIP_ATTENDEE -> "attendee"
|