react-native-rook-sdk 0.6.2 → 0.7.1
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.
- package/android/build.gradle +1 -1
- package/android/src/main/AndroidManifestNew.xml +0 -8
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +121 -55
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +36 -0
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +35 -0
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +44 -0
- package/android/src/main/java/com/rooksdk/{RookDateTime.kt → utils/RookDateTime.kt} +1 -1
- package/ios/RookSdk.mm +104 -41
- package/lib/commonjs/context/RookSyncGateProvider.js +2 -1
- package/lib/commonjs/context/RookSyncGateProvider.js.map +1 -1
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +5 -2
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/commonjs/hooks/useRookConfiguration.js +19 -15
- package/lib/commonjs/hooks/useRookConfiguration.js.map +1 -1
- package/lib/commonjs/hooks/useRookDataSources.js +13 -1
- package/lib/commonjs/hooks/useRookDataSources.js.map +1 -1
- package/lib/commonjs/hooks/useRookEvents.js +37 -32
- package/lib/commonjs/hooks/useRookEvents.js.map +1 -1
- package/lib/commonjs/hooks/useRookPermissions.js +50 -34
- package/lib/commonjs/hooks/useRookPermissions.js.map +1 -1
- package/lib/commonjs/hooks/useRookSummaries.js +15 -11
- package/lib/commonjs/hooks/useRookSummaries.js.map +1 -1
- package/lib/commonjs/index.js +20 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/hook/useRookAutoSync.js +66 -15
- package/lib/commonjs/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/commonjs/modules/types/sendMessageBroadcast.js +2 -0
- package/lib/commonjs/modules/types/sendMessageBroadcast.js.map +1 -0
- package/lib/module/context/RookSyncGateProvider.js +2 -1
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +5 -2
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +4 -1
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookDataSources.js +13 -1
- package/lib/module/hooks/useRookDataSources.js.map +1 -1
- package/lib/module/hooks/useRookEvents.js +5 -1
- package/lib/module/hooks/useRookEvents.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +32 -17
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSummaries.js +5 -1
- package/lib/module/hooks/useRookSummaries.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/hook/useRookAutoSync.js +67 -16
- package/lib/module/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/module/modules/types/sendMessageBroadcast.js +2 -0
- package/lib/module/modules/types/sendMessageBroadcast.js.map +1 -0
- package/lib/typescript/src/context/RookSyncGateProvider.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts +2 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookEvents.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +6 -3
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSummaries.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts +2 -1
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts.map +1 -1
- package/lib/typescript/src/modules/types/sendMessageBroadcast.d.ts +6 -0
- package/lib/typescript/src/modules/types/sendMessageBroadcast.d.ts.map +1 -0
- package/lib/typescript/src/types/DataSource.d.ts +1 -0
- package/lib/typescript/src/types/DataSource.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-rook-sdk.podspec +1 -1
- package/android/src/main/java/com/rooksdk/HealthConnectPermissionsActivity.kt +0 -40
- package/android/src/main/res/layout/activity_health_connect_permissions.xml +0 -15
package/android/build.gradle
CHANGED
|
@@ -90,6 +90,6 @@ dependencies {
|
|
|
90
90
|
//noinspection GradleDynamicVersion
|
|
91
91
|
implementation "com.facebook.react:react-native:+"
|
|
92
92
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
93
|
-
implementation 'com.rookmotion.android:rook-sdk:1.
|
|
93
|
+
implementation 'com.rookmotion.android:rook-sdk:1.6.0'
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -33,12 +33,4 @@
|
|
|
33
33
|
<uses-permission android:name="android.permission.health.READ_NUTRITION"/>
|
|
34
34
|
<uses-permission android:name="android.permission.health.READ_MENSTRUATION"/>
|
|
35
35
|
<uses-permission android:name="android.permission.health.READ_POWER"/>
|
|
36
|
-
|
|
37
|
-
<application>
|
|
38
|
-
<activity
|
|
39
|
-
android:name=".HealthConnectPermissionsActivity"
|
|
40
|
-
android:theme="@style/HealthConnectTheme"
|
|
41
|
-
android:excludeFromRecents="true"
|
|
42
|
-
android:exported="false"/>
|
|
43
|
-
</application>
|
|
44
36
|
</manifest>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package com.rooksdk
|
|
2
2
|
|
|
3
|
+
import android.content.IntentFilter
|
|
4
|
+
import androidx.core.content.ContextCompat
|
|
3
5
|
import com.facebook.react.bridge.Arguments
|
|
4
6
|
import com.facebook.react.bridge.Promise
|
|
5
7
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
@@ -11,21 +13,24 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
|
11
13
|
import com.rookmotion.rook.sdk.RookConfigurationManager
|
|
12
14
|
import com.rookmotion.rook.sdk.RookDataSources
|
|
13
15
|
import com.rookmotion.rook.sdk.RookEventManager
|
|
14
|
-
import com.rookmotion.rook.sdk.RookHealthPermissionsManager
|
|
15
16
|
import com.rookmotion.rook.sdk.RookHelpers
|
|
17
|
+
import com.rookmotion.rook.sdk.RookPermissionsManager
|
|
16
18
|
import com.rookmotion.rook.sdk.RookStepsManager
|
|
17
|
-
import com.rookmotion.rook.sdk.RookStepsPermissions
|
|
18
19
|
import com.rookmotion.rook.sdk.RookSummaryManager
|
|
19
20
|
import com.rookmotion.rook.sdk.RookYesterdaySyncManager
|
|
20
|
-
import com.rookmotion.rook.sdk.
|
|
21
|
+
import com.rookmotion.rook.sdk.domain.enums.HealthConnectAvailability
|
|
21
22
|
import com.rookmotion.rook.sdk.domain.environment.RookAndroidClass
|
|
22
23
|
import com.rookmotion.rook.sdk.domain.environment.RookEnvironment
|
|
23
24
|
import com.rookmotion.rook.sdk.domain.model.RookConfiguration
|
|
24
25
|
import com.rookmotion.rook.sdk.domain.enums.HealthDataType
|
|
25
|
-
import com.rookmotion.rook.sdk.domain.enums.
|
|
26
|
+
import com.rookmotion.rook.sdk.domain.enums.RequestPermissionsStatus
|
|
26
27
|
import com.rookmotion.rook.sdk.domain.enums.SyncStatus
|
|
27
28
|
import com.rookmotion.rook.sdk.domain.model.DataSource
|
|
28
29
|
import com.rookmotion.rook.sdk.domain.model.SyncStatusWithData
|
|
30
|
+
import com.rooksdk.broadcasts.AndroidPermissionsReceiverTransmitter
|
|
31
|
+
import com.rooksdk.broadcasts.HealthConnectPermissionsReceiverTransmitter
|
|
32
|
+
import com.rooksdk.utils.ReadableToWritable
|
|
33
|
+
import com.rooksdk.utils.RookDateTime
|
|
29
34
|
import kotlinx.coroutines.CoroutineScope
|
|
30
35
|
import kotlinx.coroutines.Dispatchers
|
|
31
36
|
import kotlinx.coroutines.SupervisorJob
|
|
@@ -36,7 +41,6 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
36
41
|
ReactContextBaseJavaModule(reactContext) {
|
|
37
42
|
|
|
38
43
|
private val rookConfigurationManager = RookConfigurationManager(reactApplicationContext)
|
|
39
|
-
private val rookHealthPermissionsManager = RookHealthPermissionsManager(rookConfigurationManager)
|
|
40
44
|
private val rookSummaryManager = RookSummaryManager(rookConfigurationManager)
|
|
41
45
|
private val rookEventManager = RookEventManager(rookConfigurationManager)
|
|
42
46
|
private var scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
@@ -54,12 +58,43 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
54
58
|
RookStepsManager(reactApplicationContext)
|
|
55
59
|
}
|
|
56
60
|
|
|
61
|
+
private val rookPermissionsManager: RookPermissionsManager by lazy {
|
|
62
|
+
RookPermissionsManager(reactApplicationContext)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private val androidPermissionsReceiverTransmitter: AndroidPermissionsReceiverTransmitter by lazy {
|
|
66
|
+
AndroidPermissionsReceiverTransmitter()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private val hcPermissionsReceiverTransmitter: HealthConnectPermissionsReceiverTransmitter by lazy {
|
|
70
|
+
HealthConnectPermissionsReceiverTransmitter()
|
|
71
|
+
}
|
|
72
|
+
|
|
57
73
|
override fun getName(): String {
|
|
58
74
|
return NAME
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
@ReactMethod
|
|
62
78
|
fun addListener(eventName: String) {
|
|
79
|
+
if (listenerCount == 0) {
|
|
80
|
+
androidPermissionsReceiverTransmitter.setReactApplicationContext(reactApplicationContext)
|
|
81
|
+
hcPermissionsReceiverTransmitter.setReactApplicationContext(reactApplicationContext)
|
|
82
|
+
|
|
83
|
+
ContextCompat.registerReceiver(
|
|
84
|
+
reactApplicationContext,
|
|
85
|
+
androidPermissionsReceiverTransmitter,
|
|
86
|
+
IntentFilter(RookPermissionsManager.ACTION_ANDROID_PERMISSIONS),
|
|
87
|
+
ContextCompat.RECEIVER_EXPORTED
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
ContextCompat.registerReceiver(
|
|
91
|
+
reactApplicationContext,
|
|
92
|
+
hcPermissionsReceiverTransmitter,
|
|
93
|
+
IntentFilter(RookPermissionsManager.ACTION_HEALTH_CONNECT_PERMISSIONS),
|
|
94
|
+
ContextCompat.RECEIVER_EXPORTED,
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
63
98
|
listenerCount += 1
|
|
64
99
|
}
|
|
65
100
|
|
|
@@ -68,6 +103,9 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
68
103
|
listenerCount -= count
|
|
69
104
|
if (listenerCount == 0) {
|
|
70
105
|
stepsScope.cancel()
|
|
106
|
+
|
|
107
|
+
reactApplicationContext.unregisterReceiver(hcPermissionsReceiverTransmitter)
|
|
108
|
+
reactApplicationContext.unregisterReceiver(androidPermissionsReceiverTransmitter)
|
|
71
109
|
}
|
|
72
110
|
}
|
|
73
111
|
|
|
@@ -95,7 +133,7 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
95
133
|
val map = Arguments.createMap()
|
|
96
134
|
map.putString("name", dataSource.name)
|
|
97
135
|
map.putString("description", dataSource.description)
|
|
98
|
-
map.putString("
|
|
136
|
+
map.putString("imageUrl", dataSource.image)
|
|
99
137
|
map.putBoolean("connected", dataSource.connected)
|
|
100
138
|
dataSource.authorizationUrl?.let {
|
|
101
139
|
map.putString("authorizationUrl", it)
|
|
@@ -105,21 +143,15 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
105
143
|
return array
|
|
106
144
|
}
|
|
107
145
|
|
|
108
|
-
private fun determineDoEndValue(permissionString: String): SyncInstruction {
|
|
109
|
-
return when (permissionString) {
|
|
110
|
-
"oldest" -> SyncInstruction.SYNC_OLDEST
|
|
111
|
-
"latest" -> SyncInstruction.SYNC_LATEST
|
|
112
|
-
else -> SyncInstruction.NOTHING
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
146
|
@ReactMethod
|
|
117
147
|
fun getUserID(promise: Promise) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
scope.launch {
|
|
149
|
+
try {
|
|
150
|
+
promise.resolve(rookConfigurationManager.getUserID())
|
|
151
|
+
}
|
|
152
|
+
catch (e: Exception) {
|
|
153
|
+
promise.reject(e)
|
|
154
|
+
}
|
|
123
155
|
}
|
|
124
156
|
}
|
|
125
157
|
|
|
@@ -217,10 +249,34 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
217
249
|
}
|
|
218
250
|
|
|
219
251
|
// MARK: - Permissions
|
|
252
|
+
@ReactMethod
|
|
253
|
+
fun shouldRequestPermissions(promise: Promise) {
|
|
254
|
+
val activity = reactApplicationContext.currentActivity
|
|
255
|
+
|
|
256
|
+
if (activity == null) {
|
|
257
|
+
promise.reject(Exception("Error trying to request permissions"))
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
val r = RookPermissionsManager.shouldRequestAndroidPermissions(activity)
|
|
263
|
+
promise.resolve(r)
|
|
264
|
+
}
|
|
265
|
+
catch (e: Exception) {
|
|
266
|
+
promise.reject(e)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
220
270
|
@ReactMethod
|
|
221
271
|
fun checkAvailability(promise: Promise) {
|
|
222
272
|
|
|
223
|
-
|
|
273
|
+
val r = rookPermissionsManager.checkHealthConnectAvailability()
|
|
274
|
+
|
|
275
|
+
when(r) {
|
|
276
|
+
HealthConnectAvailability.INSTALLED -> promise.resolve("INSTALED")
|
|
277
|
+
HealthConnectAvailability.NOT_INSTALLED -> promise.resolve("NOT_INSTALED")
|
|
278
|
+
HealthConnectAvailability.NOT_SUPPORTED -> promise.resolve("NOT_SUPPORTED")
|
|
279
|
+
}
|
|
224
280
|
|
|
225
281
|
}
|
|
226
282
|
|
|
@@ -228,7 +284,7 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
228
284
|
fun openHealthConnectSettings(promise: Promise) {
|
|
229
285
|
scope.launch {
|
|
230
286
|
|
|
231
|
-
val result =
|
|
287
|
+
val result = rookPermissionsManager.openHealthConnectSettings()
|
|
232
288
|
|
|
233
289
|
result.fold({
|
|
234
290
|
promise.resolve(true)
|
|
@@ -242,7 +298,7 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
242
298
|
@ReactMethod
|
|
243
299
|
fun checkPermissions(promise: Promise) {
|
|
244
300
|
scope.launch {
|
|
245
|
-
val result =
|
|
301
|
+
val result = rookPermissionsManager.checkHealthConnectPermissions()
|
|
246
302
|
|
|
247
303
|
result.fold({
|
|
248
304
|
promise.resolve(it)
|
|
@@ -254,26 +310,22 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
254
310
|
|
|
255
311
|
@ReactMethod
|
|
256
312
|
fun requestPermissions(promise: Promise) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
catch (e: Exception) {
|
|
271
|
-
promise.reject(e)
|
|
313
|
+
scope.launch {
|
|
314
|
+
rookPermissionsManager.requestHealthConnectPermissions().fold({
|
|
315
|
+
when(it) {
|
|
316
|
+
RequestPermissionsStatus.REQUEST_SENT -> {
|
|
317
|
+
promise.resolve("REQUEST_SENT")
|
|
318
|
+
}
|
|
319
|
+
RequestPermissionsStatus .ALREADY_GRANTED -> {
|
|
320
|
+
promise.resolve("ALREADY_GRANTED")
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}, {
|
|
324
|
+
promise.reject(it)
|
|
325
|
+
})
|
|
272
326
|
}
|
|
273
|
-
|
|
274
327
|
}
|
|
275
328
|
|
|
276
|
-
|
|
277
329
|
// MARK: - Sync Summaries
|
|
278
330
|
@ReactMethod
|
|
279
331
|
fun shouldSyncFor(summaryString: String, date: String,promise: Promise) {
|
|
@@ -519,21 +571,24 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
519
571
|
fun scheduleYesterdaySync(config: ReadableMap, promise: Promise) {
|
|
520
572
|
scope.launch {
|
|
521
573
|
try {
|
|
574
|
+
val clientUUID = config.getString("clientUUID")?.trim() ?: return@launch
|
|
575
|
+
val secretKey = config.getString("clientPassword")?.trim() ?: return@launch
|
|
576
|
+
|
|
577
|
+
if (clientUUID.isBlank() || secretKey.isBlank()) return@launch
|
|
578
|
+
|
|
522
579
|
var environment = RookEnvironment.SANDBOX
|
|
523
580
|
|
|
524
581
|
if (config.getString("environment") == "production")
|
|
525
582
|
environment = RookEnvironment.PRODUCTION
|
|
526
583
|
|
|
527
|
-
val doEnd = determineDoEndValue(config.getString("doOnEnd") ?: "")
|
|
528
|
-
|
|
529
584
|
rookSynManager.scheduleYesterdaySync(
|
|
530
585
|
enableLogs = true,
|
|
531
|
-
clientUUID =
|
|
532
|
-
secretKey =
|
|
586
|
+
clientUUID = clientUUID,
|
|
587
|
+
secretKey = secretKey,
|
|
533
588
|
environment = environment,
|
|
534
|
-
doOnEnd = doEnd
|
|
535
589
|
)
|
|
536
590
|
|
|
591
|
+
|
|
537
592
|
promise.resolve(true)
|
|
538
593
|
|
|
539
594
|
}
|
|
@@ -547,8 +602,11 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
547
602
|
@ReactMethod
|
|
548
603
|
fun requestAndroidBackgroundPermissions(promise: Promise) {
|
|
549
604
|
try {
|
|
550
|
-
|
|
551
|
-
|
|
605
|
+
val response = rookPermissionsManager.requestAndroidPermissions()
|
|
606
|
+
|
|
607
|
+
if (response == RequestPermissionsStatus.REQUEST_SENT)
|
|
608
|
+
promise.resolve("REQUEST_SENT")
|
|
609
|
+
else promise.resolve("ALREADY_GRANTED")
|
|
552
610
|
}
|
|
553
611
|
catch (e: Exception) {
|
|
554
612
|
promise.reject(e)
|
|
@@ -558,7 +616,7 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
558
616
|
@ReactMethod
|
|
559
617
|
fun hasAndroidBackgroundPermissions(promise: Promise) {
|
|
560
618
|
try {
|
|
561
|
-
val result =
|
|
619
|
+
val result = rookPermissionsManager.checkAndroidPermissions()
|
|
562
620
|
promise.resolve(result)
|
|
563
621
|
}
|
|
564
622
|
catch (e: Exception) {
|
|
@@ -569,18 +627,12 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
569
627
|
// MARK: - Steps
|
|
570
628
|
@ReactMethod
|
|
571
629
|
fun isStepsAvailable(promise: Promise) {
|
|
572
|
-
promise.resolve(
|
|
630
|
+
promise.resolve(rookStepsManager.isAvailable())
|
|
573
631
|
}
|
|
574
632
|
|
|
575
633
|
@ReactMethod
|
|
576
634
|
fun hasStepsPermissions(promise: Promise) {
|
|
577
|
-
promise.resolve(
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
@ReactMethod
|
|
581
|
-
fun requestStepsPermissions(promise: Promise) {
|
|
582
|
-
RookStepsPermissions.requestPermissions(reactApplicationContext)
|
|
583
|
-
promise.resolve(true)
|
|
635
|
+
promise.resolve(rookPermissionsManager.checkAndroidPermissions())
|
|
584
636
|
}
|
|
585
637
|
|
|
586
638
|
@ReactMethod
|
|
@@ -683,6 +735,20 @@ class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
|
683
735
|
})
|
|
684
736
|
}
|
|
685
737
|
|
|
738
|
+
@ReactMethod
|
|
739
|
+
fun sendMessageToBroadcast(message: ReadableMap, promise: Promise) {
|
|
740
|
+
if (listenerCount <= 0) return
|
|
741
|
+
|
|
742
|
+
val hash = ReadableToWritable.readableMapToHashMap(message)
|
|
743
|
+
val writable = ReadableToWritable.hashMapToWritableMap(hash)
|
|
744
|
+
|
|
745
|
+
reactApplicationContext
|
|
746
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
747
|
+
.emit("ROOK_NOTIFICATION", writable)
|
|
748
|
+
|
|
749
|
+
promise.resolve(true)
|
|
750
|
+
}
|
|
751
|
+
|
|
686
752
|
companion object {
|
|
687
753
|
const val NAME = "RookSdk"
|
|
688
754
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.rooksdk.broadcasts
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.Intent
|
|
6
|
+
import com.facebook.react.bridge.Arguments
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
9
|
+
import com.rookmotion.rook.sdk.RookPermissionsManager
|
|
10
|
+
|
|
11
|
+
class AndroidPermissionsReceiverTransmitter: BroadcastReceiver() {
|
|
12
|
+
private var reactApplicationContext: ReactApplicationContext? = null
|
|
13
|
+
|
|
14
|
+
override fun onReceive(context: Context?, intent: Intent?) {
|
|
15
|
+
val permissionsGranted = intent?.getBooleanExtra(
|
|
16
|
+
/* name = */ RookPermissionsManager.EXTRA_ANDROID_PERMISSIONS_GRANTED,
|
|
17
|
+
/* defaultValue = */ false
|
|
18
|
+
) ?: false
|
|
19
|
+
|
|
20
|
+
if (reactApplicationContext == null) return
|
|
21
|
+
|
|
22
|
+
val params = Arguments.createMap().apply {
|
|
23
|
+
putString("type", "ROOK_BACKGROUND_ANDROID_PERMISSIONS")
|
|
24
|
+
putBoolean("value", permissionsGranted)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
reactApplicationContext!!
|
|
28
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
29
|
+
.emit("ROOK_NOTIFICATION", params)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun setReactApplicationContext(context: ReactApplicationContext) {
|
|
33
|
+
this.reactApplicationContext = context
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.rooksdk.broadcasts
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.content.Intent
|
|
6
|
+
import com.facebook.react.bridge.Arguments
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
9
|
+
import com.rookmotion.rook.sdk.RookPermissionsManager
|
|
10
|
+
|
|
11
|
+
class HealthConnectPermissionsReceiverTransmitter: BroadcastReceiver() {
|
|
12
|
+
private var reactApplicationContext: ReactApplicationContext? = null
|
|
13
|
+
|
|
14
|
+
override fun onReceive(context: Context?, intent: Intent?) {
|
|
15
|
+
val permissionsGranted = intent?.getBooleanExtra(
|
|
16
|
+
/* name = */ RookPermissionsManager.EXTRA_HEALTH_CONNECT_PERMISSIONS_GRANTED,
|
|
17
|
+
/* defaultValue = */ false
|
|
18
|
+
) ?: false
|
|
19
|
+
|
|
20
|
+
if (reactApplicationContext == null) return
|
|
21
|
+
|
|
22
|
+
val params = Arguments.createMap().apply {
|
|
23
|
+
putString("type", "ROOK_HEALTH_CONNECT_PERMISSIONS")
|
|
24
|
+
putBoolean("value", permissionsGranted)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
reactApplicationContext!!
|
|
28
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
29
|
+
.emit("ROOK_NOTIFICATION", params)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun setReactApplicationContext(context: ReactApplicationContext) {
|
|
33
|
+
this.reactApplicationContext = context
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.rooksdk.utils
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
import com.facebook.react.bridge.ReadableType
|
|
6
|
+
import com.facebook.react.bridge.WritableMap
|
|
7
|
+
|
|
8
|
+
object ReadableToWritable {
|
|
9
|
+
fun readableMapToHashMap(readableMap: ReadableMap): HashMap<String, Any> {
|
|
10
|
+
val map = HashMap<String, Any>()
|
|
11
|
+
val iterator = readableMap.keySetIterator()
|
|
12
|
+
|
|
13
|
+
while (iterator.hasNextKey()) {
|
|
14
|
+
val key = iterator.nextKey()
|
|
15
|
+
when (readableMap.getType(key)) {
|
|
16
|
+
ReadableType.Boolean -> map[key] = readableMap.getBoolean(key)
|
|
17
|
+
ReadableType.Number -> map[key] = readableMap.getDouble(key)
|
|
18
|
+
ReadableType.String -> map[key] = readableMap.getString(key) ?: ""
|
|
19
|
+
ReadableType.Map -> map[key] = readableMapToHashMap(readableMap.getMap(key)!!)
|
|
20
|
+
ReadableType.Array -> map[key] = readableMap.getArray(key)!!.toArrayList()
|
|
21
|
+
else -> {} // Manejar otros tipos si es necesario
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return map
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fun hashMapToWritableMap(hashMap: HashMap<String, Any>): WritableMap {
|
|
29
|
+
val writableMap = Arguments.createMap()
|
|
30
|
+
|
|
31
|
+
for ((key, value) in hashMap) {
|
|
32
|
+
when (value) {
|
|
33
|
+
is Boolean -> writableMap.putBoolean(key, value)
|
|
34
|
+
is Double -> writableMap.putDouble(key, value)
|
|
35
|
+
is String -> writableMap.putString(key, value)
|
|
36
|
+
is HashMap<*, *> -> writableMap.putMap(key, hashMapToWritableMap(value as HashMap<String, Any>))
|
|
37
|
+
is ArrayList<*> -> writableMap.putArray(key, Arguments.fromArray(value))
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return writableMap
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|