@ebarooni/capacitor-calendar 6.5.0 → 6.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +61 -12
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendar.kt +178 -119
  4. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +73 -0
  5. package/assets/images/text-logo.png +0 -0
  6. package/dist/docs.json +461 -60
  7. package/dist/esm/definitions.d.ts +174 -34
  8. package/dist/esm/definitions.js.map +1 -1
  9. package/dist/esm/index.d.ts +18 -14
  10. package/dist/esm/index.js +12 -9
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/schemas/enums/calendar-source-type.d.ts +38 -0
  13. package/dist/esm/schemas/enums/calendar-source-type.js +40 -0
  14. package/dist/esm/schemas/enums/calendar-source-type.js.map +1 -0
  15. package/dist/esm/schemas/enums/calendar-type.d.ts +28 -0
  16. package/dist/esm/schemas/enums/calendar-type.js +30 -0
  17. package/dist/esm/schemas/enums/calendar-type.js.map +1 -0
  18. package/dist/esm/schemas/enums/event-span.d.ts +16 -0
  19. package/dist/esm/schemas/enums/event-span.js +18 -0
  20. package/dist/esm/schemas/enums/event-span.js.map +1 -0
  21. package/dist/esm/schemas/interfaces/calendar-event.d.ts +14 -3
  22. package/dist/esm/schemas/interfaces/calendar-event.js.map +1 -1
  23. package/dist/esm/schemas/interfaces/calendar-source.d.ts +15 -0
  24. package/dist/esm/schemas/interfaces/calendar-source.js +2 -0
  25. package/dist/esm/schemas/interfaces/calendar-source.js.map +1 -0
  26. package/dist/esm/schemas/interfaces/calendar.d.ts +43 -2
  27. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  28. package/dist/esm/web.d.ts +49 -9
  29. package/dist/esm/web.js +13 -2
  30. package/dist/esm/web.js.map +1 -1
  31. package/dist/plugin.cjs.js +101 -2
  32. package/dist/plugin.cjs.js.map +1 -1
  33. package/dist/plugin.js +101 -2
  34. package/dist/plugin.js.map +1 -1
  35. package/ios/Plugin/CapacitorCalendar.swift +210 -17
  36. package/ios/Plugin/CapacitorCalendarPlugin.m +4 -0
  37. package/ios/Plugin/CapacitorCalendarPlugin.swift +111 -1
  38. package/ios/Plugin/CapacitorReminders.swift +63 -9
  39. package/ios/Plugin/EventCreationParameters.swift +1 -1
  40. package/package.json +32 -20
package/README.md CHANGED
@@ -27,29 +27,73 @@
27
27
 
28
28
  ## Table of Contents
29
29
 
30
- - [Install](#install)
30
+ - [Installation](#installation)
31
+ - [Stable](#stable)
32
+ - [Capacitor 6](#capacitor-6)
33
+ - [Capacitor 5](#capacitor-5)
34
+ - [Development](#development)
35
+ - [Setup](#setup)
36
+ - [Install](#install-1)
31
37
  - [Demo](#demo--click-for-details-)
32
38
  - [Permissions](#permissions)
33
39
  - [API](#-api)
34
40
  - [Documentation](#-documentation)
35
41
  - [Contributions](#-contributions)
36
42
 
37
- ## Install
43
+ ## Installation
38
44
 
39
- ### Capacitor 6
45
+ To use this package, follow the instructions for installing either the stable or development release.
46
+ Stable releases are recommended for production, while development releases provide access to the latest features and
47
+ fixes which are still under development.
48
+
49
+ ### Stable
50
+
51
+ The stable releases are published to the npm package registry.
52
+
53
+ #### Capacitor 6
40
54
 
41
55
  ```bash
42
56
  npm install @ebarooni/capacitor-calendar@latest
43
57
  npx cap sync
44
58
  ```
45
59
 
46
- ### Capacitor 5
60
+ #### Capacitor 5
61
+
62
+ > [!IMPORTANT]
63
+ > This plugin no longer receives updates for Capacitor v5 and only supports the latest version.
47
64
 
48
65
  ```bash
49
66
  npm install @ebarooni/capacitor-calendar@^5
50
67
  npx cap sync
51
68
  ```
52
69
 
70
+ ### Development
71
+
72
+ Development releases are published to the GitHub package registry. These releases are automatically generated from the
73
+ latest state of the `develop branch every time a pull request is merged into it.
74
+
75
+ > [!WARNING]
76
+ > Development releases are not recommended for production use as they may contain untested or experimental changes.
77
+
78
+ #### Setup
79
+
80
+ Create an `.npmrc` file and place it in the root of your project with the following content:
81
+
82
+ ```
83
+ //npm.pkg.github.com/:_authToken=$GITHUB_PAT
84
+ @ebarooni:registry=https://npm.pkg.github.com
85
+ always-auth=true
86
+ ```
87
+
88
+ Replace `$GITHUB_PAT` with your own personal access token with at least `read:packages` scope.
89
+
90
+ #### Install
91
+
92
+ ```bash
93
+ npm install @ebarooni/capacitor-calendar
94
+ npx cap sync
95
+ ```
96
+
53
97
  ## [Demo (click for details)](./example/README.md)
54
98
 
55
99
  | iOS 17 | Android 14 |
@@ -63,11 +107,11 @@ The video is just for showing the functionality, otherwise the `createEventWithP
63
107
 
64
108
  ## Permissions
65
109
 
66
- To be able to use the plugin, you will need to add the required permissions to your app. The required platform-specific
67
- permissions can be found below:
110
+ To be able to use the plugin, you will need to add the required usage descriptions to your app. The required platform-specific
111
+ usage descriptions can be found below:
68
112
 
69
- - [iOS](./ios/PERMISSIONS.md)
70
- - [Android](./android/PERMISSIONS.md)
113
+ - [iOS](./docs/usage-descriptions/ios.md)
114
+ - [Android](./docs/usage-descriptions/android.md)
71
115
 
72
116
  ## 📋 API
73
117
 
@@ -97,6 +141,10 @@ permissions can be found below:
97
141
  * [`requestReadOnlyCalendarAccess()`](#requestreadonlycalendaraccess)
98
142
  * [`requestFullCalendarAccess()`](#requestfullcalendaraccess)
99
143
  * [`requestFullRemindersAccess()`](#requestfullremindersaccess)
144
+ * [`modifyEventWithPrompt(...)`](#modifyeventwithprompt)
145
+ * [`modifyEvent(...)`](#modifyevent)
146
+ * [`fetchAllCalendarSources()`](#fetchallcalendarsources)
147
+ * [`fetchAllRemindersSources()`](#fetchallreminderssources)
100
148
  * [Interfaces](#interfaces)
101
149
  * [Type Aliases](#type-aliases)
102
150
  * [Enums](#enums)
@@ -105,14 +153,15 @@ permissions can be found below:
105
153
 
106
154
  ## 📚 Documentation
107
155
 
108
- For detailed explanations, usage examples, and additional information:
156
+ For comprehensive explanations, usage examples, and additional information, please refer to the following resources:
109
157
 
110
- - **documentation.md**: Autogenerated docs are available in the [documentation](documentation.md) file.
111
- - **definitions.ts**: Complete documentation with usage examples is available in the [src/definitions.ts](src/definitions.ts) file.
158
+ - **[Online Documentation](https://ebarooni.github.io/capacitor-calendar/)**
159
+ - **[API Reference](docs/api-reference.md)**
160
+ - **[Type Definitions and Examples](src/definitions.ts)**
112
161
 
113
162
  ## 💙 Contributions
114
163
 
115
- > [!WARNING]
164
+ > [!NOTE]
116
165
  > Thank you for your interest in contributing to the project! At the moment, the focus is on reaching the first major
117
166
  > release. Until then, the contributions will not be accepted. This approach allows to set a solid
118
167
  > foundation and maintain consistency throughout the development process.
@@ -14,7 +14,7 @@ buildscript {
14
14
  mavenCentral()
15
15
  }
16
16
  dependencies {
17
- classpath 'com.android.tools.build:gradle:8.3.2'
17
+ classpath 'com.android.tools.build:gradle:8.5.1'
18
18
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19
19
  }
20
20
  }
@@ -57,7 +57,7 @@ dependencies {
57
57
  implementation fileTree(dir: 'libs', include: ['*.jar'])
58
58
  implementation project(':capacitor-android')
59
59
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
60
- implementation 'androidx.core:core-ktx:+'
60
+ implementation 'androidx.core:core-ktx:1.13.1'
61
61
  testImplementation "junit:junit:$junitVersion"
62
62
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
63
63
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -12,7 +12,7 @@ import com.getcapacitor.JSObject
12
12
  import java.util.Calendar
13
13
  import java.util.TimeZone
14
14
 
15
- class CapacitorCalendar() {
15
+ class CapacitorCalendar {
16
16
  var eventIdsArray: List<Long> = emptyList()
17
17
 
18
18
  @Throws(Exception::class)
@@ -32,9 +32,7 @@ class CapacitorCalendar() {
32
32
  }
33
33
 
34
34
  @Throws(Exception::class)
35
- fun getNewEventIds(newIds: List<Long>): List<Long> {
36
- return newIds.filterNot { it in eventIdsArray }
37
- }
35
+ fun getNewEventIds(newIds: List<Long>): List<Long> = newIds.filterNot { it in eventIdsArray }
38
36
 
39
37
  @Throws(Exception::class)
40
38
  fun listCalendars(context: Context): JSArray {
@@ -42,32 +40,37 @@ class CapacitorCalendar() {
42
40
  arrayOf(
43
41
  CalendarContract.Calendars._ID,
44
42
  CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
43
+ CalendarContract.Calendars.CALENDAR_COLOR,
45
44
  )
46
45
 
47
46
  val calendars = JSArray()
48
47
 
49
- context.contentResolver.query(
50
- CalendarContract.Calendars.CONTENT_URI,
51
- projection,
52
- null,
53
- null,
54
- null,
55
- )?.use { cursor ->
56
- val idColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars._ID)
57
- val nameColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
58
-
59
- while (cursor.moveToNext()) {
60
- val id = cursor.getLong(idColumnIndex)
61
- val title = cursor.getString(nameColumnIndex)
62
- val calendar =
63
- JSObject().apply {
64
- put("id", "$id")
65
- put("title", title)
66
- }
48
+ context.contentResolver
49
+ .query(
50
+ CalendarContract.Calendars.CONTENT_URI,
51
+ projection,
52
+ null,
53
+ null,
54
+ null,
55
+ )?.use { cursor ->
56
+ val idColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars._ID)
57
+ val nameColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
58
+ val calendarColorColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_COLOR)
67
59
 
68
- calendars.put(calendar)
69
- }
70
- } ?: throw Exception("Cursor is null")
60
+ while (cursor.moveToNext()) {
61
+ val id = cursor.getLong(idColumnIndex)
62
+ val title = cursor.getString(nameColumnIndex)
63
+ val calendarColor = cursor.getInt(calendarColorColumnIndex)
64
+ val calendar =
65
+ JSObject().apply {
66
+ put("id", "$id")
67
+ put("title", title)
68
+ put("color", String.format("#%06X", 0xFFFFFF and calendarColor))
69
+ }
70
+
71
+ calendars.put(calendar)
72
+ }
73
+ } ?: throw Exception("Cursor is null")
71
74
 
72
75
  return calendars
73
76
  }
@@ -83,29 +86,30 @@ class CapacitorCalendar() {
83
86
  val selection = "${CalendarContract.Calendars.IS_PRIMARY} = ?"
84
87
  val selectionArgs = arrayOf("1")
85
88
 
86
- context.contentResolver.query(
87
- CalendarContract.Calendars.CONTENT_URI,
88
- projection,
89
- selection,
90
- selectionArgs,
91
- null,
92
- )?.use { cursor ->
93
- if (cursor.moveToFirst()) {
94
- val idColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars._ID)
95
- val nameColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
96
- val id = cursor.getLong(idColumnIndex)
97
- val title = cursor.getString(nameColumnIndex)
89
+ context.contentResolver
90
+ .query(
91
+ CalendarContract.Calendars.CONTENT_URI,
92
+ projection,
93
+ selection,
94
+ selectionArgs,
95
+ null,
96
+ )?.use { cursor ->
97
+ if (cursor.moveToFirst()) {
98
+ val idColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars._ID)
99
+ val nameColumnIndex = cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
100
+ val id = cursor.getLong(idColumnIndex)
101
+ val title = cursor.getString(nameColumnIndex)
98
102
 
99
- val calendarObject =
100
- JSObject().apply {
101
- put("id", id.toString())
102
- put("title", title)
103
- }
104
- return calendarObject
105
- } else {
106
- return null
103
+ val calendarObject =
104
+ JSObject().apply {
105
+ put("id", id.toString())
106
+ put("title", title)
107
+ }
108
+ return calendarObject
109
+ } else {
110
+ return null
111
+ }
107
112
  }
108
- }
109
113
  throw Exception("No primary calendar found")
110
114
  }
111
115
 
@@ -147,41 +151,77 @@ class CapacitorCalendar() {
147
151
  context.contentResolver.insert(CalendarContract.Reminders.CONTENT_URI, alertValues)
148
152
  }
149
153
  alertOffsetInMinutesMultiple != null -> {
150
- alertOffsetInMinutesMultiple.toList<Any>().mapNotNull { alert ->
151
- try {
152
- val alertFloat = alert.toString().toFloat()
153
- if (alertFloat > -1) alertFloat else null
154
- } catch (e: NumberFormatException) {
155
- Log.e("Error", "Failed to convert alert to float: $alert", e)
156
- null
154
+ alertOffsetInMinutesMultiple
155
+ .toList<Any>()
156
+ .mapNotNull { alert ->
157
+ try {
158
+ val alertFloat = alert.toString().toFloat()
159
+ if (alertFloat > -1) alertFloat else null
160
+ } catch (e: NumberFormatException) {
161
+ Log.e("Error", "Failed to convert alert to float: $alert", e)
162
+ null
163
+ }
164
+ }.forEach { alertFloat ->
165
+ val alertValues = createAlertValues(eventId, alertFloat)
166
+ context.contentResolver.insert(CalendarContract.Reminders.CONTENT_URI, alertValues)
157
167
  }
158
- }.forEach { alertFloat ->
159
- val alertValues = createAlertValues(eventId, alertFloat)
160
- context.contentResolver.insert(CalendarContract.Reminders.CONTENT_URI, alertValues)
161
- }
162
168
  }
163
169
  }
164
170
 
165
171
  return eventUri
166
172
  }
167
173
 
174
+ @Throws(Exception::class)
175
+ fun modifyEvent(
176
+ context: Context,
177
+ id: Long,
178
+ update: JSObject,
179
+ ): Boolean {
180
+ val title = update.getString("title")
181
+ val calendarId = update.getString("calendarId")
182
+ val location = update.getString("location")
183
+ val startDate = update.getLong("startDate")
184
+ val endDate = update.getLong("endDate")
185
+ val isAllDay = update.getBoolean("isAllDay")
186
+ val url = update.getString("url")
187
+ val notes = update.getString("notes")
188
+
189
+ val eventUri: Uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, id)
190
+
191
+ val values =
192
+ ContentValues().apply {
193
+ if (title != null) put(CalendarContract.Events.TITLE, title)
194
+ if (calendarId != null) put(CalendarContract.Events.CALENDAR_ID, calendarId)
195
+ if (location != null) put(CalendarContract.Events.EVENT_LOCATION, location)
196
+ if (startDate != null) put(CalendarContract.Events.DTSTART, startDate)
197
+ if (endDate != null) put(CalendarContract.Events.DTEND, endDate)
198
+ if (isAllDay != null) put(CalendarContract.Events.ALL_DAY, if (isAllDay) 1 else 0)
199
+ if (notes !=
200
+ null
201
+ ) {
202
+ put(CalendarContract.Events.DESCRIPTION, listOfNotNull(notes, url?.let { "URL: $it" }).joinToString("\n"))
203
+ }
204
+ }
205
+
206
+ val rows: Int = context.contentResolver.update(eventUri, values, null, null)
207
+ return rows > 0
208
+ }
209
+
168
210
  private fun createAlertValues(
169
211
  eventId: Long,
170
212
  alertOffset: Float,
171
- ): ContentValues {
172
- return ContentValues().apply {
213
+ ): ContentValues =
214
+ ContentValues().apply {
173
215
  put(CalendarContract.Reminders.EVENT_ID, eventId)
174
216
  put(CalendarContract.Reminders.MINUTES, alertOffset)
175
217
  put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT)
176
218
  }
177
- }
178
219
 
179
220
  @Throws(Exception::class)
180
- fun openCalendar(timestamp: Long): Intent {
181
- return Intent(Intent.ACTION_VIEW).apply {
221
+ fun openCalendar(timestamp: Long): Intent =
222
+ Intent(Intent.ACTION_VIEW).apply {
182
223
  data = Uri.parse("content://com.android.calendar/time/$timestamp")
183
224
  }
184
- }
185
225
 
186
226
  @Throws(Exception::class)
187
227
  fun listEventsInRange(
@@ -194,7 +234,7 @@ class CapacitorCalendar() {
194
234
  CalendarContract.Events._ID,
195
235
  CalendarContract.Events.TITLE,
196
236
  CalendarContract.Events.EVENT_LOCATION,
197
- CalendarContract.Events.EVENT_COLOR,
237
+ CalendarContract.Events.CALENDAR_COLOR,
198
238
  CalendarContract.Events.ORGANIZER,
199
239
  CalendarContract.Events.DESCRIPTION,
200
240
  CalendarContract.Events.DTSTART,
@@ -210,61 +250,74 @@ class CapacitorCalendar() {
210
250
 
211
251
  val events = JSArray()
212
252
 
213
- context.contentResolver.query(
214
- CalendarContract.Events.CONTENT_URI,
215
- projection,
216
- selection,
217
- selectionArgs,
218
- null,
219
- )?.use { cursor ->
220
- val idColumnIndex = cursor.getColumnIndex(CalendarContract.Events._ID)
221
- val nameColumnIndex = cursor.getColumnIndex(CalendarContract.Events.TITLE)
222
- val locationColumnIndex = cursor.getColumnIndex(CalendarContract.Events.EVENT_LOCATION)
223
- val eventColorColumnIndex = cursor.getColumnIndex(CalendarContract.Events.EVENT_COLOR)
224
- val organizerColumnIndex = cursor.getColumnIndex(CalendarContract.Events.ORGANIZER)
225
- val descriptionColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DESCRIPTION)
226
- val dtStartColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DTSTART)
227
- val dtEndColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DTEND)
228
- val eventTimezoneColumnIndex = cursor.getColumnIndex(CalendarContract.Events.EVENT_TIMEZONE)
229
- val eventEndTimezoneColumnIndex = cursor.getColumnIndex(CalendarContract.Events.EVENT_END_TIMEZONE)
230
- val durationColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DURATION)
231
- val isAllDayColumnIndex = cursor.getColumnIndex(CalendarContract.Events.ALL_DAY)
232
- val calendarIdColumnIndex = cursor.getColumnIndex(CalendarContract.Events.CALENDAR_ID)
233
-
234
- while (cursor.moveToNext()) {
235
- val id = cursor.getLong(idColumnIndex)
236
- val title = cursor.getString(nameColumnIndex)
237
- val location = cursor.getString(locationColumnIndex)
238
- val eventColor = cursor.getInt(eventColorColumnIndex)
239
- val organizer = cursor.getString(organizerColumnIndex)
240
- val desc = cursor.getString(descriptionColumnIndex)
241
- val dtStart = cursor.getLong(dtStartColumnIndex)
242
- val dtEnd = cursor.getLong(dtEndColumnIndex)
243
- val eventTimezone = cursor.getString(eventTimezoneColumnIndex)
244
- val eventEndTimezone = cursor.getString(eventEndTimezoneColumnIndex)
245
- val duration = cursor.getString(durationColumnIndex)
246
- val allDay = cursor.getInt(isAllDayColumnIndex) == 1
247
- val calendarId = cursor.getLong(calendarIdColumnIndex)
248
-
249
- val event =
250
- JSObject().apply {
251
- put("id", id.toString())
252
- title?.takeIf { it.isNotEmpty() }?.let { put("title", it) }
253
- location?.takeIf { it.isNotEmpty() }?.let { put("location", it) }
254
- eventColor.takeIf { it != 0 }?.let { put("eventColor", String.format("#%06X", 0xFFFFFF and it)) }
255
- organizer?.takeIf { it.isNotEmpty() }?.let { put("organizer", it) }
256
- desc?.takeIf { it.isNotEmpty() }?.let { put("description", it) }
257
- dtStart.takeIf { it != 0.toLong() }?.let { put("startDate", it) }
258
- dtEnd.takeIf { it != 0.toLong() }?.let { put("endDate", it) }
259
- eventTimezone?.takeIf { it.isNotEmpty() }?.let { put("eventTimezone", it) }
260
- eventEndTimezone?.takeIf { it.isNotEmpty() }?.let { put("eventEndTimezone", it) }
261
- duration?.takeIf { it.isNotEmpty() }?.let { put("duration", it) }
262
- put("isAllDay", allDay)
263
- calendarId.takeIf { it != 0.toLong() }?.let { put("calendarId", it.toString()) }
264
- }
265
- events.put(event)
266
- }
267
- } ?: throw Exception("Cursor is null")
253
+ context.contentResolver
254
+ .query(
255
+ CalendarContract.Events.CONTENT_URI,
256
+ projection,
257
+ selection,
258
+ selectionArgs,
259
+ null,
260
+ )?.use { cursor ->
261
+ val idColumnIndex = cursor.getColumnIndex(CalendarContract.Events._ID)
262
+ val nameColumnIndex = cursor.getColumnIndex(CalendarContract.Events.TITLE)
263
+ val locationColumnIndex = cursor.getColumnIndex(CalendarContract.Events.EVENT_LOCATION)
264
+ val calendarColorColumnIndex = cursor.getColumnIndex(CalendarContract.Events.CALENDAR_COLOR)
265
+ val organizerColumnIndex = cursor.getColumnIndex(CalendarContract.Events.ORGANIZER)
266
+ val descriptionColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DESCRIPTION)
267
+ val dtStartColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DTSTART)
268
+ val dtEndColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DTEND)
269
+ val eventTimezoneColumnIndex = cursor.getColumnIndex(CalendarContract.Events.EVENT_TIMEZONE)
270
+ val eventEndTimezoneColumnIndex = cursor.getColumnIndex(CalendarContract.Events.EVENT_END_TIMEZONE)
271
+ val durationColumnIndex = cursor.getColumnIndex(CalendarContract.Events.DURATION)
272
+ val isAllDayColumnIndex = cursor.getColumnIndex(CalendarContract.Events.ALL_DAY)
273
+ val calendarIdColumnIndex = cursor.getColumnIndex(CalendarContract.Events.CALENDAR_ID)
274
+
275
+ while (cursor.moveToNext()) {
276
+ val id = cursor.getLong(idColumnIndex)
277
+ val title = cursor.getString(nameColumnIndex)
278
+ val location = cursor.getString(locationColumnIndex)
279
+ val calendarColor = cursor.getInt(calendarColorColumnIndex)
280
+ val organizer = cursor.getString(organizerColumnIndex)
281
+ val desc = cursor.getString(descriptionColumnIndex)
282
+ val dtStart = cursor.getLong(dtStartColumnIndex)
283
+ val dtEnd = cursor.getLong(dtEndColumnIndex)
284
+ val eventTimezone = cursor.getString(eventTimezoneColumnIndex)
285
+ val eventEndTimezone = cursor.getString(eventEndTimezoneColumnIndex)
286
+ val duration = cursor.getString(durationColumnIndex)
287
+ val allDay = cursor.getInt(isAllDayColumnIndex) == 1
288
+ val calendarId = cursor.getLong(calendarIdColumnIndex)
289
+
290
+ val event =
291
+ JSObject().apply {
292
+ put("id", id.toString())
293
+ title?.takeIf { it.isNotEmpty() }?.let { put("title", it) }
294
+ location?.takeIf { it.isNotEmpty() }?.let { put("location", it) }
295
+ calendarColor.takeIf { it != 0 }?.let { put("eventColor", String.format("#%06X", 0xFFFFFF and it)) }
296
+ organizer?.takeIf { it.isNotEmpty() }?.let { put("organizer", it) }
297
+ desc?.takeIf { it.isNotEmpty() }?.let { put("description", it) }
298
+ dtStart.takeIf { it != 0.toLong() }?.let { put("startDate", it) }
299
+ dtEnd.takeIf { it != 0.toLong() }?.let { put("endDate", it) }
300
+ eventTimezone?.takeIf { it.isNotEmpty() }?.let { timezone ->
301
+ val abbreviation = getTimeZoneAbbreviation(timezone)
302
+ val obj = JSObject()
303
+ obj.put("region", timezone)
304
+ obj.put("abbreviation", abbreviation)
305
+ put("eventTimezone", obj)
306
+ }
307
+ eventEndTimezone?.takeIf { it.isNotEmpty() }?.let {
308
+ val abbreviation = getTimeZoneAbbreviation(it)
309
+ val obj = JSObject()
310
+ obj.put("region", it)
311
+ obj.put("abbreviation", abbreviation)
312
+ put("eventEndTimezone", obj)
313
+ }
314
+ duration?.takeIf { it.isNotEmpty() }?.let { put("duration", it) }
315
+ put("isAllDay", allDay)
316
+ calendarId.takeIf { it != 0.toLong() }?.let { put("calendarId", it.toString()) }
317
+ }
318
+ events.put(event)
319
+ }
320
+ } ?: throw Exception("Cursor is null")
268
321
  return events
269
322
  }
270
323
 
@@ -296,4 +349,10 @@ class CapacitorCalendar() {
296
349
  ret.put("failed", failedToDeleteEvents)
297
350
  return ret
298
351
  }
352
+
353
+ fun getTimeZoneAbbreviation(timeZoneId: String): String {
354
+ val timeZone = TimeZone.getTimeZone(timeZoneId)
355
+ val now = Calendar.getInstance(timeZone)
356
+ return timeZone.getDisplayName(timeZone.inDaylightTime(now.time), TimeZone.SHORT)
357
+ }
299
358
  }
@@ -1,7 +1,9 @@
1
1
  package dev.barooni.capacitor.calendar
2
2
 
3
3
  import android.Manifest
4
+ import android.content.ContentUris
4
5
  import android.content.Intent
6
+ import android.net.Uri
5
7
  import android.provider.CalendarContract
6
8
  import androidx.activity.result.ActivityResult
7
9
  import com.getcapacitor.JSArray
@@ -94,6 +96,77 @@ class CapacitorCalendarPlugin : Plugin() {
94
96
  call.resolve(ret)
95
97
  }
96
98
 
99
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
100
+ fun modifyEventWithPrompt(call: PluginCall) {
101
+ try {
102
+ val stringId =
103
+ call.getString("id") ?: throw Exception("[CapacitorCalendar.${::modifyEventWithPrompt.name}] Event ID not defined")
104
+ val update = call.getObject("update")
105
+ val uri: Uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, stringId.toLong())
106
+ val intent =
107
+ Intent(Intent.ACTION_EDIT)
108
+ .setData(uri)
109
+
110
+ if (update != null) {
111
+ val title = update.getString("title")
112
+ val calendarId = update.getString("calendarId")
113
+ val location = update.getString("location")
114
+ val startDate = update.getLong("startDate")
115
+ val endDate = update.getLong("endDate")
116
+ val isAllDay = update.getBoolean("isAllDay")
117
+ val url = update.getString("url")
118
+ val notes = update.getString("notes")
119
+
120
+ intent.putExtra(CalendarContract.Events.TITLE, title)
121
+ calendarId?.let { intent.putExtra(CalendarContract.Events.CALENDAR_ID, it) }
122
+ location?.let { intent.putExtra(CalendarContract.Events.EVENT_LOCATION, it) }
123
+ startDate?.let { intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, it) }
124
+ endDate?.let { intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, it) }
125
+ isAllDay?.let { intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, it) }
126
+ intent.putExtra(CalendarContract.Events.DESCRIPTION, listOfNotNull(notes, url?.let { "URL: $it" }).joinToString("\n"))
127
+ }
128
+
129
+ return startActivityForResult(
130
+ call,
131
+ intent,
132
+ "openEventEditIntentActivityCallback",
133
+ )
134
+ } catch (error: Exception) {
135
+ call.reject("", error.message)
136
+ return
137
+ }
138
+ }
139
+
140
+ @ActivityCallback
141
+ private fun openEventEditIntentActivityCallback(
142
+ call: PluginCall?,
143
+ result: ActivityResult,
144
+ ) {
145
+ if (call == null) {
146
+ throw Exception("[CapacitorCalendar.${::createEventWithPrompt.name}] Call is not defined")
147
+ }
148
+ val ret = JSObject()
149
+ ret.put("result", JSArray())
150
+ call.resolve(ret)
151
+ }
152
+
153
+ @PluginMethod(returnType = PluginMethod.RETURN_NONE)
154
+ fun modifyEvent(call: PluginCall) {
155
+ try {
156
+ val stringId = call.getString("id") ?: throw Exception("[CapacitorCalendar.${::modifyEvent.name}] Event ID not defined")
157
+ val update = call.getObject("update") ?: throw Exception("[CapacitorCalendar.${::modifyEvent.name}] Update not provided")
158
+ val updated = implementation.modifyEvent(context, stringId.toLong(), update)
159
+ if (updated) {
160
+ call.resolve()
161
+ } else {
162
+ throw Exception("[CapacitorCalendar.${::modifyEvent.name}] Event not updated")
163
+ }
164
+ } catch (error: Exception) {
165
+ call.reject("", error.message)
166
+ return
167
+ }
168
+ }
169
+
97
170
  @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
98
171
  fun checkPermission(call: PluginCall) {
99
172
  try {
Binary file