also looking at this
feat(android): the contacts pair in Zig — ratchet 79 → 77
#166
7 files
+974
-3
| @@ -116,6 +116,8 @@ object CraftNative { | ||
| 116 | 116 | private external fun nativeSetSharedItem(activity: Activity, key: String, value: String, group: String): Boolean |
| 117 | 117 | private external fun nativeGetSharedItem(activity: Activity, key: String, group: String): Boolean |
| 118 | 118 | 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 | |
| 119 | 121 | |
| 120 | 122 | /** |
| 121 | 123 | * `getDeviceInfo`, or null to use the Kotlin implementation. |
| @@ -450,4 +452,35 @@ object CraftNative { | ||
| 450 | 452 | false |
| 451 | 453 | } |
| 452 | 454 | } |
| 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 | } | |
| 453 | 486 | } |