also looking at this
feat(android): getCalendarEvents and createCalendarEvent in Zig — ratchet 86 → 84
#158
7 files
+1167
-20
| @@ -108,6 +108,8 @@ object CraftNative { | ||
| 108 | 108 | private external fun nativeCancelNotification(activity: Activity, id: String): Boolean |
| 109 | 109 | private external fun nativeCancelAllNotifications(activity: Activity): Boolean |
| 110 | 110 | private external fun nativeDeleteCalendarEvent(activity: Activity, eventId: String): Boolean |
| 111 | private external fun nativeGetCalendarEvents(activity: Activity, startDateMs: Long, endDateMs: Long): Boolean | |
| 112 | private external fun nativeCreateCalendarEvent(activity: Activity, eventJson: String): Boolean | |
| 111 | 113 | |
| 112 | 114 | /** |
| 113 | 115 | * `getDeviceInfo`, or null to use the Kotlin implementation. |
| @@ -350,4 +352,37 @@ object CraftNative { | ||
| 350 | 352 | false |
| 351 | 353 | } |
| 352 | 354 | } |
| 355 | ||
| 356 | /** | |
| 357 | * Returns whether Zig took the action, not whether the read found anything. | |
| 358 | * | |
| 359 | * An empty calendar still answers — with `[]`, through the reply channel — | |
| 360 | * so a false here means Zig did not run, never that there was nothing to | |
| 361 | * report. | |
| 362 | */ | |
| 363 | fun getCalendarEvents(activity: Activity, startDateMs: Long, endDateMs: Long): Boolean { | |
| 364 | if (!isAvailable) return false | |
| 365 | return try { | |
| 366 | nativeGetCalendarEvents(activity, startDateMs, endDateMs) | |
| 367 | } catch (e: UnsatisfiedLinkError) { | |
| 368 | false | |
| 369 | } | |
| 370 | } | |
| 371 | ||
| 372 | /** | |
| 373 | * Returns whether Zig took the action. | |
| 374 | * | |
| 375 | * A false here is routine rather than exceptional: Zig serves the shape | |
| 376 | * `NewCalendarEvent` declares and hands anything else back, because | |
| 377 | * `org.json` coerces where a strict parser refuses. The Kotlin below is | |
| 378 | * what answers those. | |
| 379 | */ | |
| 380 | fun createCalendarEvent(activity: Activity, eventJson: String): Boolean { | |
| 381 | if (!isAvailable) return false | |
| 382 | return try { | |
| 383 | nativeCreateCalendarEvent(activity, eventJson) | |
| 384 | } catch (e: UnsatisfiedLinkError) { | |
| 385 | false | |
| 386 | } | |
| 387 | } | |
| 353 | 388 | } |