@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
|
@@ -2,6 +2,7 @@ package dev.barooni.capacitor.calendar
|
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
4
|
import androidx.activity.result.ActivityResult
|
|
5
|
+
import com.getcapacitor.JSObject
|
|
5
6
|
import com.getcapacitor.Plugin
|
|
6
7
|
import com.getcapacitor.PluginCall
|
|
7
8
|
import com.getcapacitor.PluginMethod
|
|
@@ -20,6 +21,7 @@ import dev.barooni.capacitor.calendar.models.inputs.DeleteEventInput
|
|
|
20
21
|
import dev.barooni.capacitor.calendar.models.inputs.DeleteEventWithPromptInput
|
|
21
22
|
import dev.barooni.capacitor.calendar.models.inputs.DeleteEventsByIdInput
|
|
22
23
|
import dev.barooni.capacitor.calendar.models.inputs.GetDefaultCalendarInput
|
|
24
|
+
import dev.barooni.capacitor.calendar.models.inputs.GetEventByIdInput
|
|
23
25
|
import dev.barooni.capacitor.calendar.models.inputs.ListEventsInRangeInput
|
|
24
26
|
import dev.barooni.capacitor.calendar.models.inputs.ModifyCalendarInput
|
|
25
27
|
import dev.barooni.capacitor.calendar.models.inputs.ModifyEvent
|
|
@@ -27,6 +29,7 @@ import dev.barooni.capacitor.calendar.models.inputs.ModifyEventWithPromptInput
|
|
|
27
29
|
import dev.barooni.capacitor.calendar.models.inputs.OpenCalendarInput
|
|
28
30
|
import dev.barooni.capacitor.calendar.models.inputs.RequestAllPermissionsInput
|
|
29
31
|
import dev.barooni.capacitor.calendar.models.inputs.RequestPermissionInput
|
|
32
|
+
import dev.barooni.capacitor.calendar.models.inputs.StartListeningInput
|
|
30
33
|
import dev.barooni.capacitor.calendar.models.results.CreateEventWithPromptResult
|
|
31
34
|
import dev.barooni.capacitor.calendar.models.results.ModifyEventWithPromptResult
|
|
32
35
|
import dev.barooni.capacitor.calendar.models.results.RequestAllPermissionsResult
|
|
@@ -491,6 +494,58 @@ class CapacitorCalendarPlugin : Plugin() {
|
|
|
491
494
|
}
|
|
492
495
|
}
|
|
493
496
|
|
|
497
|
+
@PluginMethod
|
|
498
|
+
fun startListening(call: PluginCall) {
|
|
499
|
+
try {
|
|
500
|
+
declarationCheck.ensureManifestPermissions(Manifest.permission.READ_CALENDAR)
|
|
501
|
+
val input = StartListeningInput(call)
|
|
502
|
+
implementation.startListening(input)
|
|
503
|
+
resolveCall(call)
|
|
504
|
+
} catch (error: Exception) {
|
|
505
|
+
rejectCall(call, error)
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
@PluginMethod
|
|
510
|
+
fun stopListening(call: PluginCall) {
|
|
511
|
+
implementation.stopListening()
|
|
512
|
+
resolveCall(call)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
fun hasCalendarChangedListeners(): Boolean = hasListeners("calendarChanged")
|
|
516
|
+
|
|
517
|
+
@PluginMethod
|
|
518
|
+
override fun removeAllListeners(call: PluginCall) {
|
|
519
|
+
implementation.stopListening()
|
|
520
|
+
super.removeAllListeners(call)
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
fun emitCalendarChanged(payload: JSObject) {
|
|
524
|
+
notifyListeners("calendarChanged", payload)
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
override fun handleOnDestroy() {
|
|
528
|
+
implementation.stopListening()
|
|
529
|
+
super.handleOnDestroy()
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
@PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
|
|
533
|
+
fun getEventById(call: PluginCall) {
|
|
534
|
+
try {
|
|
535
|
+
declarationCheck.ensureManifestPermissions(Manifest.permission.READ_CALENDAR)
|
|
536
|
+
val input = GetEventByIdInput(call)
|
|
537
|
+
implementation.getEventById(input) { result, error ->
|
|
538
|
+
if (error != null) {
|
|
539
|
+
rejectCall(call, error)
|
|
540
|
+
return@getEventById
|
|
541
|
+
}
|
|
542
|
+
resolveCall(call, result)
|
|
543
|
+
}
|
|
544
|
+
} catch (error: Exception) {
|
|
545
|
+
rejectCall(call, error)
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
494
549
|
@PluginMethod
|
|
495
550
|
fun modifyCalendar(call: PluginCall) {
|
|
496
551
|
try {
|
|
@@ -45,6 +45,8 @@ sealed class PluginError(
|
|
|
45
45
|
|
|
46
46
|
data object InvalidEventId : PluginError("Invalid event ID.", "EB-CLDR-0001")
|
|
47
47
|
|
|
48
|
+
data object InvalidFrequency : PluginError("Invalid frequency.", "EB-CLDR-0001")
|
|
49
|
+
|
|
48
50
|
data object InvalidInvitees : PluginError("Invalid invitees. Array must contain only strings.", "EB-CLDR-0001")
|
|
49
51
|
|
|
50
52
|
data object InvalidScope : PluginError("Invalid scope.", "EB-CLDR-0001")
|
|
@@ -58,6 +60,8 @@ sealed class PluginError(
|
|
|
58
60
|
"EB-CLDR-0100",
|
|
59
61
|
)
|
|
60
62
|
|
|
63
|
+
data object MissingFrequency : PluginError("Frequency must be provided.", "EB-CLDR-0001")
|
|
64
|
+
|
|
61
65
|
data object MissingId : PluginError("Event ID must be provided.", "EB-CLDR-0001")
|
|
62
66
|
|
|
63
67
|
data object MissingScope : PluginError("Scope must be provided.", "EB-CLDR-0001")
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
package dev.barooni.capacitor.calendar.implementation
|
|
2
|
+
|
|
3
|
+
import android.content.ContentResolver
|
|
4
|
+
import android.database.ContentObserver
|
|
5
|
+
import android.provider.CalendarContract
|
|
6
|
+
import com.getcapacitor.JSArray
|
|
7
|
+
import com.getcapacitor.JSObject
|
|
8
|
+
import dev.barooni.capacitor.calendar.models.data.CalendarEvent
|
|
9
|
+
import dev.barooni.capacitor.calendar.models.results.toJSObject
|
|
10
|
+
import dev.barooni.capacitor.calendar.utils.ImplementationHelper
|
|
11
|
+
import java.util.concurrent.Executors
|
|
12
|
+
import java.util.concurrent.ScheduledExecutorService
|
|
13
|
+
import java.util.concurrent.ScheduledFuture
|
|
14
|
+
import java.util.concurrent.TimeUnit
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Watches the calendar provider. After each change it waits for the changes to settle,
|
|
18
|
+
* reads the watched window again and compares it with the last snapshot.
|
|
19
|
+
* Android does not say what changed, so the comparison finds it.
|
|
20
|
+
*/
|
|
21
|
+
class CalendarChangeObserver(
|
|
22
|
+
private val contentResolver: ContentResolver,
|
|
23
|
+
private val queryEvents: (from: Long, to: Long, calendarIds: List<Long>?) -> List<CalendarEvent>,
|
|
24
|
+
private val hasListeners: () -> Boolean,
|
|
25
|
+
private val emit: (JSObject) -> Unit,
|
|
26
|
+
) {
|
|
27
|
+
private data class Entry(
|
|
28
|
+
val id: String,
|
|
29
|
+
val fingerprint: Int,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
private var executor: ScheduledExecutorService? = null
|
|
33
|
+
private var pending: ScheduledFuture<*>? = null
|
|
34
|
+
private var contentObserver: ContentObserver? = null
|
|
35
|
+
private var from = 0L
|
|
36
|
+
private var to = 0L
|
|
37
|
+
private var calendarIds: List<Long>? = null
|
|
38
|
+
private var includeEvents = true
|
|
39
|
+
private var eventSnapshot: Map<String, Entry> = emptyMap()
|
|
40
|
+
private var calendarSnapshot: Map<String, Int> = emptyMap()
|
|
41
|
+
private var listenerSeen = false
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Stops a running watch, reads the baseline and starts to observe.
|
|
45
|
+
* Throws when the baseline cannot be read. Then nothing is observed.
|
|
46
|
+
*/
|
|
47
|
+
@Synchronized
|
|
48
|
+
fun start(
|
|
49
|
+
from: Long,
|
|
50
|
+
to: Long,
|
|
51
|
+
calendarIds: List<Long>?,
|
|
52
|
+
includeEvents: Boolean,
|
|
53
|
+
) {
|
|
54
|
+
stop()
|
|
55
|
+
this.from = from
|
|
56
|
+
this.to = to
|
|
57
|
+
this.calendarIds = calendarIds
|
|
58
|
+
this.includeEvents = includeEvents
|
|
59
|
+
eventSnapshot = toEntries(queryEvents(from, to, calendarIds))
|
|
60
|
+
calendarSnapshot = readCalendars()
|
|
61
|
+
executor = Executors.newSingleThreadScheduledExecutor()
|
|
62
|
+
val observer =
|
|
63
|
+
// No handler: onChange runs on a binder thread, so a running check never blocks the main thread.
|
|
64
|
+
object : ContentObserver(null) {
|
|
65
|
+
override fun onChange(selfChange: Boolean) {
|
|
66
|
+
scheduleCheck()
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
contentResolver.registerContentObserver(CalendarContract.Events.CONTENT_URI, true, observer)
|
|
70
|
+
contentResolver.registerContentObserver(CalendarContract.Calendars.CONTENT_URI, true, observer)
|
|
71
|
+
contentObserver = observer
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@Synchronized
|
|
75
|
+
fun stop() {
|
|
76
|
+
contentObserver?.let { contentResolver.unregisterContentObserver(it) }
|
|
77
|
+
contentObserver = null
|
|
78
|
+
pending?.cancel(false)
|
|
79
|
+
pending = null
|
|
80
|
+
executor?.shutdownNow()
|
|
81
|
+
executor = null
|
|
82
|
+
eventSnapshot = emptyMap()
|
|
83
|
+
calendarSnapshot = emptyMap()
|
|
84
|
+
listenerSeen = false
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Synchronized
|
|
88
|
+
private fun scheduleCheck() {
|
|
89
|
+
val currentExecutor = executor ?: return
|
|
90
|
+
pending?.cancel(false)
|
|
91
|
+
pending = currentExecutor.schedule({ check() }, DEBOUNCE_MS, TimeUnit.MILLISECONDS)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@Synchronized
|
|
95
|
+
private fun check() {
|
|
96
|
+
if (executor == null) {
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
// After `removeAllListeners` nobody listens. Then the watch ends by itself.
|
|
100
|
+
if (!hasListeners()) {
|
|
101
|
+
if (listenerSeen) {
|
|
102
|
+
stop()
|
|
103
|
+
}
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
listenerSeen = true
|
|
107
|
+
try {
|
|
108
|
+
val freshEvents = queryEvents(from, to, calendarIds)
|
|
109
|
+
val freshEntries = toEntries(freshEvents)
|
|
110
|
+
val freshCalendars = readCalendars()
|
|
111
|
+
|
|
112
|
+
val oldCounts = eventSnapshot.values.groupingBy { it.id }.eachCount()
|
|
113
|
+
val freshCounts = freshEntries.values.groupingBy { it.id }.eachCount()
|
|
114
|
+
// A new start time for a known id is a moved event or occurrence, not a new event.
|
|
115
|
+
val created = freshEvents.filter { key(it) !in eventSnapshot && it.id !in oldCounts }
|
|
116
|
+
val updated =
|
|
117
|
+
freshEvents.filter { event ->
|
|
118
|
+
val old = eventSnapshot[key(event)]
|
|
119
|
+
if (old == null) {
|
|
120
|
+
event.id in oldCounts
|
|
121
|
+
} else {
|
|
122
|
+
old.fingerprint != freshEntries[key(event)]?.fingerprint
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
val deletedIds =
|
|
126
|
+
eventSnapshot
|
|
127
|
+
.filterKeys { it !in freshEntries }
|
|
128
|
+
.values
|
|
129
|
+
.map { it.id }
|
|
130
|
+
.filter { it !in freshCounts }
|
|
131
|
+
.distinct()
|
|
132
|
+
// An occurrence left the window while its series stays. The lists cannot express it.
|
|
133
|
+
val occurrenceRemoved = freshCounts.any { (id, count) -> count < (oldCounts[id] ?: 0) }
|
|
134
|
+
val calendarsChanged = freshCalendars != calendarSnapshot
|
|
135
|
+
|
|
136
|
+
eventSnapshot = freshEntries
|
|
137
|
+
calendarSnapshot = freshCalendars
|
|
138
|
+
|
|
139
|
+
if (created.isEmpty() && updated.isEmpty() && deletedIds.isEmpty() && !occurrenceRemoved && !calendarsChanged) {
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
val payload = JSObject()
|
|
143
|
+
if (includeEvents) {
|
|
144
|
+
if (created.isNotEmpty()) {
|
|
145
|
+
payload.put("created", toJSArray(created))
|
|
146
|
+
}
|
|
147
|
+
if (updated.isNotEmpty()) {
|
|
148
|
+
payload.put("updated", toJSArray(updated))
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (deletedIds.isNotEmpty()) {
|
|
152
|
+
payload.put("deletedIds", JSArray(deletedIds))
|
|
153
|
+
}
|
|
154
|
+
if (calendarsChanged) {
|
|
155
|
+
payload.put("calendarsChanged", true)
|
|
156
|
+
}
|
|
157
|
+
payload.put("precise", !occurrenceRemoved && (includeEvents || (created.isEmpty() && updated.isEmpty())))
|
|
158
|
+
emit(payload)
|
|
159
|
+
} catch (error: Exception) {
|
|
160
|
+
// The snapshot stays as it is. The next check compares with it again.
|
|
161
|
+
emit(JSObject().put("precise", false))
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private fun readCalendars(): Map<String, Int> = ImplementationHelper.listCalendars(contentResolver).associate { it.id to it.hashCode() }
|
|
166
|
+
|
|
167
|
+
private fun toEntries(events: List<CalendarEvent>): Map<String, Entry> = events.associate { key(it) to Entry(it.id, it.hashCode()) }
|
|
168
|
+
|
|
169
|
+
// One event id has one instance for each occurrence of a series.
|
|
170
|
+
private fun key(event: CalendarEvent): String = "${event.id}|${event.startDate}"
|
|
171
|
+
|
|
172
|
+
private fun toJSArray(events: List<CalendarEvent>): JSArray {
|
|
173
|
+
val array = JSArray()
|
|
174
|
+
events.forEach { array.put(it.toJSObject()) }
|
|
175
|
+
return array
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private companion object {
|
|
179
|
+
const val DEBOUNCE_MS = 400L
|
|
180
|
+
}
|
|
181
|
+
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt
CHANGED
|
@@ -21,6 +21,7 @@ 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
23
|
import dev.barooni.capacitor.calendar.models.inputs.GetDefaultCalendarInput
|
|
24
|
+
import dev.barooni.capacitor.calendar.models.inputs.GetEventByIdInput
|
|
24
25
|
import dev.barooni.capacitor.calendar.models.inputs.ListEventsInRangeInput
|
|
25
26
|
import dev.barooni.capacitor.calendar.models.inputs.ModifyCalendarInput
|
|
26
27
|
import dev.barooni.capacitor.calendar.models.inputs.ModifyEvent
|
|
@@ -28,6 +29,7 @@ import dev.barooni.capacitor.calendar.models.inputs.ModifyEventWithPromptInput
|
|
|
28
29
|
import dev.barooni.capacitor.calendar.models.inputs.OpenCalendarInput
|
|
29
30
|
import dev.barooni.capacitor.calendar.models.inputs.RequestAllPermissionsInput
|
|
30
31
|
import dev.barooni.capacitor.calendar.models.inputs.RequestPermissionInput
|
|
32
|
+
import dev.barooni.capacitor.calendar.models.inputs.StartListeningInput
|
|
31
33
|
import dev.barooni.capacitor.calendar.models.results.CheckAllPermissionsResult
|
|
32
34
|
import dev.barooni.capacitor.calendar.models.results.CheckPermissionResult
|
|
33
35
|
import dev.barooni.capacitor.calendar.models.results.CreateCalendarResult
|
|
@@ -35,6 +37,7 @@ import dev.barooni.capacitor.calendar.models.results.CreateEventResult
|
|
|
35
37
|
import dev.barooni.capacitor.calendar.models.results.DeleteEventWithPromptResult
|
|
36
38
|
import dev.barooni.capacitor.calendar.models.results.DeleteEventsByIdResult
|
|
37
39
|
import dev.barooni.capacitor.calendar.models.results.GetDefaultCalendarResult
|
|
40
|
+
import dev.barooni.capacitor.calendar.models.results.GetEventByIdResult
|
|
38
41
|
import dev.barooni.capacitor.calendar.models.results.ListCalendarsResult
|
|
39
42
|
import dev.barooni.capacitor.calendar.models.results.ListEventsInRangeResult
|
|
40
43
|
import dev.barooni.capacitor.calendar.models.templates.PluginCompletion
|
|
@@ -95,6 +98,16 @@ class CapacitorCalendar(
|
|
|
95
98
|
Pair(input.startDate, input.endDate)
|
|
96
99
|
}
|
|
97
100
|
val timezoneId = if (isAllDay) "UTC" else input.timezoneId
|
|
101
|
+
// The provider needs DURATION and no DTEND on a repeating event.
|
|
102
|
+
// Without DURATION it cannot add exceptions, so deleting or editing one occurrence fails.
|
|
103
|
+
val isRecurring = input.recurrence != null
|
|
104
|
+
val duration =
|
|
105
|
+
input.duration
|
|
106
|
+
?: if (isRecurring && startDate != null && endDate != null) {
|
|
107
|
+
ImplementationHelper.buildDurationFromBeginEnd(startDate, endDate, isAllDay)
|
|
108
|
+
} else {
|
|
109
|
+
null
|
|
110
|
+
}
|
|
98
111
|
|
|
99
112
|
val values =
|
|
100
113
|
ContentValues().apply {
|
|
@@ -104,11 +117,13 @@ class CapacitorCalendar(
|
|
|
104
117
|
input.isAllDay?.let { put(CalendarContract.Events.ALL_DAY, it) }
|
|
105
118
|
input.location?.let { put(CalendarContract.Events.EVENT_LOCATION, it) }
|
|
106
119
|
startDate?.let { put(CalendarContract.Events.DTSTART, it) }
|
|
107
|
-
|
|
120
|
+
if (!isRecurring || duration == null) {
|
|
121
|
+
endDate?.let { put(CalendarContract.Events.DTEND, it) }
|
|
122
|
+
}
|
|
108
123
|
input.description?.let { put(CalendarContract.Events.DESCRIPTION, it) }
|
|
109
124
|
input.availability?.let { put(CalendarContract.Events.AVAILABILITY, it) }
|
|
110
125
|
input.organizer?.let { put(CalendarContract.Events.ORGANIZER, it) }
|
|
111
|
-
|
|
126
|
+
duration?.let { put(CalendarContract.Events.DURATION, it) }
|
|
112
127
|
input.color?.let { put(CalendarContract.Events.EVENT_COLOR, it) }
|
|
113
128
|
input.recurrence?.let { put(CalendarContract.Events.RRULE, it.toRRule()) }
|
|
114
129
|
}
|
|
@@ -121,6 +136,7 @@ class CapacitorCalendar(
|
|
|
121
136
|
|
|
122
137
|
fun modifyEvent(input: ModifyEvent) {
|
|
123
138
|
val cr = plugin.context.contentResolver
|
|
139
|
+
ImplementationHelper.ensureEventExists(cr, input.id)
|
|
124
140
|
val updatingDates = input.startDate != null || input.endDate != null
|
|
125
141
|
val settingAllDay = input.isAllDay == 1
|
|
126
142
|
// Normalize when setting all-day, or when editing dates on an existing all-day event
|
|
@@ -355,7 +371,45 @@ class CapacitorCalendar(
|
|
|
355
371
|
dialog.show()
|
|
356
372
|
}
|
|
357
373
|
|
|
358
|
-
|
|
374
|
+
private val calendarChangeObserver: CalendarChangeObserver by lazy {
|
|
375
|
+
CalendarChangeObserver(
|
|
376
|
+
plugin.context.contentResolver,
|
|
377
|
+
::queryEventsInRange,
|
|
378
|
+
plugin::hasCalendarChangedListeners,
|
|
379
|
+
plugin::emitCalendarChanged,
|
|
380
|
+
)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
fun startListening(input: StartListeningInput) {
|
|
384
|
+
input.calendarIds?.forEach { calendarId ->
|
|
385
|
+
val exists =
|
|
386
|
+
plugin.context.contentResolver
|
|
387
|
+
.query(
|
|
388
|
+
ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, calendarId),
|
|
389
|
+
arrayOf(CalendarContract.Calendars._ID),
|
|
390
|
+
null,
|
|
391
|
+
null,
|
|
392
|
+
null,
|
|
393
|
+
)?.use { it.moveToFirst() } ?: false
|
|
394
|
+
if (!exists) {
|
|
395
|
+
throw PluginError.CalendarNotFound
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
calendarChangeObserver.start(input.from, input.to, input.calendarIds, input.includeEvents)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
fun stopListening() {
|
|
402
|
+
calendarChangeObserver.stop()
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
fun listEventsInRange(input: ListEventsInRangeInput): ListEventsInRangeResult =
|
|
406
|
+
ListEventsInRangeResult(queryEventsInRange(input.from, input.to, input.calendarIds))
|
|
407
|
+
|
|
408
|
+
fun queryEventsInRange(
|
|
409
|
+
from: Long,
|
|
410
|
+
to: Long,
|
|
411
|
+
calendarIds: List<Long>?,
|
|
412
|
+
): List<CalendarEvent> {
|
|
359
413
|
val cr = plugin.context.contentResolver
|
|
360
414
|
val events = mutableListOf<CalendarEvent>()
|
|
361
415
|
// Cache master Events.DTSTART by master id for this call only.
|
|
@@ -388,8 +442,8 @@ class CapacitorCalendar(
|
|
|
388
442
|
}
|
|
389
443
|
|
|
390
444
|
val builder: Uri.Builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
|
391
|
-
ContentUris.appendId(builder,
|
|
392
|
-
ContentUris.appendId(builder,
|
|
445
|
+
ContentUris.appendId(builder, from)
|
|
446
|
+
ContentUris.appendId(builder, to)
|
|
393
447
|
val uri: Uri = builder.build()
|
|
394
448
|
|
|
395
449
|
val projection =
|
|
@@ -413,10 +467,30 @@ class CapacitorCalendar(
|
|
|
413
467
|
CalendarContract.Instances.DTSTART,
|
|
414
468
|
)
|
|
415
469
|
|
|
470
|
+
calendarIds?.forEach { calendarId ->
|
|
471
|
+
val exists =
|
|
472
|
+
cr
|
|
473
|
+
.query(
|
|
474
|
+
ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, calendarId),
|
|
475
|
+
arrayOf(CalendarContract.Calendars._ID),
|
|
476
|
+
null,
|
|
477
|
+
null,
|
|
478
|
+
null,
|
|
479
|
+
)?.use { it.moveToFirst() } ?: false
|
|
480
|
+
if (!exists) {
|
|
481
|
+
throw PluginError.CalendarNotFound
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
val calendarFilter =
|
|
485
|
+
calendarIds
|
|
486
|
+
?.let { " AND (${CalendarContract.Instances.CALENDAR_ID} IN (${it.joinToString(",") { "?" }}))" }
|
|
487
|
+
?: ""
|
|
416
488
|
val selection =
|
|
417
489
|
"(${CalendarContract.Instances.BEGIN} < ?) AND " +
|
|
418
|
-
"(${CalendarContract.Instances.END} > ?)"
|
|
419
|
-
val selectionArgs =
|
|
490
|
+
"(${CalendarContract.Instances.END} > ?)" + calendarFilter
|
|
491
|
+
val selectionArgs =
|
|
492
|
+
arrayOf(to.toString(), from.toString()) +
|
|
493
|
+
(calendarIds?.map { it.toString() } ?: emptyList())
|
|
420
494
|
|
|
421
495
|
val sortOrder = "${CalendarContract.Instances.BEGIN} ASC"
|
|
422
496
|
|
|
@@ -568,7 +642,109 @@ class CapacitorCalendar(
|
|
|
568
642
|
}
|
|
569
643
|
}
|
|
570
644
|
cursor?.close()
|
|
571
|
-
return
|
|
645
|
+
return events
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
fun getEventById(
|
|
649
|
+
input: GetEventByIdInput,
|
|
650
|
+
completion: PluginCompletion<GetEventByIdResult>,
|
|
651
|
+
) {
|
|
652
|
+
try {
|
|
653
|
+
completion(getEventByIdResult(input), null)
|
|
654
|
+
} catch (error: Exception) {
|
|
655
|
+
completion(null, error)
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
private fun getEventByIdResult(input: GetEventByIdInput): GetEventByIdResult {
|
|
660
|
+
val cr = plugin.context.contentResolver
|
|
661
|
+
val eventUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, input.id)
|
|
662
|
+
val projection =
|
|
663
|
+
arrayOf(
|
|
664
|
+
CalendarContract.Events.TITLE,
|
|
665
|
+
CalendarContract.Events.CALENDAR_ID,
|
|
666
|
+
CalendarContract.Events.EVENT_LOCATION,
|
|
667
|
+
CalendarContract.Events.DTSTART,
|
|
668
|
+
CalendarContract.Events.DTEND,
|
|
669
|
+
CalendarContract.Events.ALL_DAY,
|
|
670
|
+
CalendarContract.Events.DESCRIPTION,
|
|
671
|
+
CalendarContract.Events.AVAILABILITY,
|
|
672
|
+
CalendarContract.Events.ORGANIZER,
|
|
673
|
+
CalendarContract.Events.EVENT_COLOR,
|
|
674
|
+
CalendarContract.Events.EVENT_TIMEZONE,
|
|
675
|
+
CalendarContract.Events.STATUS,
|
|
676
|
+
CalendarContract.Events.DURATION,
|
|
677
|
+
CalendarContract.Events.RRULE,
|
|
678
|
+
CalendarContract.Events.ORIGINAL_ID,
|
|
679
|
+
CalendarContract.Events.DELETED,
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
val event =
|
|
683
|
+
cr.query(eventUri, projection, null, null, null)?.use { cursor ->
|
|
684
|
+
if (!cursor.moveToFirst()) {
|
|
685
|
+
return@use null
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
fun column(name: String): Int? = cursor.getColumnIndex(name).takeIf { it != -1 && !cursor.isNull(it) }
|
|
689
|
+
|
|
690
|
+
if (column(CalendarContract.Events.DELETED)?.let { cursor.getInt(it) == 1 } == true) {
|
|
691
|
+
return@use null
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
val startDate = column(CalendarContract.Events.DTSTART)?.let { cursor.getLong(it) } ?: 0L
|
|
695
|
+
val isAllDay = column(CalendarContract.Events.ALL_DAY)?.let { cursor.getInt(it) == 1 } ?: false
|
|
696
|
+
val rrule = column(CalendarContract.Events.RRULE)?.let { cursor.getString(it) }
|
|
697
|
+
val originalId = column(CalendarContract.Events.ORIGINAL_ID)?.let { cursor.getLong(it) }?.takeIf { it != 0L }
|
|
698
|
+
val storedDuration = column(CalendarContract.Events.DURATION)?.let { cursor.getString(it) }
|
|
699
|
+
// Recurring masters have DURATION and no DTEND.
|
|
700
|
+
val endDate =
|
|
701
|
+
column(CalendarContract.Events.DTEND)?.let { cursor.getLong(it) }
|
|
702
|
+
?: (startDate + (storedDuration?.let { ImplementationHelper.durationToMillis(it) } ?: 0L))
|
|
703
|
+
val duration = storedDuration ?: ImplementationHelper.buildDurationFromBeginEnd(startDate, endDate, isAllDay)
|
|
704
|
+
val isPartOfSeries = !rrule.isNullOrEmpty() || originalId != null
|
|
705
|
+
val seriesStartDate =
|
|
706
|
+
originalId?.let { masterId ->
|
|
707
|
+
cr
|
|
708
|
+
.query(
|
|
709
|
+
ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, masterId),
|
|
710
|
+
arrayOf(CalendarContract.Events.DTSTART),
|
|
711
|
+
null,
|
|
712
|
+
null,
|
|
713
|
+
null,
|
|
714
|
+
)?.use { masterCursor ->
|
|
715
|
+
if (masterCursor.moveToFirst() && !masterCursor.isNull(0)) masterCursor.getLong(0) else null
|
|
716
|
+
}
|
|
717
|
+
} ?: startDate
|
|
718
|
+
|
|
719
|
+
CalendarEvent(
|
|
720
|
+
input.id.toString(),
|
|
721
|
+
(originalId ?: input.id).toString(),
|
|
722
|
+
column(CalendarContract.Events.TITLE)?.let { cursor.getString(it) } ?: "",
|
|
723
|
+
column(CalendarContract.Events.CALENDAR_ID)?.let { cursor.getLong(it).toString() },
|
|
724
|
+
null,
|
|
725
|
+
column(CalendarContract.Events.EVENT_LOCATION)?.let { cursor.getString(it) },
|
|
726
|
+
startDate,
|
|
727
|
+
seriesStartDate,
|
|
728
|
+
endDate,
|
|
729
|
+
isAllDay,
|
|
730
|
+
ImplementationHelper.getEventAlerts(cr, input.id),
|
|
731
|
+
null,
|
|
732
|
+
column(CalendarContract.Events.DESCRIPTION)?.let { cursor.getString(it) },
|
|
733
|
+
column(CalendarContract.Events.AVAILABILITY)?.let { cursor.getInt(it) },
|
|
734
|
+
column(CalendarContract.Events.ORGANIZER)?.let { cursor.getString(it) },
|
|
735
|
+
column(CalendarContract.Events.EVENT_COLOR)?.let { ImplementationHelper.intToHexColor(cursor.getInt(it)) },
|
|
736
|
+
duration,
|
|
737
|
+
null,
|
|
738
|
+
isPartOfSeries,
|
|
739
|
+
null,
|
|
740
|
+
column(CalendarContract.Events.STATUS)?.let { ImplementationHelper.mapEventStatus(cursor.getInt(it)) },
|
|
741
|
+
null,
|
|
742
|
+
null,
|
|
743
|
+
ImplementationHelper.getEventAttendees(cr, input.id),
|
|
744
|
+
column(CalendarContract.Events.EVENT_TIMEZONE)?.let { cursor.getString(it) },
|
|
745
|
+
)
|
|
746
|
+
}
|
|
747
|
+
return GetEventByIdResult(event)
|
|
572
748
|
}
|
|
573
749
|
|
|
574
750
|
fun modifyCalendar(input: ModifyCalendarInput) {
|
|
@@ -5,4 +5,10 @@ data class EventDeleteInfo(
|
|
|
5
5
|
val originalId: Long?,
|
|
6
6
|
val originalInstanceTime: Long?,
|
|
7
7
|
val rrule: String?,
|
|
8
|
+
val dtEnd: Long? = null,
|
|
9
|
+
val duration: String? = null,
|
|
10
|
+
val exdate: String? = null,
|
|
11
|
+
val timezone: String? = null,
|
|
12
|
+
val isAllDay: Boolean = false,
|
|
13
|
+
val syncId: String? = null,
|
|
8
14
|
)
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventRecurrenceRule.kt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package dev.barooni.capacitor.calendar.models.data
|
|
2
2
|
|
|
3
3
|
import com.getcapacitor.JSObject
|
|
4
|
+
import dev.barooni.capacitor.calendar.PluginError
|
|
4
5
|
import org.json.JSONArray
|
|
5
6
|
import org.json.JSONException
|
|
6
7
|
import java.util.Calendar
|
|
@@ -45,8 +46,8 @@ data class EventRecurrenceRule(
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
companion object {
|
|
48
|
-
fun parseRecurrence(obj: JSObject): EventRecurrenceRule
|
|
49
|
-
val frequencyString = obj.getString("frequency") ?:
|
|
49
|
+
fun parseRecurrence(obj: JSObject): EventRecurrenceRule {
|
|
50
|
+
val frequencyString = obj.getString("frequency") ?: throw PluginError.MissingFrequency
|
|
50
51
|
val frequency =
|
|
51
52
|
try {
|
|
52
53
|
Frequency.valueOf(
|
|
@@ -55,7 +56,7 @@ data class EventRecurrenceRule(
|
|
|
55
56
|
.replaceFirstChar { it.uppercase() },
|
|
56
57
|
)
|
|
57
58
|
} catch (_: IllegalArgumentException) {
|
|
58
|
-
|
|
59
|
+
throw PluginError.InvalidFrequency
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
val interval = (obj.getInteger("interval") ?: 1).coerceAtLeast(1)
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetEventByIdInput.kt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package dev.barooni.capacitor.calendar.models.inputs
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.PluginCall
|
|
4
|
+
import dev.barooni.capacitor.calendar.PluginError
|
|
5
|
+
|
|
6
|
+
data class GetEventByIdInput(
|
|
7
|
+
private val call: PluginCall,
|
|
8
|
+
) {
|
|
9
|
+
val id: Long =
|
|
10
|
+
call.getString("id")?.let { idString ->
|
|
11
|
+
idString.toLongOrNull() ?: throw PluginError.InvalidEventId
|
|
12
|
+
} ?: throw PluginError.MissingId
|
|
13
|
+
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ListEventsInRangeInput.kt
CHANGED
|
@@ -11,4 +11,9 @@ data class ListEventsInRangeInput(
|
|
|
11
11
|
call.getLong("from")?.let { ImplementationHelper.getCalendarFromTimestamp(it).timeInMillis } ?: throw PluginError.FromDateMissing
|
|
12
12
|
val to: Long =
|
|
13
13
|
call.getLong("to")?.let { ImplementationHelper.getCalendarFromTimestamp(it).timeInMillis } ?: throw PluginError.ToDateMissing
|
|
14
|
+
val calendarIds: List<Long>? =
|
|
15
|
+
call
|
|
16
|
+
.getArray("calendarIds")
|
|
17
|
+
?.let { ImplementationHelper.jsArrayToLongArray(it, PluginError.InvalidCalendarId) }
|
|
18
|
+
?.takeIf { it.isNotEmpty() }
|
|
14
19
|
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/StartListeningInput.kt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package dev.barooni.capacitor.calendar.models.inputs
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.PluginCall
|
|
4
|
+
import dev.barooni.capacitor.calendar.PluginError
|
|
5
|
+
import dev.barooni.capacitor.calendar.utils.ImplementationHelper
|
|
6
|
+
|
|
7
|
+
data class StartListeningInput(
|
|
8
|
+
private var call: PluginCall,
|
|
9
|
+
) {
|
|
10
|
+
val from: Long =
|
|
11
|
+
call.getLong("from")?.let { ImplementationHelper.getCalendarFromTimestamp(it).timeInMillis } ?: throw PluginError.FromDateMissing
|
|
12
|
+
val to: Long =
|
|
13
|
+
call.getLong("to")?.let { ImplementationHelper.getCalendarFromTimestamp(it).timeInMillis } ?: throw PluginError.ToDateMissing
|
|
14
|
+
val calendarIds: List<Long>? =
|
|
15
|
+
call
|
|
16
|
+
.getArray("calendarIds")
|
|
17
|
+
?.let { ImplementationHelper.jsArrayToLongArray(it, PluginError.InvalidCalendarId) }
|
|
18
|
+
?.takeIf { it.isNotEmpty() }
|
|
19
|
+
val includeEvents: Boolean = call.getBoolean("includeEvents", true) ?: true
|
|
20
|
+
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/GetEventByIdResult.kt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package dev.barooni.capacitor.calendar.models.results
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject
|
|
4
|
+
import dev.barooni.capacitor.calendar.models.data.CalendarEvent
|
|
5
|
+
import dev.barooni.capacitor.calendar.models.templates.JSResult
|
|
6
|
+
|
|
7
|
+
data class GetEventByIdResult(
|
|
8
|
+
private val event: CalendarEvent?,
|
|
9
|
+
) : JSResult {
|
|
10
|
+
override fun toJSON(): JSObject {
|
|
11
|
+
val result = JSObject()
|
|
12
|
+
result.put("event", event?.toJSObject() ?: JSObject.NULL)
|
|
13
|
+
return result
|
|
14
|
+
}
|
|
15
|
+
}
|