ReviewOS

also looking at this

craft-native/craft

feat(android): getCalendarEvents and createCalendarEvent in Zig — ratchet 86 → 84

#158
Merged glennmichael123 wants to merge feat/android-calendar-events into main
7 files +1167 -20
packages/android/templates/CraftNative.kt.templatemodified+35-0
Changes to packages/android/templates/CraftNative.kt.template
@@ -108,6 +108,8 @@ object CraftNative {
108108 private external fun nativeCancelNotification(activity: Activity, id: String): Boolean
109109 private external fun nativeCancelAllNotifications(activity: Activity): Boolean
110110 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
111113
112114 /**
113115 * `getDeviceInfo`, or null to use the Kotlin implementation.
@@ -350,4 +352,37 @@ object CraftNative {
350352 false
351353 }
352354 }
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 }
353388}