@ebarooni/capacitor-calendar 8.3.0 → 8.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 +179 -71
- 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 +439 -51
- package/dist/esm/index.d.ts +8 -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/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 +15 -1
- 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.d.ts +15 -21
- package/dist/esm/web.js +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +9 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +9 -1
- 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
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> {
|