@ebarooni/capacitor-calendar 0.3.1 → 0.4.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 +73 -4
- package/android/build.gradle +1 -1
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendar.kt +35 -0
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +22 -0
- package/dist/docs.json +810 -6
- package/dist/esm/definitions.d.ts +41 -7
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +10 -0
- package/dist/esm/web.js +3 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +3 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +3 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendar.swift +33 -0
- package/ios/Plugin/CapacitorCalendarPlugin.m +1 -0
- package/ios/Plugin/CapacitorCalendarPlugin.swift +28 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -29,10 +29,10 @@ npx cap sync
|
|
|
29
29
|
|
|
30
30
|
## Support Range
|
|
31
31
|
|
|
32
|
-
|
|
|
33
|
-
|
|
34
|
-
|
|
|
35
|
-
|
|
|
32
|
+
| Platform | range |
|
|
33
|
+
|:--------:|:-------------------------:|
|
|
34
|
+
| iOS | ≥ 13 |
|
|
35
|
+
| Android | ≥ 7 (SDK 24 or Nougat) |
|
|
36
36
|
|
|
37
37
|
## [Demo (click for details)](./example/README.md)
|
|
38
38
|
|
|
@@ -74,6 +74,7 @@ permissions can be found below:
|
|
|
74
74
|
* [`selectCalendarsWithPrompt(...)`](#selectcalendarswithprompt)
|
|
75
75
|
* [`listCalendars()`](#listcalendars)
|
|
76
76
|
* [`getDefaultCalendar()`](#getdefaultcalendar)
|
|
77
|
+
* [`createEvent(...)`](#createevent)
|
|
77
78
|
* [Interfaces](#interfaces)
|
|
78
79
|
* [Type Aliases](#type-aliases)
|
|
79
80
|
* [Enums](#enums)
|
|
@@ -203,6 +204,23 @@ Retrieves the default calendar set on the device.
|
|
|
203
204
|
--------------------
|
|
204
205
|
|
|
205
206
|
|
|
207
|
+
### createEvent(...)
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
createEvent(options: { title: string; calendarId?: string; location?: string; startDate?: Date; endDate?: Date; isAllDay?: boolean; }) => Promise<{ eventCreated: boolean; }>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Creates an event with the provided options.
|
|
214
|
+
|
|
215
|
+
| Param | Type | Description |
|
|
216
|
+
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
|
|
217
|
+
| **`options`** | <code>{ title: string; calendarId?: string; location?: string; startDate?: <a href="#date">Date</a>; endDate?: <a href="#date">Date</a>; isAllDay?: boolean; }</code> | - Options for creating the event. |
|
|
218
|
+
|
|
219
|
+
**Returns:** <code>Promise<{ eventCreated: boolean; }></code>
|
|
220
|
+
|
|
221
|
+
--------------------
|
|
222
|
+
|
|
223
|
+
|
|
206
224
|
### Interfaces
|
|
207
225
|
|
|
208
226
|
|
|
@@ -226,6 +244,57 @@ Represents a calendar object with an ID and title.
|
|
|
226
244
|
| **`title`** | <code>string</code> |
|
|
227
245
|
|
|
228
246
|
|
|
247
|
+
#### Date
|
|
248
|
+
|
|
249
|
+
Enables basic storage and retrieval of dates and times.
|
|
250
|
+
|
|
251
|
+
| Method | Signature | Description |
|
|
252
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
253
|
+
| **toString** | () => string | Returns a string representation of a date. The format of the string depends on the locale. |
|
|
254
|
+
| **toDateString** | () => string | Returns a date as a string value. |
|
|
255
|
+
| **toTimeString** | () => string | Returns a time as a string value. |
|
|
256
|
+
| **toLocaleString** | () => string | Returns a value as a string value appropriate to the host environment's current locale. |
|
|
257
|
+
| **toLocaleDateString** | () => string | Returns a date as a string value appropriate to the host environment's current locale. |
|
|
258
|
+
| **toLocaleTimeString** | () => string | Returns a time as a string value appropriate to the host environment's current locale. |
|
|
259
|
+
| **valueOf** | () => number | Returns the stored time value in milliseconds since midnight, January 1, 1970 UTC. |
|
|
260
|
+
| **getTime** | () => number | Gets the time value in milliseconds. |
|
|
261
|
+
| **getFullYear** | () => number | Gets the year, using local time. |
|
|
262
|
+
| **getUTCFullYear** | () => number | Gets the year using Universal Coordinated Time (UTC). |
|
|
263
|
+
| **getMonth** | () => number | Gets the month, using local time. |
|
|
264
|
+
| **getUTCMonth** | () => number | Gets the month of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
265
|
+
| **getDate** | () => number | Gets the day-of-the-month, using local time. |
|
|
266
|
+
| **getUTCDate** | () => number | Gets the day-of-the-month, using Universal Coordinated Time (UTC). |
|
|
267
|
+
| **getDay** | () => number | Gets the day of the week, using local time. |
|
|
268
|
+
| **getUTCDay** | () => number | Gets the day of the week using Universal Coordinated Time (UTC). |
|
|
269
|
+
| **getHours** | () => number | Gets the hours in a date, using local time. |
|
|
270
|
+
| **getUTCHours** | () => number | Gets the hours value in a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
271
|
+
| **getMinutes** | () => number | Gets the minutes of a <a href="#date">Date</a> object, using local time. |
|
|
272
|
+
| **getUTCMinutes** | () => number | Gets the minutes of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
273
|
+
| **getSeconds** | () => number | Gets the seconds of a <a href="#date">Date</a> object, using local time. |
|
|
274
|
+
| **getUTCSeconds** | () => number | Gets the seconds of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
275
|
+
| **getMilliseconds** | () => number | Gets the milliseconds of a <a href="#date">Date</a>, using local time. |
|
|
276
|
+
| **getUTCMilliseconds** | () => number | Gets the milliseconds of a <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
277
|
+
| **getTimezoneOffset** | () => number | Gets the difference in minutes between the time on the local computer and Universal Coordinated Time (UTC). |
|
|
278
|
+
| **setTime** | (time: number) => number | Sets the date and time value in the <a href="#date">Date</a> object. |
|
|
279
|
+
| **setMilliseconds** | (ms: number) => number | Sets the milliseconds value in the <a href="#date">Date</a> object using local time. |
|
|
280
|
+
| **setUTCMilliseconds** | (ms: number) => number | Sets the milliseconds value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
281
|
+
| **setSeconds** | (sec: number, ms?: number \| undefined) => number | Sets the seconds value in the <a href="#date">Date</a> object using local time. |
|
|
282
|
+
| **setUTCSeconds** | (sec: number, ms?: number \| undefined) => number | Sets the seconds value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
283
|
+
| **setMinutes** | (min: number, sec?: number \| undefined, ms?: number \| undefined) => number | Sets the minutes value in the <a href="#date">Date</a> object using local time. |
|
|
284
|
+
| **setUTCMinutes** | (min: number, sec?: number \| undefined, ms?: number \| undefined) => number | Sets the minutes value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
285
|
+
| **setHours** | (hours: number, min?: number \| undefined, sec?: number \| undefined, ms?: number \| undefined) => number | Sets the hour value in the <a href="#date">Date</a> object using local time. |
|
|
286
|
+
| **setUTCHours** | (hours: number, min?: number \| undefined, sec?: number \| undefined, ms?: number \| undefined) => number | Sets the hours value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
287
|
+
| **setDate** | (date: number) => number | Sets the numeric day-of-the-month value of the <a href="#date">Date</a> object using local time. |
|
|
288
|
+
| **setUTCDate** | (date: number) => number | Sets the numeric day of the month in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
289
|
+
| **setMonth** | (month: number, date?: number \| undefined) => number | Sets the month value in the <a href="#date">Date</a> object using local time. |
|
|
290
|
+
| **setUTCMonth** | (month: number, date?: number \| undefined) => number | Sets the month value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
291
|
+
| **setFullYear** | (year: number, month?: number \| undefined, date?: number \| undefined) => number | Sets the year of the <a href="#date">Date</a> object using local time. |
|
|
292
|
+
| **setUTCFullYear** | (year: number, month?: number \| undefined, date?: number \| undefined) => number | Sets the year value in the <a href="#date">Date</a> object using Universal Coordinated Time (UTC). |
|
|
293
|
+
| **toUTCString** | () => string | Returns a date converted to a string using Universal Coordinated Time (UTC). |
|
|
294
|
+
| **toISOString** | () => string | Returns a date as a string value in ISO format. |
|
|
295
|
+
| **toJSON** | (key?: any) => string | Used by the JSON.stringify method to enable the transformation of an object's data for JavaScript Object Notation (JSON) serialization. |
|
|
296
|
+
|
|
297
|
+
|
|
229
298
|
### Type Aliases
|
|
230
299
|
|
|
231
300
|
|
package/android/build.gradle
CHANGED
|
@@ -26,7 +26,7 @@ android {
|
|
|
26
26
|
namespace "dev.barooni.capacitor.calendar"
|
|
27
27
|
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
28
28
|
defaultConfig {
|
|
29
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion :
|
|
29
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
30
30
|
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
31
31
|
versionCode 1
|
|
32
32
|
versionName "1.0"
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
package dev.barooni.capacitor.calendar
|
|
2
2
|
|
|
3
3
|
import android.content.ContentResolver
|
|
4
|
+
import android.content.ContentValues
|
|
4
5
|
import android.content.Context
|
|
6
|
+
import android.net.Uri
|
|
5
7
|
import android.provider.CalendarContract
|
|
6
8
|
import com.getcapacitor.JSArray
|
|
7
9
|
import com.getcapacitor.JSObject
|
|
10
|
+
import java.text.SimpleDateFormat
|
|
11
|
+
import java.util.Calendar
|
|
12
|
+
import java.util.Locale
|
|
13
|
+
import java.util.TimeZone
|
|
8
14
|
|
|
9
15
|
class CapacitorCalendar() {
|
|
10
16
|
var eventsCount: Int = 0
|
|
@@ -88,4 +94,33 @@ class CapacitorCalendar() {
|
|
|
88
94
|
}
|
|
89
95
|
throw Exception("No primary calendar found")
|
|
90
96
|
}
|
|
97
|
+
|
|
98
|
+
@Throws(Exception::class)
|
|
99
|
+
fun createEvent(
|
|
100
|
+
context: Context,
|
|
101
|
+
title: String,
|
|
102
|
+
calendarId: String?,
|
|
103
|
+
location: String?,
|
|
104
|
+
startDate: String?,
|
|
105
|
+
endDate: String?,
|
|
106
|
+
isAllDay: Boolean?
|
|
107
|
+
): Uri? {
|
|
108
|
+
val isoFormatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.getDefault()).apply {
|
|
109
|
+
timeZone = TimeZone.getTimeZone("UTC")
|
|
110
|
+
}
|
|
111
|
+
val startMillis = startDate?.let { isoFormatter.parse(it)?.time } ?: Calendar.getInstance().timeInMillis
|
|
112
|
+
val endMillis = endDate?.let { isoFormatter.parse(it)?.time } ?: (startMillis + 3600 * 1000)
|
|
113
|
+
|
|
114
|
+
val values = ContentValues().apply {
|
|
115
|
+
put(CalendarContract.Events.DTSTART, startMillis)
|
|
116
|
+
put(CalendarContract.Events.DTEND, endMillis)
|
|
117
|
+
put(CalendarContract.Events.TITLE, title)
|
|
118
|
+
location?.let { put(CalendarContract.Events.EVENT_LOCATION, it) }
|
|
119
|
+
put(CalendarContract.Events.CALENDAR_ID, calendarId ?: getDefaultCalendar(context).getString("id"))
|
|
120
|
+
put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().id)
|
|
121
|
+
isAllDay?.let { put(CalendarContract.Events.ALL_DAY, if (it) 1 else 0) }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return context.contentResolver.insert(CalendarContract.Events.CONTENT_URI, values)
|
|
125
|
+
}
|
|
91
126
|
}
|
|
@@ -3,6 +3,7 @@ package dev.barooni.capacitor.calendar
|
|
|
3
3
|
import android.Manifest
|
|
4
4
|
import android.content.Intent
|
|
5
5
|
import android.provider.CalendarContract
|
|
6
|
+
import android.util.Log
|
|
6
7
|
import androidx.activity.result.ActivityResult
|
|
7
8
|
import com.getcapacitor.JSObject
|
|
8
9
|
import com.getcapacitor.Plugin
|
|
@@ -161,4 +162,25 @@ class CapacitorCalendarPlugin: Plugin() {
|
|
|
161
162
|
call.reject("", "[CapacitorCalendar.${::getDefaultCalendar.name}] No default calendar found")
|
|
162
163
|
}
|
|
163
164
|
}
|
|
165
|
+
|
|
166
|
+
@PluginMethod
|
|
167
|
+
fun createEvent(call: PluginCall) {
|
|
168
|
+
try {
|
|
169
|
+
val title = call.getString("title")
|
|
170
|
+
?: throw Exception("[CapacitorCalendar.${::createEvent.name}] A title for the event was not provided")
|
|
171
|
+
val calendarId = call.getString("calendarId")
|
|
172
|
+
val location = call.getString("location")
|
|
173
|
+
val startDate = call.getString("startDate")
|
|
174
|
+
val endDate = call.getString("endDate")
|
|
175
|
+
val isAllDay = call.getBoolean("isAllDay", false)
|
|
176
|
+
|
|
177
|
+
val eventUri = implementation.createEvent(context, title, calendarId, location, startDate, endDate, isAllDay)
|
|
178
|
+
val ret = JSObject()
|
|
179
|
+
ret.put("eventCreated", eventUri != null)
|
|
180
|
+
call.resolve(ret)
|
|
181
|
+
} catch (error: Exception) {
|
|
182
|
+
call.reject("", "[CapacitorCalendar.${::createEvent.name}] Unable to create event")
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
}
|
|
164
186
|
}
|