react-native-rook-sdk 0.2.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.
- package/LICENSE +20 -0
- package/README.md +31 -0
- package/android/build.gradle +95 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +38 -0
- package/android/src/main/java/com/rooksdk/HealthConnectPermissionsActivity.kt +45 -0
- package/android/src/main/java/com/rooksdk/RookDateTime.kt +12 -0
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +575 -0
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +17 -0
- package/android/src/main/res/drawable/ic_health_connect.xml +19 -0
- package/android/src/main/res/layout/activity_health_connect_permissions.xml +15 -0
- package/android/src/main/res/values/themes.xml +3 -0
- package/ios/RookSdk.h +13 -0
- package/ios/RookSdk.mm +568 -0
- package/lib/commonjs/context/RookSyncGateContext.js +19 -0
- package/lib/commonjs/context/RookSyncGateContext.js.map +1 -0
- package/lib/commonjs/context/RookSyncGateProvider.js +70 -0
- package/lib/commonjs/context/RookSyncGateProvider.js.map +1 -0
- package/lib/commonjs/context/RookSyncGateReducer.js +39 -0
- package/lib/commonjs/context/RookSyncGateReducer.js.map +1 -0
- package/lib/commonjs/context/RookSyncGateTypes.js +2 -0
- package/lib/commonjs/context/RookSyncGateTypes.js.map +1 -0
- package/lib/commonjs/context/index.js +14 -0
- package/lib/commonjs/context/index.js.map +1 -0
- package/lib/commonjs/hooks/index.js +48 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/hooks/useRookAppleHealth.js +143 -0
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +1 -0
- package/lib/commonjs/hooks/useRookConfiguration.js +90 -0
- package/lib/commonjs/hooks/useRookConfiguration.js.map +1 -0
- package/lib/commonjs/hooks/useRookEvents.js +239 -0
- package/lib/commonjs/hooks/useRookEvents.js.map +1 -0
- package/lib/commonjs/hooks/useRookHealthConnect.js +124 -0
- package/lib/commonjs/hooks/useRookHealthConnect.js.map +1 -0
- package/lib/commonjs/hooks/useRookPermissions.js +59 -0
- package/lib/commonjs/hooks/useRookPermissions.js.map +1 -0
- package/lib/commonjs/hooks/useRookSummaries.js +110 -0
- package/lib/commonjs/hooks/useRookSummaries.js.map +1 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/utils/credentials.js +11 -0
- package/lib/commonjs/utils/credentials.js.map +1 -0
- package/lib/commonjs/utils/getRookModule.js +21 -0
- package/lib/commonjs/utils/getRookModule.js.map +1 -0
- package/lib/commonjs/utils/index.js +63 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/isModuleReady.js +13 -0
- package/lib/commonjs/utils/isModuleReady.js.map +1 -0
- package/lib/commonjs/utils/isRunningOnAndroid.js +15 -0
- package/lib/commonjs/utils/isRunningOnAndroid.js.map +1 -0
- package/lib/commonjs/utils/isRunningOniOS.js +15 -0
- package/lib/commonjs/utils/isRunningOniOS.js.map +1 -0
- package/lib/commonjs/utils/isValidDate.js +14 -0
- package/lib/commonjs/utils/isValidDate.js.map +1 -0
- package/lib/commonjs/utils/loggerDescription.js +24 -0
- package/lib/commonjs/utils/loggerDescription.js.map +1 -0
- package/lib/commonjs/utils/packageInfo.js +13 -0
- package/lib/commonjs/utils/packageInfo.js.map +1 -0
- package/lib/module/context/RookSyncGateContext.js +11 -0
- package/lib/module/context/RookSyncGateContext.js.map +1 -0
- package/lib/module/context/RookSyncGateProvider.js +60 -0
- package/lib/module/context/RookSyncGateProvider.js.map +1 -0
- package/lib/module/context/RookSyncGateReducer.js +32 -0
- package/lib/module/context/RookSyncGateReducer.js.map +1 -0
- package/lib/module/context/RookSyncGateTypes.js +2 -0
- package/lib/module/context/RookSyncGateTypes.js.map +1 -0
- package/lib/module/context/index.js +2 -0
- package/lib/module/context/index.js.map +1 -0
- package/lib/module/hooks/index.js +7 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useRookAppleHealth.js +135 -0
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -0
- package/lib/module/hooks/useRookConfiguration.js +83 -0
- package/lib/module/hooks/useRookConfiguration.js.map +1 -0
- package/lib/module/hooks/useRookEvents.js +231 -0
- package/lib/module/hooks/useRookEvents.js.map +1 -0
- package/lib/module/hooks/useRookHealthConnect.js +116 -0
- package/lib/module/hooks/useRookHealthConnect.js.map +1 -0
- package/lib/module/hooks/useRookPermissions.js +52 -0
- package/lib/module/hooks/useRookPermissions.js.map +1 -0
- package/lib/module/hooks/useRookSummaries.js +102 -0
- package/lib/module/hooks/useRookSummaries.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/credentials.js +5 -0
- package/lib/module/utils/credentials.js.map +1 -0
- package/lib/module/utils/getRookModule.js +14 -0
- package/lib/module/utils/getRookModule.js.map +1 -0
- package/lib/module/utils/index.js +9 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/isModuleReady.js +6 -0
- package/lib/module/utils/isModuleReady.js.map +1 -0
- package/lib/module/utils/isRunningOnAndroid.js +8 -0
- package/lib/module/utils/isRunningOnAndroid.js.map +1 -0
- package/lib/module/utils/isRunningOniOS.js +8 -0
- package/lib/module/utils/isRunningOniOS.js.map +1 -0
- package/lib/module/utils/isValidDate.js +7 -0
- package/lib/module/utils/isValidDate.js.map +1 -0
- package/lib/module/utils/loggerDescription.js +17 -0
- package/lib/module/utils/loggerDescription.js.map +1 -0
- package/lib/module/utils/packageInfo.js +7 -0
- package/lib/module/utils/packageInfo.js.map +1 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts +11 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts.map +1 -0
- package/lib/typescript/src/context/RookSyncGateProvider.d.ts +11 -0
- package/lib/typescript/src/context/RookSyncGateProvider.d.ts.map +1 -0
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts +3 -0
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts.map +1 -0
- package/lib/typescript/src/context/RookSyncGateTypes.d.ts +26 -0
- package/lib/typescript/src/context/RookSyncGateTypes.d.ts.map +1 -0
- package/lib/typescript/src/context/index.d.ts +2 -0
- package/lib/typescript/src/context/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +7 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts +12 -0
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +12 -0
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookEvents.d.ts +17 -0
- package/lib/typescript/src/hooks/useRookEvents.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookHealthConnect.d.ts +12 -0
- package/lib/typescript/src/hooks/useRookHealthConnect.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +12 -0
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookSummaries.d.ts +15 -0
- package/lib/typescript/src/hooks/useRookSummaries.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/credentials.d.ts +5 -0
- package/lib/typescript/src/utils/credentials.d.ts.map +1 -0
- package/lib/typescript/src/utils/getRookModule.d.ts +2 -0
- package/lib/typescript/src/utils/getRookModule.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +9 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/isModuleReady.d.ts +2 -0
- package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -0
- package/lib/typescript/src/utils/isRunningOnAndroid.d.ts +3 -0
- package/lib/typescript/src/utils/isRunningOnAndroid.d.ts.map +1 -0
- package/lib/typescript/src/utils/isRunningOniOS.d.ts +2 -0
- package/lib/typescript/src/utils/isRunningOniOS.d.ts.map +1 -0
- package/lib/typescript/src/utils/isValidDate.d.ts +2 -0
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -0
- package/lib/typescript/src/utils/loggerDescription.d.ts +10 -0
- package/lib/typescript/src/utils/loggerDescription.d.ts.map +1 -0
- package/lib/typescript/src/utils/packageInfo.d.ts +6 -0
- package/lib/typescript/src/utils/packageInfo.d.ts.map +1 -0
- package/package.json +170 -0
- package/react-native-rook-sdk.podspec +43 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
package com.rooksdk
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import com.rookmotion.rook.sdk.RookConfigurationManager
|
|
11
|
+
import com.rookmotion.rook.sdk.RookEventManager
|
|
12
|
+
import com.rookmotion.rook.sdk.RookHealthPermissionsManager
|
|
13
|
+
import com.rookmotion.rook.sdk.RookHelpers
|
|
14
|
+
import com.rookmotion.rook.sdk.RookSummaryManager
|
|
15
|
+
import com.rookmotion.rook.sdk.domain.enums.HealthPermission
|
|
16
|
+
import com.rookmotion.rook.sdk.domain.environment.RookAndroidClass
|
|
17
|
+
import com.rookmotion.rook.sdk.domain.environment.RookEnvironment
|
|
18
|
+
import com.rookmotion.rook.sdk.domain.model.RookConfiguration
|
|
19
|
+
import com.rookmotion.rook.sdk.RookStepsTracker
|
|
20
|
+
import com.rookmotion.rook.sdk.domain.enums.HealthDataType
|
|
21
|
+
import com.rookmotion.rook.sdk.domain.model.SyncStatus
|
|
22
|
+
import kotlinx.coroutines.CoroutineScope
|
|
23
|
+
import kotlinx.coroutines.Dispatchers
|
|
24
|
+
import kotlinx.coroutines.SupervisorJob
|
|
25
|
+
import kotlinx.coroutines.cancel
|
|
26
|
+
import kotlinx.coroutines.launch
|
|
27
|
+
|
|
28
|
+
class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
29
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
30
|
+
|
|
31
|
+
private val rookConfigurationManager = RookConfigurationManager(reactApplicationContext)
|
|
32
|
+
private val rookHealthPermissionsManager = RookHealthPermissionsManager(rookConfigurationManager)
|
|
33
|
+
private val rookSummaryManager = RookSummaryManager(rookConfigurationManager)
|
|
34
|
+
private val rookEventManager = RookEventManager(rookConfigurationManager)
|
|
35
|
+
private var scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
36
|
+
private var stepsScope: CoroutineScope? = null
|
|
37
|
+
private var listenerCount = 0
|
|
38
|
+
|
|
39
|
+
override fun getName(): String {
|
|
40
|
+
return NAME
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ReactMethod
|
|
44
|
+
fun addListener(eventName: String) {
|
|
45
|
+
listenerCount += 1
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ReactMethod
|
|
49
|
+
fun removeListeners(count: Int) {
|
|
50
|
+
listenerCount -= count
|
|
51
|
+
if (listenerCount == 0) {
|
|
52
|
+
stepsScope?.cancel()
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private fun determinePermissionValue(permissionString: String): HealthPermission {
|
|
57
|
+
return when (permissionString) {
|
|
58
|
+
"SLEEP" -> HealthPermission.SLEEP
|
|
59
|
+
"PHYSICAL" -> HealthPermission.PHYSICAL
|
|
60
|
+
"BODY" -> HealthPermission.BODY
|
|
61
|
+
"ALL" -> HealthPermission.ALL
|
|
62
|
+
else -> HealthPermission.ALL
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
private fun determineSummaryValue(summaryString: String): HealthDataType {
|
|
66
|
+
return when (summaryString) {
|
|
67
|
+
"SLEEP" -> HealthDataType.SLEEP_SUMMARY
|
|
68
|
+
"PHYSICAL" -> HealthDataType.PHYSICAL_SUMMARY
|
|
69
|
+
"BODY" -> HealthDataType.BODY_SUMMARY
|
|
70
|
+
"BLOOD_GLUCOSE_EVENT" -> HealthDataType.BLOOD_GLUCOSE_BODY_EVENT
|
|
71
|
+
"BLOOD_PRESSURE_EVENT" -> HealthDataType.BLOOD_PRESSURE_BODY_EVENT
|
|
72
|
+
"BODY_METRICS_EVENT" -> HealthDataType.BODY_METRICS_EVENT
|
|
73
|
+
"HEART_RATE_EVENT" -> HealthDataType.HEART_RATE_BODY_EVENT
|
|
74
|
+
"HYDRATION_EVENT" -> HealthDataType.HYDRATION_BODY_EVENT
|
|
75
|
+
"NUTRITION_EVENT" -> HealthDataType.NUTRITION_BODY_EVENT
|
|
76
|
+
"OXYGENATION_EVENT" -> HealthDataType.OXYGENATION_BODY_EVENT
|
|
77
|
+
"PHYSICAL_EVENT" -> HealthDataType.PHYSICAL_EVENT
|
|
78
|
+
"TEMPERATURE_EVENT" -> HealthDataType.TEMPERATURE_BODY_EVENT
|
|
79
|
+
else -> HealthDataType.SLEEP_SUMMARY
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@ReactMethod
|
|
84
|
+
fun getUserID(promise: Promise) {
|
|
85
|
+
try {
|
|
86
|
+
promise.resolve(rookConfigurationManager.getUserID())
|
|
87
|
+
}
|
|
88
|
+
catch (e: Exception) {
|
|
89
|
+
promise.reject(e)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@ReactMethod
|
|
94
|
+
fun updateUserID(userID: String, promise: Promise) {
|
|
95
|
+
scope.launch {
|
|
96
|
+
try {
|
|
97
|
+
rookConfigurationManager.updateUserID(userID)
|
|
98
|
+
promise.resolve(true)
|
|
99
|
+
}
|
|
100
|
+
catch (e: Exception) {
|
|
101
|
+
promise.reject(e)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@ReactMethod
|
|
107
|
+
fun clearUserID(promise: Promise) {
|
|
108
|
+
try {
|
|
109
|
+
rookConfigurationManager.clearUserID()
|
|
110
|
+
promise.resolve(true)
|
|
111
|
+
}
|
|
112
|
+
catch (e: Exception) {
|
|
113
|
+
promise.reject(e)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@ReactMethod
|
|
119
|
+
fun removeUserFromRook(promise: Promise) {
|
|
120
|
+
scope.launch {
|
|
121
|
+
val result = rookConfigurationManager.deleteUserFromRook()
|
|
122
|
+
|
|
123
|
+
result.fold({
|
|
124
|
+
promise.resolve(true)
|
|
125
|
+
}, {
|
|
126
|
+
promise.reject(it)
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@ReactMethod
|
|
132
|
+
fun syncUserTimeZone(promise: Promise) {
|
|
133
|
+
scope.launch {
|
|
134
|
+
val result = rookConfigurationManager.syncUserTimeZone()
|
|
135
|
+
|
|
136
|
+
result.fold({
|
|
137
|
+
promise.resolve(true)
|
|
138
|
+
}, {
|
|
139
|
+
promise.reject(it)
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@ReactMethod
|
|
147
|
+
fun initRook(config: ReadableMap,promise: Promise) {
|
|
148
|
+
try {
|
|
149
|
+
|
|
150
|
+
var environment = RookEnvironment.SANDBOX
|
|
151
|
+
|
|
152
|
+
if (config.getString("environment") == "production")
|
|
153
|
+
environment = RookEnvironment.PRODUCTION
|
|
154
|
+
|
|
155
|
+
if (config.getString("environment") == "development") RookAndroidClass.test()
|
|
156
|
+
else RookAndroidClass.disableTest()
|
|
157
|
+
|
|
158
|
+
val rookConfiguration = RookConfiguration(
|
|
159
|
+
environment = environment,
|
|
160
|
+
clientUUID = config.getString("clientUUID") ?: "",
|
|
161
|
+
secretKey = config.getString("password") ?: ""
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
rookConfigurationManager.enableLocalLogs()
|
|
165
|
+
rookConfigurationManager.setConfiguration(rookConfiguration)
|
|
166
|
+
|
|
167
|
+
scope.launch {
|
|
168
|
+
val result = rookConfigurationManager.initRook()
|
|
169
|
+
|
|
170
|
+
result.fold(
|
|
171
|
+
{
|
|
172
|
+
promise.resolve(true)
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
promise.reject(it)
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (e: Exception) {
|
|
181
|
+
promise.reject(e)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// MARK: - Permissions
|
|
187
|
+
@ReactMethod
|
|
188
|
+
fun checkAvailability(promise: Promise) {
|
|
189
|
+
|
|
190
|
+
promise.resolve(RookHealthPermissionsManager.checkAvailability(reactApplicationContext).toString())
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@ReactMethod
|
|
195
|
+
fun openHealthConnectSettings(promise: Promise) {
|
|
196
|
+
scope.launch {
|
|
197
|
+
|
|
198
|
+
val result = rookHealthPermissionsManager.openHealthConnectSettings()
|
|
199
|
+
|
|
200
|
+
result.fold({
|
|
201
|
+
promise.resolve(true)
|
|
202
|
+
},{
|
|
203
|
+
promise.reject(it)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@ReactMethod
|
|
210
|
+
fun checkPermissions(permission: String, promise: Promise) {
|
|
211
|
+
scope.launch {
|
|
212
|
+
val result = rookHealthPermissionsManager.checkPermissions(determinePermissionValue(permission));
|
|
213
|
+
|
|
214
|
+
result.fold({
|
|
215
|
+
promise.resolve(it)
|
|
216
|
+
}, {
|
|
217
|
+
promise.reject(it)
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@ReactMethod
|
|
223
|
+
fun requestPermissions(permission: String, promise: Promise) {
|
|
224
|
+
val activity = reactApplicationContext.currentActivity
|
|
225
|
+
|
|
226
|
+
if (activity == null) {
|
|
227
|
+
promise.reject(Exception("Error trying to request permissions"))
|
|
228
|
+
return
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
|
|
233
|
+
HealthConnectPermissionsActivity.launch(activity, determinePermissionValue(permission))
|
|
234
|
+
promise.resolve(true)
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
catch (e: Exception) {
|
|
238
|
+
promise.reject(e)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
// MARK: - Sync Summaries
|
|
245
|
+
@ReactMethod
|
|
246
|
+
fun shouldSyncFor(summaryString: String, date: String,promise: Promise) {
|
|
247
|
+
scope.launch {
|
|
248
|
+
RookHelpers.shouldSyncFor(
|
|
249
|
+
healthDataType = determineSummaryValue(summaryString),
|
|
250
|
+
localDate = RookDateTime.stringToLocalDate(date)
|
|
251
|
+
).fold({
|
|
252
|
+
promise.resolve(it)
|
|
253
|
+
},{
|
|
254
|
+
promise.reject(it)
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Sleep
|
|
260
|
+
@ReactMethod
|
|
261
|
+
fun syncYesterdaySummaries(promise: Promise) {
|
|
262
|
+
scope.launch {
|
|
263
|
+
val result = rookSummaryManager.syncYesterdaySummaries();
|
|
264
|
+
|
|
265
|
+
promise.resolve(true);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@ReactMethod
|
|
270
|
+
fun syncSleepSummary(date: String, promise: Promise) {
|
|
271
|
+
scope.launch {
|
|
272
|
+
val result = rookSummaryManager.syncSleepSummary(RookDateTime.stringToLocalDate(date))
|
|
273
|
+
|
|
274
|
+
result.fold({
|
|
275
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
276
|
+
else promise.resolve(false)
|
|
277
|
+
}, {
|
|
278
|
+
promise.reject(it)
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Body
|
|
284
|
+
@ReactMethod
|
|
285
|
+
fun syncBodySummary(date: String, promise: Promise) {
|
|
286
|
+
scope.launch {
|
|
287
|
+
val result = rookSummaryManager.syncBodySummary(RookDateTime.stringToLocalDate(date))
|
|
288
|
+
|
|
289
|
+
result.fold({
|
|
290
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
291
|
+
else promise.resolve(false)
|
|
292
|
+
}, {
|
|
293
|
+
promise.reject(it)
|
|
294
|
+
})
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Physical
|
|
299
|
+
@ReactMethod
|
|
300
|
+
fun syncPhysicalSummary(date: String, promise: Promise) {
|
|
301
|
+
scope.launch {
|
|
302
|
+
val result = rookSummaryManager.syncPhysicalSummary(RookDateTime.stringToLocalDate(date))
|
|
303
|
+
|
|
304
|
+
result.fold({
|
|
305
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
306
|
+
else promise.resolve(false)
|
|
307
|
+
}, {
|
|
308
|
+
promise.reject(it)
|
|
309
|
+
})
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
@ReactMethod
|
|
314
|
+
fun syncPendingSummaries(promise: Promise) {
|
|
315
|
+
scope.launch {
|
|
316
|
+
val result = rookSummaryManager.syncPendingSummaries()
|
|
317
|
+
|
|
318
|
+
result.fold({
|
|
319
|
+
promise.resolve(true)
|
|
320
|
+
}, {
|
|
321
|
+
promise.reject(it)
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// MARK: - Events
|
|
327
|
+
|
|
328
|
+
@ReactMethod
|
|
329
|
+
fun syncYesterdayEvents(promise: Promise) {
|
|
330
|
+
scope.launch {
|
|
331
|
+
val result = rookEventManager.syncYesterdayEvents();
|
|
332
|
+
|
|
333
|
+
promise.resolve(true);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
@ReactMethod
|
|
337
|
+
fun syncPhysicalEvents(date: String, promise: Promise) {
|
|
338
|
+
scope.launch {
|
|
339
|
+
val result = rookEventManager.syncPhysicalEvents(RookDateTime.stringToLocalDate(date))
|
|
340
|
+
|
|
341
|
+
result.fold({
|
|
342
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
343
|
+
else promise.resolve(false)
|
|
344
|
+
}, {
|
|
345
|
+
promise.reject(it)
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
@ReactMethod
|
|
351
|
+
fun syncBloodGlucoseEvents(date: String, promise: Promise) {
|
|
352
|
+
scope.launch {
|
|
353
|
+
val result = rookEventManager.syncBloodGlucoseEvents(RookDateTime.stringToLocalDate(date))
|
|
354
|
+
|
|
355
|
+
result.fold({
|
|
356
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
357
|
+
else promise.resolve(false)
|
|
358
|
+
}, {
|
|
359
|
+
promise.reject(it)
|
|
360
|
+
})
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
@ReactMethod
|
|
365
|
+
fun syncBloodPressureEvents(date: String, promise: Promise) {
|
|
366
|
+
scope.launch {
|
|
367
|
+
val result = rookEventManager.syncBloodPressureEvents(RookDateTime.stringToLocalDate(date))
|
|
368
|
+
|
|
369
|
+
result.fold({
|
|
370
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
371
|
+
else promise.resolve(false)
|
|
372
|
+
}, {
|
|
373
|
+
promise.reject(it)
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
@ReactMethod
|
|
379
|
+
fun syncBodyMetricsEvent(date: String, promise: Promise) {
|
|
380
|
+
scope.launch {
|
|
381
|
+
val result = rookEventManager.syncBodyMetricsEvents(RookDateTime.stringToLocalDate(date))
|
|
382
|
+
|
|
383
|
+
result.fold({
|
|
384
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
385
|
+
else promise.resolve(false)
|
|
386
|
+
}, {
|
|
387
|
+
promise.reject(it)
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@ReactMethod
|
|
393
|
+
fun syncBodyHeartRateEvent(date: String, promise: Promise) {
|
|
394
|
+
scope.launch {
|
|
395
|
+
val result = rookEventManager.syncBodyHeartRateEvents(RookDateTime.stringToLocalDate(date))
|
|
396
|
+
|
|
397
|
+
result.fold({
|
|
398
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
399
|
+
else promise.resolve(false)
|
|
400
|
+
}, {
|
|
401
|
+
promise.reject(it)
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
@ReactMethod
|
|
407
|
+
fun syncPhysicalHeartRateEvent(date: String, promise: Promise) {
|
|
408
|
+
scope.launch {
|
|
409
|
+
val result = rookEventManager.syncPhysicalHeartRateEvents(RookDateTime.stringToLocalDate(date))
|
|
410
|
+
|
|
411
|
+
result.fold({
|
|
412
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
413
|
+
else promise.resolve(false)
|
|
414
|
+
}, {
|
|
415
|
+
promise.reject(it)
|
|
416
|
+
})
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
@ReactMethod
|
|
421
|
+
fun syncNutritionEvents(date: String, promise: Promise) {
|
|
422
|
+
scope.launch {
|
|
423
|
+
val result = rookEventManager.syncNutritionEvents(RookDateTime.stringToLocalDate(date))
|
|
424
|
+
|
|
425
|
+
result.fold({
|
|
426
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
427
|
+
else promise.resolve(false)
|
|
428
|
+
}, {
|
|
429
|
+
promise.reject(it)
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
@ReactMethod
|
|
435
|
+
fun syncHydrationEvents(date: String, promise: Promise) {
|
|
436
|
+
scope.launch {
|
|
437
|
+
val result = rookEventManager.syncHydrationEvents(RookDateTime.stringToLocalDate(date))
|
|
438
|
+
|
|
439
|
+
result.fold({
|
|
440
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
441
|
+
else promise.resolve(false)
|
|
442
|
+
}, {
|
|
443
|
+
promise.reject(it)
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
@ReactMethod
|
|
448
|
+
fun syncPhysicalOxygenationEvent(date: String, promise: Promise) {
|
|
449
|
+
scope.launch {
|
|
450
|
+
val result = rookEventManager.syncPhysicalOxygenationEvents(RookDateTime.stringToLocalDate(date))
|
|
451
|
+
|
|
452
|
+
result.fold({
|
|
453
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
454
|
+
else promise.resolve(false)
|
|
455
|
+
}, {
|
|
456
|
+
promise.reject(it)
|
|
457
|
+
})
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
@ReactMethod
|
|
462
|
+
fun syncBodyOxygenationEvent(date: String, promise: Promise) {
|
|
463
|
+
scope.launch {
|
|
464
|
+
val result = rookEventManager.syncBodyOxygenationEvents(RookDateTime.stringToLocalDate(date))
|
|
465
|
+
|
|
466
|
+
result.fold({
|
|
467
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
468
|
+
else promise.resolve(false)
|
|
469
|
+
}, {
|
|
470
|
+
promise.reject(it)
|
|
471
|
+
})
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
@ReactMethod
|
|
476
|
+
fun syncTemperatureEvent(date: String, promise: Promise) {
|
|
477
|
+
scope.launch {
|
|
478
|
+
val result = rookEventManager.syncTemperatureEvents(RookDateTime.stringToLocalDate(date))
|
|
479
|
+
|
|
480
|
+
result.fold({
|
|
481
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
482
|
+
else promise.resolve(false)
|
|
483
|
+
}, {
|
|
484
|
+
promise.reject(it)
|
|
485
|
+
})
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
@ReactMethod
|
|
490
|
+
fun syncPendingEvents(promise: Promise) {
|
|
491
|
+
scope.launch {
|
|
492
|
+
val result = rookEventManager.syncPendingEvents()
|
|
493
|
+
|
|
494
|
+
result.fold({
|
|
495
|
+
promise.resolve(true)
|
|
496
|
+
}, {
|
|
497
|
+
promise.reject(it)
|
|
498
|
+
})
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// MARK: - Steps
|
|
503
|
+
@ReactMethod
|
|
504
|
+
fun isStepsAvailable(promise: Promise) {
|
|
505
|
+
promise.resolve(RookStepsTracker.isAvailable(reactApplicationContext))
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
@ReactMethod
|
|
509
|
+
fun hasStepsPermissions(promise: Promise) {
|
|
510
|
+
promise.resolve(RookStepsTracker.hasPermissions(reactApplicationContext))
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
@ReactMethod
|
|
514
|
+
fun requestStepsPermissions(promise: Promise) {
|
|
515
|
+
RookStepsTracker.requestPermissions(reactApplicationContext)
|
|
516
|
+
promise.resolve(true)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
@ReactMethod
|
|
520
|
+
fun startSteps(promise: Promise) {
|
|
521
|
+
RookStepsTracker.start(reactApplicationContext).fold({
|
|
522
|
+
promise.resolve(true)
|
|
523
|
+
}, {
|
|
524
|
+
promise.reject(it)
|
|
525
|
+
})
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
@ReactMethod
|
|
529
|
+
fun stopSteps(promise: Promise) {
|
|
530
|
+
RookStepsTracker.stop(reactApplicationContext).fold({
|
|
531
|
+
stepsScope?.cancel()
|
|
532
|
+
promise.resolve(true)
|
|
533
|
+
}, {
|
|
534
|
+
promise.reject(it)
|
|
535
|
+
})
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
@ReactMethod
|
|
539
|
+
fun isStepsActive(promise: Promise) {
|
|
540
|
+
scope.launch {
|
|
541
|
+
val response = RookStepsTracker.isActive()
|
|
542
|
+
promise.resolve(response)
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
@ReactMethod
|
|
547
|
+
fun getTodaySteps(promise: Promise) {
|
|
548
|
+
scope.launch {
|
|
549
|
+
RookStepsTracker.getTodaySteps().fold({
|
|
550
|
+
promise.resolve(it.toString())
|
|
551
|
+
}, {
|
|
552
|
+
promise.reject(it)
|
|
553
|
+
})
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
@ReactMethod
|
|
558
|
+
fun observeTodaySteps(promise: Promise) {
|
|
559
|
+
if (stepsScope == null) stepsScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
560
|
+
|
|
561
|
+
stepsScope?.launch {
|
|
562
|
+
RookStepsTracker.observeTodaySteps().collect {
|
|
563
|
+
reactApplicationContext
|
|
564
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
565
|
+
.emit("RookStepsUpdate", Arguments.createMap().putString("steps", it.toString()))
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
promise.resolve(true)
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
companion object {
|
|
573
|
+
const val NAME = "RookSdk"
|
|
574
|
+
}
|
|
575
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.rooksdk
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RookSdkPackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
+
return listOf(RookSdkModule(reactContext))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
+
return emptyList()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:width="200dp"
|
|
4
|
+
android:height="200dp"
|
|
5
|
+
android:viewportWidth="512"
|
|
6
|
+
android:viewportHeight="512">
|
|
7
|
+
<path
|
|
8
|
+
android:fillColor="#4285F4"
|
|
9
|
+
android:pathData="M258.3,431.3c-35.1,0 -68.1,-13.3 -92.9,-37.6l44.2,-45.4c26.9,26.2 70.6,26.2 97.6,0l94.4,-92c12.7,-12.4 19.8,-28.9 19.8,-46.3s-7,-33.9 -19.8,-46.3c-26.9,-26.2 -70.6,-26.2 -97.6,0l-17.1,16.7L242.6,135l17.1,-16.7c25,-24.3 58,-37.6 93,-37.6c35.1,0 68.1,13.3 92.9,37.6c25.1,24.4 38.9,57 38.9,91.7s-13.8,67.2 -38.9,91.7l-94.4,92.1C326.4,417.9 293.4,431.3 258.3,431.3z" />
|
|
10
|
+
<path
|
|
11
|
+
android:fillColor="#3DDB85"
|
|
12
|
+
android:pathData="M165.6,393.7L66.5,302l-0.3,-0.3c-25.1,-24.4 -38.9,-57 -38.9,-91.7s13.8,-67.2 38.9,-91.7c24.9,-24.2 57.9,-37.6 92.9,-37.6c35.1,0 68.1,13.3 93,37.5l25.2,24.6l-44.2,45.4L208,163.7c-26.9,-26.2 -70.7,-26.2 -97.6,0c-12.7,12.4 -19.8,28.9 -19.8,46.3c0,17.3 6.9,33.7 19.5,46.1l98.5,91.2L165.6,393.7z" />
|
|
13
|
+
<path
|
|
14
|
+
android:fillColor="#4285F4"
|
|
15
|
+
android:pathData="M165.3,393.7c-24.9,-24.2 -38.6,-56.5 -38.8,-90.9c-0.1,-35.1 13.9,-68.4 39.5,-93.7l0.2,-0.2l91.4,-88.5l44.1,45.5l-91.2,88.4c-13.4,13.3 -20.7,30.4 -20.6,48.3c0.1,17.3 7,33.5 19.6,45.8L165.3,393.7z" />
|
|
16
|
+
<path
|
|
17
|
+
android:fillColor="#3DDB85"
|
|
18
|
+
android:pathData="M302.5,211.3a50.7,50.7 0,1 0,101.4 0a50.7,50.7 0,1 0,-101.4 0z" />
|
|
19
|
+
</vector>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
xmlns:tools="http://schemas.android.com/tools"
|
|
4
|
+
android:layout_width="match_parent"
|
|
5
|
+
android:layout_height="match_parent"
|
|
6
|
+
tools:context=".HealthConnectPermissionsActivity">
|
|
7
|
+
|
|
8
|
+
<ImageView
|
|
9
|
+
android:layout_width="wrap_content"
|
|
10
|
+
android:layout_height="wrap_content"
|
|
11
|
+
android:layout_centerInParent="true"
|
|
12
|
+
android:contentDescription="@null"
|
|
13
|
+
android:importantForAccessibility="2"
|
|
14
|
+
android:src="@drawable/ic_health_connect" />
|
|
15
|
+
</RelativeLayout>
|
package/ios/RookSdk.h
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import <React/RCTEventEmitter.h>
|
|
2
|
+
|
|
3
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
4
|
+
#import "RNRookSdkSpec.h"
|
|
5
|
+
|
|
6
|
+
@interface RookSdk : RCTEventEmitter <NativeRookSdkSpec>
|
|
7
|
+
#else
|
|
8
|
+
#import <React/RCTBridgeModule.h>
|
|
9
|
+
|
|
10
|
+
@interface RookSdk : RCTEventEmitter <RCTBridgeModule>
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
@end
|