@cap-kit/people 8.0.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.
Files changed (42) hide show
  1. package/CapKitPeople.podspec +20 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +1177 -0
  5. package/android/build.gradle +101 -0
  6. package/android/src/main/AndroidManifest.xml +4 -0
  7. package/android/src/main/java/io/capkit/people/PeopleImpl.kt +1003 -0
  8. package/android/src/main/java/io/capkit/people/PeopleObserver.kt +80 -0
  9. package/android/src/main/java/io/capkit/people/PeoplePlugin.kt +766 -0
  10. package/android/src/main/java/io/capkit/people/config/PeopleConfig.kt +44 -0
  11. package/android/src/main/java/io/capkit/people/error/PeopleError.kt +90 -0
  12. package/android/src/main/java/io/capkit/people/error/PeopleErrorMessages.kt +39 -0
  13. package/android/src/main/java/io/capkit/people/logger/PeopleLogger.kt +85 -0
  14. package/android/src/main/java/io/capkit/people/models/ContactModels.kt +64 -0
  15. package/android/src/main/java/io/capkit/people/utils/PeopleUtils.kt +133 -0
  16. package/android/src/main/res/.gitkeep +0 -0
  17. package/dist/docs.json +1449 -0
  18. package/dist/esm/definitions.d.ts +775 -0
  19. package/dist/esm/definitions.js +31 -0
  20. package/dist/esm/definitions.js.map +1 -0
  21. package/dist/esm/index.d.ts +15 -0
  22. package/dist/esm/index.js +18 -0
  23. package/dist/esm/index.js.map +1 -0
  24. package/dist/esm/web.d.ts +120 -0
  25. package/dist/esm/web.js +252 -0
  26. package/dist/esm/web.js.map +1 -0
  27. package/dist/plugin.cjs +300 -0
  28. package/dist/plugin.cjs.map +1 -0
  29. package/dist/plugin.js +303 -0
  30. package/dist/plugin.js.map +1 -0
  31. package/ios/Sources/PeoplePlugin/PeopleImpl.swift +463 -0
  32. package/ios/Sources/PeoplePlugin/PeoplePlugin.swift +627 -0
  33. package/ios/Sources/PeoplePlugin/PrivacyInfo.xcprivacy +13 -0
  34. package/ios/Sources/PeoplePlugin/Utils/PeopleUtils.swift +120 -0
  35. package/ios/Sources/PeoplePlugin/Version.swift +16 -0
  36. package/ios/Sources/PeoplePlugin/config/PeopleConfig.swift +56 -0
  37. package/ios/Sources/PeoplePlugin/error/PeopleError.swift +89 -0
  38. package/ios/Sources/PeoplePlugin/error/PeopleErrorMessages.swift +25 -0
  39. package/ios/Sources/PeoplePlugin/logger/PeopleLogging.swift +69 -0
  40. package/ios/Sources/PeoplePlugin/models/ContactModels.swift +68 -0
  41. package/ios/Tests/PeoplePluginTests/PeoplePluginTests.swift +10 -0
  42. package/package.json +119 -0
@@ -0,0 +1,80 @@
1
+ package io.capkit.people
2
+
3
+ import android.database.ContentObserver
4
+ import android.net.Uri
5
+ import android.os.Handler
6
+ import android.os.Looper
7
+ import android.os.SystemClock
8
+ import android.provider.ContactsContract
9
+
10
+ /**
11
+ * ContentObserver implementation for monitoring changes in the Android Contacts database.
12
+ * * This class observes the ContactsContract URI and triggers a callback when insertions,
13
+ * updates, or deletions are detected.
14
+ */
15
+ class PeopleObserver(
16
+ private val onChangeCallback: (type: String, ids: List<String>?) -> Unit,
17
+ ) : ContentObserver(Handler(Looper.getMainLooper())) {
18
+ companion object {
19
+ private const val SETTLE_WINDOW_MS = 350L
20
+
21
+ /**
22
+ * The base URI for contacts that this observer targets.
23
+ */
24
+ val CONTACTS_URI: Uri = ContactsContract.Contacts.CONTENT_URI
25
+ }
26
+
27
+ private val debounceHandler = Handler(Looper.getMainLooper())
28
+ private val pendingIds = linkedSetOf<String>()
29
+ private var hasGeneralChange = false
30
+ private var lastChangeAtMs = 0L
31
+
32
+ private val dispatchRunnable =
33
+ object : Runnable {
34
+ override fun run() {
35
+ val now = SystemClock.elapsedRealtime()
36
+ val elapsed = now - lastChangeAtMs
37
+ if (elapsed < SETTLE_WINDOW_MS) {
38
+ debounceHandler.postDelayed(this, SETTLE_WINDOW_MS - elapsed)
39
+ return
40
+ }
41
+
42
+ val ids = if (hasGeneralChange) null else pendingIds.toList()
43
+ pendingIds.clear()
44
+ hasGeneralChange = false
45
+ onChangeCallback("update", ids)
46
+ }
47
+ }
48
+
49
+ // -----------------------------------------------------------------------------
50
+ // Lifecycle / Callbacks
51
+ // -----------------------------------------------------------------------------
52
+
53
+ /**
54
+ * Called when a content change occurs.
55
+ *
56
+ * @param selfChange True if this is a self-triggered change.
57
+ * @param uri The URI of the changed content.
58
+ */
59
+ override fun onChange(
60
+ selfChange: Boolean,
61
+ uri: Uri?,
62
+ ) {
63
+ lastChangeAtMs = SystemClock.elapsedRealtime()
64
+
65
+ // If URI is null, emit a coalesced general update without specific IDs.
66
+ if (uri == null) {
67
+ hasGeneralChange = true
68
+ } else {
69
+ // Attempt to extract the specific contact ID from the URI segment.
70
+ uri.lastPathSegment?.let { pendingIds.add(it) }
71
+ }
72
+
73
+ debounceHandler.removeCallbacks(dispatchRunnable)
74
+ debounceHandler.postDelayed(dispatchRunnable, SETTLE_WINDOW_MS)
75
+ }
76
+
77
+ fun dispose() {
78
+ debounceHandler.removeCallbacks(dispatchRunnable)
79
+ }
80
+ }