ReviewOS

also looking at this

craft-native/craft

feat(android): the contacts pair in Zig — ratchet 79 → 77

#166
Merged chris wants to merge feat/android-contacts into main
7 files +974 -3
packages/android/templates/CraftNative.kt.templatemodified+33-0
Changes to packages/android/templates/CraftNative.kt.template
@@ -116,6 +116,8 @@ object CraftNative {
116116 private external fun nativeSetSharedItem(activity: Activity, key: String, value: String, group: String): Boolean
117117 private external fun nativeGetSharedItem(activity: Activity, key: String, group: String): Boolean
118118 private external fun nativeRemoveSharedItem(activity: Activity, key: String, group: String): Boolean
119 private external fun nativeGetContacts(activity: Activity): Boolean
120 private external fun nativeAddContact(activity: Activity, contactJson: String): Boolean
119121
120122 /**
121123 * `getDeviceInfo`, or null to use the Kotlin implementation.
@@ -450,4 +452,35 @@ object CraftNative {
450452 false
451453 }
452454 }
455
456 /**
457 * Returns whether Zig took the read, not whether it found anyone.
458 *
459 * An empty address book still answers — with `[]`, through the reply
460 * channel — so a false here means Zig did not run.
461 */
462 fun getContacts(activity: Activity): Boolean {
463 if (!isAvailable) return false
464 return try {
465 nativeGetContacts(activity)
466 } catch (e: UnsatisfiedLinkError) {
467 false
468 }
469 }
470
471 /**
472 * Returns whether Zig took the write.
473 *
474 * A false is routine rather than exceptional: Zig serves the shape the
475 * page's own SDK sends and hands anything else back, because `org.json`
476 * coerces where a strict parser refuses.
477 */
478 fun addContact(activity: Activity, contactJson: String): Boolean {
479 if (!isAvailable) return false
480 return try {
481 nativeAddContact(activity, contactJson)
482 } catch (e: UnsatisfiedLinkError) {
483 false
484 }
485 }
453486}