@ebarooni/capacitor-calendar 8.3.0 → 8.5.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 +225 -97
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +42 -7
- package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +31 -21
- package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +59 -15
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CheckPermissionInput.kt +0 -4
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CreateCalendarInput.kt +3 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteCalendarInput.kt +4 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/GetDefaultCalendarInput.kt +9 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ModifyCalendarInput.kt +10 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/RequestPermissionInput.kt +3 -5
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/CheckAllPermissionsResult.kt +3 -2
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/RequestAllPermissionsResult.kt +1 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/models/templates/PluginCompletion.kt +8 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +68 -31
- package/dist/docs.json +562 -70
- package/dist/esm/index.d.ts +12 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/enums/calendar-permission-scope.d.ts +8 -0
- package/dist/esm/schemas/enums/calendar-permission-scope.js +8 -0
- package/dist/esm/schemas/enums/calendar-permission-scope.js.map +1 -1
- package/dist/esm/schemas/interfaces/calendar-source.d.ts +3 -0
- package/dist/esm/schemas/interfaces/calendar-source.js.map +1 -1
- package/dist/esm/schemas/interfaces/calendar.d.ts +12 -2
- package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
- package/dist/esm/schemas/interfaces/check-permission-options.d.ts +19 -0
- package/dist/esm/schemas/interfaces/check-permission-options.js +2 -0
- package/dist/esm/schemas/interfaces/check-permission-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-calendar-options.d.ts +16 -5
- package/dist/esm/schemas/interfaces/create-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-calendar-result.d.ts +12 -0
- package/dist/esm/schemas/interfaces/create-calendar-result.js +2 -0
- package/dist/esm/schemas/interfaces/create-calendar-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-event-options.d.ts +22 -13
- package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-event-result.d.ts +23 -0
- package/dist/esm/schemas/interfaces/create-event-result.js +2 -0
- package/dist/esm/schemas/interfaces/create-event-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.d.ts +14 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.js +2 -0
- package/dist/esm/schemas/interfaces/create-event-with-prompt-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/delete-calendar-options.d.ts +1 -0
- package/dist/esm/schemas/interfaces/delete-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js +2 -0
- package/dist/esm/schemas/interfaces/fetch-all-calendar-sources-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/get-default-calendar-options.d.ts +13 -0
- package/dist/esm/schemas/interfaces/get-default-calendar-options.js +2 -0
- package/dist/esm/schemas/interfaces/get-default-calendar-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/list-calendars-result.d.ts +13 -0
- package/dist/esm/schemas/interfaces/list-calendars-result.js +2 -0
- package/dist/esm/schemas/interfaces/list-calendars-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/list-events-in-range-options.d.ts +7 -2
- package/dist/esm/schemas/interfaces/list-events-in-range-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/modify-calendar-options.d.ts +8 -1
- package/dist/esm/schemas/interfaces/modify-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +5 -1
- package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
- package/dist/esm/schemas/interfaces/request-permission-options.d.ts +16 -0
- package/dist/esm/schemas/interfaces/request-permission-options.js +2 -0
- package/dist/esm/schemas/interfaces/request-permission-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.d.ts +14 -0
- package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js +2 -0
- package/dist/esm/schemas/interfaces/select-calendars-with-prompt-result.js.map +1 -0
- package/dist/esm/sub-definitions/calendar-access.d.ts +22 -10
- package/dist/esm/sub-definitions/calendar-access.js.map +1 -1
- package/dist/esm/sub-definitions/calendar-operations.d.ts +61 -14
- package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
- package/dist/esm/sub-definitions/event-operations.d.ts +35 -9
- package/dist/esm/sub-definitions/event-operations.js.map +1 -1
- package/dist/esm/sub-definitions/reminders-access.d.ts +4 -0
- package/dist/esm/sub-definitions/reminders-access.js.map +1 -1
- package/dist/esm/web/download-ics-file.d.ts +18 -0
- package/dist/esm/web/download-ics-file.js +33 -0
- package/dist/esm/web/download-ics-file.js.map +1 -0
- package/dist/esm/web/ics.d.ts +21 -0
- package/dist/esm/web/ics.js +252 -0
- package/dist/esm/web/ics.js.map +1 -0
- package/dist/esm/web.d.ts +19 -27
- package/dist/esm/web.js +14 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +306 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +306 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +19 -16
- package/ios/Plugin/Implementation/CapacitorCalendar.swift +64 -34
- package/ios/Plugin/Models/Inputs/CreateCalendarInput.swift +4 -5
- package/ios/Plugin/Models/Inputs/DeleteCalendarInput.swift +1 -1
- package/ios/Plugin/Models/Inputs/GetDefaultCalendarInput.swift +13 -0
- package/ios/Plugin/Models/Inputs/ModifyCalendarInput.swift +4 -1
- package/ios/Plugin/PluginError.swift +68 -56
- package/ios/Plugin/Utils/ImplementationHelper.swift +15 -12
- 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
|
-
|
|
291
|
-
|
|
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
|
|
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
|
|
311
|
-
|
|
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
|
|
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,51 +3,61 @@ package dev.barooni.capacitor.calendar
|
|
|
3
3
|
sealed class PluginError(
|
|
4
4
|
localizedDescription: String,
|
|
5
5
|
) : Exception(localizedDescription) {
|
|
6
|
-
data object
|
|
6
|
+
data object AccountNameMissing : PluginError("Account name must be provided.")
|
|
7
7
|
|
|
8
|
-
data object
|
|
8
|
+
data object AttendeeEmailMissing : PluginError("Attendee email must be provided.")
|
|
9
9
|
|
|
10
|
-
data object
|
|
10
|
+
data object CalendarIdMissing : PluginError("Calendar ID must be provided.")
|
|
11
11
|
|
|
12
|
-
data object
|
|
12
|
+
data object CalendarNotFound : PluginError("Calendar not found.")
|
|
13
13
|
|
|
14
|
-
data object
|
|
14
|
+
data object ColorMissing : PluginError("Color must be provided.")
|
|
15
|
+
|
|
16
|
+
data class CustomError(
|
|
17
|
+
val details: String,
|
|
18
|
+
) : PluginError(details)
|
|
19
|
+
|
|
20
|
+
data object FailedToDelete : PluginError("Failed to delete.")
|
|
21
|
+
|
|
22
|
+
data object FailedToModify : PluginError("Failed to modify.")
|
|
23
|
+
|
|
24
|
+
data object FailedToRetrieveCalendarId : PluginError("Failed to retrieve calendar ID.")
|
|
25
|
+
|
|
26
|
+
data object FailedToRetrieveEventId : PluginError("Failed to retrieve event ID.")
|
|
27
|
+
|
|
28
|
+
data object FromDateMissing : PluginError("From date must be provided.")
|
|
15
29
|
|
|
16
30
|
data object InstanceDateMissing : PluginError(
|
|
17
31
|
"Instance date must be provided for this span on recurring events.",
|
|
18
32
|
)
|
|
19
33
|
|
|
20
|
-
data object
|
|
34
|
+
data object InvalidCalendarId : PluginError("Invalid calendar ID.")
|
|
21
35
|
|
|
22
|
-
data object
|
|
36
|
+
data object InvalidColor : PluginError("Invalid color format.")
|
|
23
37
|
|
|
24
|
-
data object
|
|
38
|
+
data object InvalidInvitees : PluginError("Invalid invitees. Array must contain only strings.")
|
|
25
39
|
|
|
26
|
-
data object
|
|
40
|
+
data object InvalidScope : PluginError("Invalid scope.")
|
|
27
41
|
|
|
28
|
-
data object
|
|
42
|
+
data object MessageMissing : PluginError("Message must be provided.")
|
|
29
43
|
|
|
30
|
-
data object
|
|
44
|
+
data object MissingId : PluginError("Event ID must be provided.")
|
|
31
45
|
|
|
32
|
-
data object
|
|
46
|
+
data object MissingScope : PluginError("Scope must be provided.")
|
|
33
47
|
|
|
34
|
-
data object
|
|
48
|
+
data object NoCalendarsAvailable : PluginError("No calendars available.")
|
|
35
49
|
|
|
36
|
-
data object
|
|
50
|
+
data object NoFieldsToModify : PluginError("At least one of title or color must be provided.")
|
|
37
51
|
|
|
38
|
-
data object
|
|
52
|
+
data object OwnerAccountMissing : PluginError("Owner account must be provided.")
|
|
39
53
|
|
|
40
|
-
data object
|
|
54
|
+
data object TitleMissing : PluginError("Title must be provided.")
|
|
41
55
|
|
|
42
56
|
data object ToDateMissing : PluginError("To date must be provided.")
|
|
43
57
|
|
|
44
|
-
data object
|
|
58
|
+
data object UnhandledPermissionState : PluginError("Unhandled permission state.")
|
|
45
59
|
|
|
46
60
|
data class Unimplemented(
|
|
47
61
|
val methodName: String,
|
|
48
62
|
) : PluginError("$methodName is not implemented on Android.")
|
|
49
|
-
|
|
50
|
-
data class CustomError(
|
|
51
|
-
val details: String,
|
|
52
|
-
) : PluginError(details)
|
|
53
63
|
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt
CHANGED
|
@@ -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) ?:
|
|
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(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
|
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
|
+
)
|
|
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()
|
|
194
234
|
|
|
235
|
+
val rowsDeleted = cr.delete(deleteUri, null, null)
|
|
195
236
|
if (rowsDeleted < 1) {
|
|
196
|
-
throw PluginError.
|
|
237
|
+
throw PluginError.CalendarNotFound
|
|
197
238
|
}
|
|
198
239
|
}
|
|
199
240
|
|
|
@@ -403,13 +444,16 @@ class CapacitorCalendar(
|
|
|
403
444
|
val cr = plugin.context.contentResolver
|
|
404
445
|
val values =
|
|
405
446
|
ContentValues().apply {
|
|
406
|
-
input.title?.let {
|
|
447
|
+
input.title?.let {
|
|
448
|
+
put(CalendarContract.Calendars.NAME, it)
|
|
449
|
+
put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, it)
|
|
450
|
+
}
|
|
407
451
|
input.color?.let { put(CalendarContract.Calendars.CALENDAR_COLOR, it) }
|
|
408
452
|
}
|
|
409
453
|
val uri: Uri = ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, input.id)
|
|
410
454
|
val rowsUpdated = cr.update(uri, values, null, null)
|
|
411
455
|
if (rowsUpdated < 1) {
|
|
412
|
-
throw PluginError.
|
|
456
|
+
throw PluginError.CalendarNotFound
|
|
413
457
|
}
|
|
414
458
|
}
|
|
415
459
|
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CheckPermissionInput.kt
CHANGED
|
@@ -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
|
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/CreateCalendarInput.kt
CHANGED
|
@@ -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 =
|
|
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
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/DeleteCalendarInput.kt
CHANGED
|
@@ -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 =
|
|
9
|
+
val id: Long =
|
|
10
|
+
call.getString("id")?.let { idString ->
|
|
11
|
+
idString.toLongOrNull() ?: throw PluginError.InvalidCalendarId
|
|
12
|
+
} ?: throw PluginError.CalendarIdMissing
|
|
10
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
|
+
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/ModifyCalendarInput.kt
CHANGED
|
@@ -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 =
|
|
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
|
}
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/RequestPermissionInput.kt
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
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())
|
package/android/src/main/java/dev/barooni/capacitor/calendar/models/templates/PluginCompletion.kt
ADDED
|
@@ -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
|
|
@@ -18,6 +18,9 @@ import java.util.TimeZone
|
|
|
18
18
|
|
|
19
19
|
class ImplementationHelper {
|
|
20
20
|
companion object {
|
|
21
|
+
/** Default `CALENDAR_COLOR` when `color` is omitted: `#007AFF`, fully opaque. */
|
|
22
|
+
val DEFAULT_CALENDAR_COLOR: Int = 0xFF007AFF.toInt()
|
|
23
|
+
|
|
21
24
|
fun getCalendarFromTimestamp(timestamp: Long?): Calendar =
|
|
22
25
|
Calendar.getInstance().apply {
|
|
23
26
|
timeInMillis = timestamp ?: System.currentTimeMillis()
|
|
@@ -43,14 +46,56 @@ class ImplementationHelper {
|
|
|
43
46
|
return list.map { it.toLongOrNull() ?: throw PluginError.MissingId }
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
fun hexToColorInt(hex: String?): Int?
|
|
49
|
+
fun hexToColorInt(hex: String?): Int? {
|
|
47
50
|
if (hex == null) {
|
|
48
|
-
null
|
|
49
|
-
} else {
|
|
50
|
-
android.graphics.Color.parseColor(hex)
|
|
51
|
+
return null
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
if (!hex.startsWith("#")) {
|
|
55
|
+
throw PluginError.InvalidColor
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
val digits = hex.substring(1)
|
|
59
|
+
return when (digits.length) {
|
|
60
|
+
6 -> {
|
|
61
|
+
// RRGGBB with fully opaque alpha — Color.parseColor is correct for 6-digit.
|
|
62
|
+
try {
|
|
63
|
+
android.graphics.Color.parseColor(hex)
|
|
64
|
+
} catch (_: IllegalArgumentException) {
|
|
65
|
+
throw PluginError.InvalidColor
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
8 -> {
|
|
70
|
+
// RRGGBBAA (not AARRGGBB). Do not use Color.parseColor for 8-digit.
|
|
71
|
+
try {
|
|
72
|
+
val r = digits.substring(0, 2).toInt(16)
|
|
73
|
+
val g = digits.substring(2, 4).toInt(16)
|
|
74
|
+
val b = digits.substring(4, 6).toInt(16)
|
|
75
|
+
val a = digits.substring(6, 8).toInt(16)
|
|
76
|
+
android.graphics.Color.argb(a, r, g, b)
|
|
77
|
+
} catch (_: NumberFormatException) {
|
|
78
|
+
throw PluginError.InvalidColor
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
else -> {
|
|
83
|
+
throw PluginError.InvalidColor
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fun intToHexColor(colorInt: Int): String {
|
|
89
|
+
val alpha = android.graphics.Color.alpha(colorInt)
|
|
90
|
+
val red = android.graphics.Color.red(colorInt)
|
|
91
|
+
val green = android.graphics.Color.green(colorInt)
|
|
92
|
+
val blue = android.graphics.Color.blue(colorInt)
|
|
93
|
+
return if (alpha == 0xFF) {
|
|
94
|
+
String.format(Locale.US, "#%02X%02X%02X", red, green, blue)
|
|
95
|
+
} else {
|
|
96
|
+
String.format(Locale.US, "#%02X%02X%02X%02X", red, green, blue, alpha)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
54
99
|
|
|
55
100
|
fun eventGuestsFromCall(call: PluginCall): List<EventGuest>? {
|
|
56
101
|
val attendeesJson = call.getArray("attendees") ?: return null
|
|
@@ -132,35 +177,27 @@ class ImplementationHelper {
|
|
|
132
177
|
)
|
|
133
178
|
}
|
|
134
179
|
|
|
135
|
-
fun
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var fallbackCalendarId: Long? = null
|
|
144
|
-
cr.query(uri, projection, null, null, null)?.use { cursor ->
|
|
145
|
-
if (cursor.count == 0) {
|
|
146
|
-
throw PluginError.NoCalendarsAvailable
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
while (cursor.moveToNext()) {
|
|
150
|
-
val id = cursor.getLong(cursor.getColumnIndexOrThrow(CalendarContract.Calendars._ID))
|
|
151
|
-
val isPrimary = cursor.getInt(cursor.getColumnIndexOrThrow(CalendarContract.Calendars.IS_PRIMARY)) == 1
|
|
152
|
-
|
|
153
|
-
if (isPrimary) {
|
|
154
|
-
return id
|
|
155
|
-
}
|
|
180
|
+
fun resolveDefaultCalendar(
|
|
181
|
+
calendars: List<CalendarInfo>,
|
|
182
|
+
useFallbackCalendar: Boolean,
|
|
183
|
+
): CalendarInfo? {
|
|
184
|
+
if (calendars.isEmpty()) {
|
|
185
|
+
return null
|
|
186
|
+
}
|
|
156
187
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
188
|
+
val primary = calendars.find { it.isPrimary == true }
|
|
189
|
+
if (primary != null) {
|
|
190
|
+
return primary
|
|
161
191
|
}
|
|
162
192
|
|
|
163
|
-
return
|
|
193
|
+
return if (useFallbackCalendar) calendars.first() else null
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
fun getDefaultCalendarId(cr: ContentResolver): Long {
|
|
197
|
+
val calendar =
|
|
198
|
+
resolveDefaultCalendar(listCalendars(cr), useFallbackCalendar = true)
|
|
199
|
+
?: throw PluginError.NoCalendarsAvailable
|
|
200
|
+
return calendar.id.toLong()
|
|
164
201
|
}
|
|
165
202
|
|
|
166
203
|
fun listCalendars(cr: ContentResolver): List<CalendarInfo> {
|