react-native-rook-sdk 0.6.2 → 1.0.0-rc.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/android/build.gradle +1 -1
- package/android/src/main/AndroidManifestNew.xml +0 -8
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +94 -580
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +17 -1
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +54 -0
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +53 -0
- package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +108 -0
- package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +160 -0
- package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +105 -0
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +497 -0
- package/android/src/main/java/com/rooksdk/utils/DatasourcesUtils.kt +49 -0
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +64 -0
- package/android/src/main/java/com/rooksdk/utils/RookDateTime.kt +20 -0
- package/ios/RookSdk.mm +393 -42
- package/lib/commonjs/context/RookSyncGateContext.js +12 -0
- package/lib/commonjs/context/RookSyncGateContext.js.map +1 -1
- package/lib/commonjs/context/RookSyncGateProvider.js +14 -6
- package/lib/commonjs/context/RookSyncGateProvider.js.map +1 -1
- package/lib/commonjs/context/RookSyncGateReducer.js +15 -0
- package/lib/commonjs/context/RookSyncGateReducer.js.map +1 -1
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +26 -38
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/commonjs/hooks/useRookAppleHealth.js +24 -10
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/commonjs/hooks/useRookAppleHealthVariables.js +22 -4
- package/lib/commonjs/hooks/useRookAppleHealthVariables.js.map +1 -1
- package/lib/commonjs/hooks/useRookConfiguration.js +32 -16
- package/lib/commonjs/hooks/useRookConfiguration.js.map +1 -1
- package/lib/commonjs/hooks/useRookDataSources.js +30 -5
- package/lib/commonjs/hooks/useRookDataSources.js.map +1 -1
- package/lib/commonjs/hooks/useRookEvents.js +61 -57
- package/lib/commonjs/hooks/useRookEvents.js.map +1 -1
- package/lib/commonjs/hooks/useRookPermissions.js +79 -37
- package/lib/commonjs/hooks/useRookPermissions.js.map +1 -1
- package/lib/commonjs/hooks/useRookSummaries.js +23 -29
- 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 +133 -27
- 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/commonjs/types/PermissionsType.js +2 -0
- package/lib/commonjs/types/PermissionsType.js.map +1 -0
- package/lib/commonjs/utils/getNativeModule.js +29 -0
- package/lib/commonjs/utils/getNativeModule.js.map +1 -0
- package/lib/commonjs/utils/getRookModule.js +7 -0
- package/lib/commonjs/utils/getRookModule.js.map +1 -1
- package/lib/commonjs/utils/isModuleReady.js +6 -0
- package/lib/commonjs/utils/isModuleReady.js.map +1 -1
- package/lib/commonjs/utils/isValidDate.js +6 -0
- package/lib/commonjs/utils/isValidDate.js.map +1 -1
- package/lib/commonjs/utils/nativeModules.js +19 -0
- package/lib/commonjs/utils/nativeModules.js.map +1 -0
- package/lib/module/context/RookSyncGateContext.js +12 -0
- package/lib/module/context/RookSyncGateContext.js.map +1 -1
- package/lib/module/context/RookSyncGateProvider.js +10 -2
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/context/RookSyncGateReducer.js +15 -0
- package/lib/module/context/RookSyncGateReducer.js.map +1 -1
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +14 -26
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealth.js +15 -2
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealthVariables.js +20 -2
- package/lib/module/hooks/useRookAppleHealthVariables.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +18 -3
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookDataSources.js +27 -3
- package/lib/module/hooks/useRookDataSources.js.map +1 -1
- package/lib/module/hooks/useRookEvents.js +32 -28
- package/lib/module/hooks/useRookEvents.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +63 -22
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSummaries.js +16 -22
- 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 +133 -28
- 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/module/types/PermissionsType.js +2 -0
- package/lib/module/types/PermissionsType.js.map +1 -0
- package/lib/module/utils/getNativeModule.js +23 -0
- package/lib/module/utils/getNativeModule.js.map +1 -0
- package/lib/module/utils/getRookModule.js +8 -0
- package/lib/module/utils/getRookModule.js.map +1 -1
- package/lib/module/utils/isModuleReady.js +6 -0
- package/lib/module/utils/isModuleReady.js.map +1 -1
- package/lib/module/utils/isValidDate.js +6 -0
- package/lib/module/utils/isValidDate.js.map +1 -1
- package/lib/module/utils/nativeModules.js +13 -0
- package/lib/module/utils/nativeModules.js.map +1 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts +7 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateProvider.d.ts.map +1 -1
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts +15 -0
- package/lib/typescript/src/context/RookSyncGateReducer.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts +6 -2
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealthVariables.d.ts +9 -0
- package/lib/typescript/src/hooks/useRookAppleHealthVariables.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +7 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts +8 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookEvents.d.ts +9 -1
- package/lib/typescript/src/hooks/useRookEvents.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +16 -3
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSummaries.d.ts +6 -6
- 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 +18 -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/lib/typescript/src/types/PermissionsType.d.ts +6 -0
- package/lib/typescript/src/types/PermissionsType.d.ts.map +1 -0
- package/lib/typescript/src/utils/getNativeModule.d.ts +10 -0
- package/lib/typescript/src/utils/getNativeModule.d.ts.map +1 -0
- package/lib/typescript/src/utils/getRookModule.d.ts +7 -0
- package/lib/typescript/src/utils/getRookModule.d.ts.map +1 -1
- package/lib/typescript/src/utils/isModuleReady.d.ts +6 -0
- package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -1
- package/lib/typescript/src/utils/isValidDate.d.ts +6 -0
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
- package/lib/typescript/src/utils/nativeModules.d.ts +14 -0
- package/lib/typescript/src/utils/nativeModules.d.ts.map +1 -0
- 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/java/com/rooksdk/RookDateTime.kt +0 -12
- package/android/src/main/res/layout/activity_health_connect_permissions.xml +0 -15
- package/lib/commonjs/utils/index.js +0 -69
- package/lib/commonjs/utils/index.js.map +0 -1
- package/lib/module/utils/index.js +0 -9
- package/lib/module/utils/index.js.map +0 -1
- package/lib/typescript/src/utils/index.d.ts +0 -9
- package/lib/typescript/src/utils/index.d.ts.map +0 -1
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
package com.rooksdk.modules
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Promise
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.rookmotion.rook.sdk.RookConfigurationManager
|
|
9
|
+
import com.rookmotion.rook.sdk.RookDataSources
|
|
10
|
+
import com.rookmotion.rook.sdk.RookEventManager
|
|
11
|
+
import com.rookmotion.rook.sdk.RookSummaryManager
|
|
12
|
+
import com.rookmotion.rook.sdk.RookYesterdaySyncManager
|
|
13
|
+
import com.rookmotion.rook.sdk.domain.enums.SyncStatus
|
|
14
|
+
import com.rookmotion.rook.sdk.domain.environment.RookEnvironment
|
|
15
|
+
import com.rookmotion.rook.sdk.domain.model.SyncStatusWithData
|
|
16
|
+
import com.rooksdk.utils.DatasourcesUtils.dataSourcesToWritableArray
|
|
17
|
+
import com.rooksdk.utils.DatasourcesUtils.mapToDataSourceType
|
|
18
|
+
import com.rooksdk.utils.RookDateTime
|
|
19
|
+
import kotlinx.coroutines.CoroutineScope
|
|
20
|
+
import kotlinx.coroutines.Dispatchers
|
|
21
|
+
import kotlinx.coroutines.SupervisorJob
|
|
22
|
+
import kotlinx.coroutines.launch
|
|
23
|
+
|
|
24
|
+
class RookSyncModule(
|
|
25
|
+
reactContext: ReactApplicationContext,
|
|
26
|
+
rookConfigurationManager: RookConfigurationManager
|
|
27
|
+
): ReactContextBaseJavaModule(reactContext) {
|
|
28
|
+
|
|
29
|
+
private val rookSynManager: RookYesterdaySyncManager by lazy {
|
|
30
|
+
RookYesterdaySyncManager(reactApplicationContext)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private val rookEventManager by lazy {
|
|
34
|
+
RookEventManager(rookConfigurationManager)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private val rookSummaryManager by lazy {
|
|
38
|
+
RookSummaryManager(rookConfigurationManager)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private val scope: CoroutineScope by lazy {
|
|
42
|
+
CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private val rookDataSources: RookDataSources by lazy {
|
|
46
|
+
RookDataSources(reactApplicationContext)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Schedules a background sync for yesterday's data, which automatically retrieves and processes data
|
|
51
|
+
* from connected devices or platforms.
|
|
52
|
+
* @param config The configuration settings to apply when scheduling the sync.
|
|
53
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
54
|
+
*/
|
|
55
|
+
@ReactMethod
|
|
56
|
+
fun scheduleYesterdaySync(config: ReadableMap, promise: Promise) {
|
|
57
|
+
scope.launch {
|
|
58
|
+
try {
|
|
59
|
+
val clientUUID = config.getString("clientUUID")?.trim() ?: return@launch
|
|
60
|
+
val secretKey = config.getString("clientPassword")?.trim() ?: return@launch
|
|
61
|
+
|
|
62
|
+
if (clientUUID.isBlank() || secretKey.isBlank()) return@launch
|
|
63
|
+
|
|
64
|
+
var environment = RookEnvironment.SANDBOX
|
|
65
|
+
|
|
66
|
+
if (config.getString("environment") == "production")
|
|
67
|
+
environment = RookEnvironment.PRODUCTION
|
|
68
|
+
|
|
69
|
+
rookSynManager.scheduleYesterdaySync(
|
|
70
|
+
enableLogs = true,
|
|
71
|
+
clientUUID = clientUUID,
|
|
72
|
+
secretKey = secretKey,
|
|
73
|
+
environment = environment,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
promise.resolve(true)
|
|
77
|
+
}
|
|
78
|
+
catch (e: Exception) {
|
|
79
|
+
promise.reject(e)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Sleep
|
|
85
|
+
/**
|
|
86
|
+
* Synchronizes the sleep summary data for the given date.
|
|
87
|
+
* @param date The date for which to sync the data (in string format).
|
|
88
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
89
|
+
*/
|
|
90
|
+
@ReactMethod
|
|
91
|
+
fun syncSleepSummary(date: String, promise: Promise) {
|
|
92
|
+
scope.launch {
|
|
93
|
+
val result = rookSummaryManager.syncSleepSummary(RookDateTime.stringToLocalDate(date))
|
|
94
|
+
|
|
95
|
+
result.fold({
|
|
96
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
97
|
+
else promise.resolve(false)
|
|
98
|
+
}, {
|
|
99
|
+
promise.reject(it)
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Body
|
|
105
|
+
/**
|
|
106
|
+
* Synchronizes the body summary data for the given date.
|
|
107
|
+
* @param date The date for which to sync the data (in string format).
|
|
108
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
109
|
+
*/
|
|
110
|
+
@ReactMethod
|
|
111
|
+
fun syncBodySummary(date: String, promise: Promise) {
|
|
112
|
+
scope.launch {
|
|
113
|
+
val result = rookSummaryManager.syncBodySummary(RookDateTime.stringToLocalDate(date))
|
|
114
|
+
|
|
115
|
+
result.fold({
|
|
116
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
117
|
+
else promise.resolve(false)
|
|
118
|
+
}, {
|
|
119
|
+
promise.reject(it)
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Physical
|
|
125
|
+
/**
|
|
126
|
+
* Synchronizes the physical summary data for the given date.
|
|
127
|
+
* @param date The date for which to sync the data (in string format).
|
|
128
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
129
|
+
*/
|
|
130
|
+
@ReactMethod
|
|
131
|
+
fun syncPhysicalSummary(date: String, promise: Promise) {
|
|
132
|
+
scope.launch {
|
|
133
|
+
val result = rookSummaryManager.syncPhysicalSummary(RookDateTime.stringToLocalDate(date))
|
|
134
|
+
|
|
135
|
+
result.fold({
|
|
136
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
137
|
+
else promise.resolve(false)
|
|
138
|
+
}, {
|
|
139
|
+
promise.reject(it)
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Sync all failed summaries
|
|
146
|
+
*/
|
|
147
|
+
@ReactMethod
|
|
148
|
+
fun syncPendingSummaries(promise: Promise) {
|
|
149
|
+
scope.launch {
|
|
150
|
+
val result = rookSummaryManager.syncPendingSummaries()
|
|
151
|
+
|
|
152
|
+
result.fold({
|
|
153
|
+
promise.resolve(true)
|
|
154
|
+
}, {
|
|
155
|
+
promise.reject(it)
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// MARK: - Events
|
|
161
|
+
/**
|
|
162
|
+
* Synchronizes the physical events data for the given date.
|
|
163
|
+
* @param date The date for which to sync the data (in string format).
|
|
164
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
165
|
+
*/
|
|
166
|
+
@ReactMethod
|
|
167
|
+
fun syncPhysicalEvents(date: String, promise: Promise) {
|
|
168
|
+
scope.launch {
|
|
169
|
+
val result = rookEventManager.syncPhysicalEvents(RookDateTime.stringToLocalDate(date))
|
|
170
|
+
|
|
171
|
+
result.fold({
|
|
172
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
173
|
+
else promise.resolve(false)
|
|
174
|
+
}, {
|
|
175
|
+
promise.reject(it)
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Synchronizes the blood glucose events data for the given date.
|
|
182
|
+
* @param date The date for which to sync the data (in string format).
|
|
183
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
184
|
+
*/
|
|
185
|
+
@ReactMethod
|
|
186
|
+
fun syncBloodGlucoseEvents(date: String, promise: Promise) {
|
|
187
|
+
scope.launch {
|
|
188
|
+
val result = rookEventManager.syncBloodGlucoseEvents(RookDateTime.stringToLocalDate(date))
|
|
189
|
+
|
|
190
|
+
result.fold({
|
|
191
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
192
|
+
else promise.resolve(false)
|
|
193
|
+
}, {
|
|
194
|
+
promise.reject(it)
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Synchronizes the blood pressure events data for the given date.
|
|
201
|
+
* @param date The date for which to sync the data (in string format).
|
|
202
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
203
|
+
*/
|
|
204
|
+
@ReactMethod
|
|
205
|
+
fun syncBloodPressureEvents(date: String, promise: Promise) {
|
|
206
|
+
scope.launch {
|
|
207
|
+
val result = rookEventManager.syncBloodPressureEvents(RookDateTime.stringToLocalDate(date))
|
|
208
|
+
|
|
209
|
+
result.fold({
|
|
210
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
211
|
+
else promise.resolve(false)
|
|
212
|
+
}, {
|
|
213
|
+
promise.reject(it)
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Synchronizes the body metrics event data for the given date.
|
|
220
|
+
* @param date The date for which to sync the data (in string format).
|
|
221
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
222
|
+
*/
|
|
223
|
+
@ReactMethod
|
|
224
|
+
fun syncBodyMetricsEvent(date: String, promise: Promise) {
|
|
225
|
+
scope.launch {
|
|
226
|
+
val result = rookEventManager.syncBodyMetricsEvents(RookDateTime.stringToLocalDate(date))
|
|
227
|
+
|
|
228
|
+
result.fold({
|
|
229
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
230
|
+
else promise.resolve(false)
|
|
231
|
+
}, {
|
|
232
|
+
promise.reject(it)
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Synchronizes the body heart Rate events data for the given date.
|
|
239
|
+
* @param date The date for which to sync the data (in string format).
|
|
240
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
241
|
+
*/
|
|
242
|
+
@ReactMethod
|
|
243
|
+
fun syncBodyHeartRateEvent(date: String, promise: Promise) {
|
|
244
|
+
scope.launch {
|
|
245
|
+
val result = rookEventManager.syncBodyHeartRateEvents(RookDateTime.stringToLocalDate(date))
|
|
246
|
+
|
|
247
|
+
result.fold({
|
|
248
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
249
|
+
else promise.resolve(false)
|
|
250
|
+
}, {
|
|
251
|
+
promise.reject(it)
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Synchronizes the physical heart rate events data for the given date.
|
|
258
|
+
* @param date The date for which to sync the data (in string format).
|
|
259
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
260
|
+
*/
|
|
261
|
+
@ReactMethod
|
|
262
|
+
fun syncPhysicalHeartRateEvent(date: String, promise: Promise) {
|
|
263
|
+
scope.launch {
|
|
264
|
+
val result = rookEventManager.syncPhysicalHeartRateEvents(RookDateTime.stringToLocalDate(date))
|
|
265
|
+
|
|
266
|
+
result.fold({
|
|
267
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
268
|
+
else promise.resolve(false)
|
|
269
|
+
}, {
|
|
270
|
+
promise.reject(it)
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Synchronizes the nutrition events data for the given date.
|
|
277
|
+
* @param date The date for which to sync the data (in string format).
|
|
278
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
279
|
+
*/
|
|
280
|
+
@ReactMethod
|
|
281
|
+
fun syncNutritionEvents(date: String, promise: Promise) {
|
|
282
|
+
scope.launch {
|
|
283
|
+
val result = rookEventManager.syncNutritionEvents(RookDateTime.stringToLocalDate(date))
|
|
284
|
+
|
|
285
|
+
result.fold({
|
|
286
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
287
|
+
else promise.resolve(false)
|
|
288
|
+
}, {
|
|
289
|
+
promise.reject(it)
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Synchronizes the hydration events data for the given date.
|
|
296
|
+
* @param date The date for which to sync the data (in string format).
|
|
297
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
298
|
+
*/
|
|
299
|
+
@ReactMethod
|
|
300
|
+
fun syncHydrationEvents(date: String, promise: Promise) {
|
|
301
|
+
scope.launch {
|
|
302
|
+
val result = rookEventManager.syncHydrationEvents(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
|
+
/**
|
|
314
|
+
* Synchronizes the physical oxygenation events data for the given date.
|
|
315
|
+
* @param date The date for which to sync the data (in string format).
|
|
316
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
317
|
+
*/
|
|
318
|
+
@ReactMethod
|
|
319
|
+
fun syncPhysicalOxygenationEvent(date: String, promise: Promise) {
|
|
320
|
+
scope.launch {
|
|
321
|
+
val result = rookEventManager.syncPhysicalOxygenationEvents(RookDateTime.stringToLocalDate(date))
|
|
322
|
+
|
|
323
|
+
result.fold({
|
|
324
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
325
|
+
else promise.resolve(false)
|
|
326
|
+
}, {
|
|
327
|
+
promise.reject(it)
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Synchronizes the body oxygenation events data for the given date.
|
|
334
|
+
* @param date The date for which to sync the data (in string format).
|
|
335
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
336
|
+
*/
|
|
337
|
+
@ReactMethod
|
|
338
|
+
fun syncBodyOxygenationEvent(date: String, promise: Promise) {
|
|
339
|
+
scope.launch {
|
|
340
|
+
val result = rookEventManager.syncBodyOxygenationEvents(RookDateTime.stringToLocalDate(date))
|
|
341
|
+
|
|
342
|
+
result.fold({
|
|
343
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
344
|
+
else promise.resolve(false)
|
|
345
|
+
}, {
|
|
346
|
+
promise.reject(it)
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Synchronizes the sync temperature events data for the given date.
|
|
353
|
+
* @param date The date for which to sync the data (in string format).
|
|
354
|
+
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
355
|
+
*/
|
|
356
|
+
@ReactMethod
|
|
357
|
+
fun syncTemperatureEvent(date: String, promise: Promise) {
|
|
358
|
+
scope.launch {
|
|
359
|
+
val result = rookEventManager.syncTemperatureEvents(RookDateTime.stringToLocalDate(date))
|
|
360
|
+
|
|
361
|
+
result.fold({
|
|
362
|
+
if (it == SyncStatus.SYNCED) promise.resolve(true)
|
|
363
|
+
else promise.resolve(false)
|
|
364
|
+
}, {
|
|
365
|
+
promise.reject(it)
|
|
366
|
+
})
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Synchronizes all failed events
|
|
372
|
+
*/
|
|
373
|
+
@ReactMethod
|
|
374
|
+
fun syncPendingEvents(promise: Promise) {
|
|
375
|
+
scope.launch {
|
|
376
|
+
val result = rookEventManager.syncPendingEvents()
|
|
377
|
+
|
|
378
|
+
result.fold({
|
|
379
|
+
promise.resolve(true)
|
|
380
|
+
}, {
|
|
381
|
+
promise.reject(it)
|
|
382
|
+
})
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Synchronizes the step count for the current day from Health Connect.
|
|
388
|
+
* This method queries the Health Connect platform via the Rook SDK to retrieve
|
|
389
|
+
* the step count for today. If no records are found, it rejects the promise with an error message.
|
|
390
|
+
*
|
|
391
|
+
* @param promise A promise object that resolves with the step count if data is found,
|
|
392
|
+
* or rejects with an error if records are not found or synchronization fails.
|
|
393
|
+
*/
|
|
394
|
+
@ReactMethod
|
|
395
|
+
fun syncTodayHealthConnectStepsCount(promise: Promise) {
|
|
396
|
+
scope.launch {
|
|
397
|
+
rookEventManager.syncTodayHealthConnectStepsCount().fold(
|
|
398
|
+
{
|
|
399
|
+
when (it) {
|
|
400
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
401
|
+
promise.reject("syncTodayHealthConnect", "Records Not Found")
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
is SyncStatusWithData.Synced -> {
|
|
405
|
+
val steps = it.data
|
|
406
|
+
promise.resolve(steps)
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
promise.reject(it)
|
|
412
|
+
}
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Retrieves the available data sources that can be connected to the app.
|
|
420
|
+
* This method fetches data sources such as Garmin, Fitbit, Oura, etc.,
|
|
421
|
+
* that the user can authorize to sync their health data.
|
|
422
|
+
*
|
|
423
|
+
* @param options Optional parameters that may include a redirect URL to be used during authorization.
|
|
424
|
+
* @param promise A promise object that resolves with a list of available data sources
|
|
425
|
+
* or rejects with an error if the operation fails.
|
|
426
|
+
*/
|
|
427
|
+
@ReactMethod
|
|
428
|
+
fun getAvailableDataSources(options: ReadableMap?, promise: Promise) {
|
|
429
|
+
var redirectURL: String? = null
|
|
430
|
+
|
|
431
|
+
if (options !== null) redirectURL = options.getString("redirectURL")
|
|
432
|
+
|
|
433
|
+
scope.launch {
|
|
434
|
+
rookDataSources.getAvailableDataSources(redirectURL).fold(
|
|
435
|
+
{ dataSources ->
|
|
436
|
+
promise.resolve(dataSourcesToWritableArray(dataSources))
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
promise.reject(it)
|
|
440
|
+
},
|
|
441
|
+
)
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Presents a view to the user where they can authorize and connect a specific data source.
|
|
447
|
+
* This method initiates the user interface for connecting a health data source (e.g., Garmin, Fitbit).
|
|
448
|
+
*
|
|
449
|
+
* @param options Optional parameters that may include a redirect URL for the authorization flow.
|
|
450
|
+
* @param promise A promise object that resolves with true if the data source view was presented successfully,
|
|
451
|
+
* or rejects with an error if the operation fails.
|
|
452
|
+
*/
|
|
453
|
+
@ReactMethod
|
|
454
|
+
fun presentDataSourceView(options: ReadableMap?, promise: Promise) {
|
|
455
|
+
var redirectURL: String? = null
|
|
456
|
+
|
|
457
|
+
if (options !== null) redirectURL = options.getString("redirectURL")
|
|
458
|
+
|
|
459
|
+
rookDataSources.presentDataSourceView(redirectURL).fold({
|
|
460
|
+
promise.resolve(true)
|
|
461
|
+
}, {
|
|
462
|
+
promise.reject(it)
|
|
463
|
+
})
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Revokes authorization for a specific data source, disconnecting it from the app.
|
|
468
|
+
* This method allows the user to revoke a previously authorized data source,
|
|
469
|
+
* such as Garmin, Fitbit, or Oura, preventing further data synchronization.
|
|
470
|
+
*
|
|
471
|
+
* @param source The name of the data source to revoke (e.g., "Garmin", "Fitbit").
|
|
472
|
+
* @param promise A promise object that resolves with true if the data source was revoked successfully,
|
|
473
|
+
* or rejects with an error if the operation fails or if the source is invalid.
|
|
474
|
+
*/
|
|
475
|
+
@ReactMethod
|
|
476
|
+
fun revokeDataSource(source: String, promise: Promise) {
|
|
477
|
+
val type = mapToDataSourceType(source)
|
|
478
|
+
|
|
479
|
+
if (type == null) {
|
|
480
|
+
promise.reject("Invalid", "Enter a valid data source")
|
|
481
|
+
return
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
scope.launch {
|
|
485
|
+
rookDataSources.revokeDataSource(type).fold({
|
|
486
|
+
promise.resolve(true)
|
|
487
|
+
}, {
|
|
488
|
+
promise.reject(it)
|
|
489
|
+
})
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
override fun getName(): String {
|
|
494
|
+
return "RookSyncModule"
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package com.rooksdk.utils
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableArray
|
|
5
|
+
import com.rookmotion.rook.sdk.domain.enums.DataSourceType
|
|
6
|
+
import com.rookmotion.rook.sdk.domain.model.DataSource
|
|
7
|
+
|
|
8
|
+
object DatasourcesUtils {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Maps a data source string to its corresponding DataSourceType enum.
|
|
12
|
+
* @param string The data source name as a string (e.g., "Garmin", "Fitbit").
|
|
13
|
+
* @return The corresponding DataSourceType enum or null if the string does not match.
|
|
14
|
+
*/
|
|
15
|
+
fun mapToDataSourceType(string: String): DataSourceType? {
|
|
16
|
+
return when (string) {
|
|
17
|
+
"Garmin" -> DataSourceType.GARMIN
|
|
18
|
+
"Oura" -> DataSourceType.OURA
|
|
19
|
+
"Polar" -> DataSourceType.POLAR
|
|
20
|
+
"Fitbit" -> DataSourceType.FITBIT
|
|
21
|
+
"Withings" -> DataSourceType.WITHINGS
|
|
22
|
+
"Whoop" -> DataSourceType.WHOOP
|
|
23
|
+
else -> null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Converts a list of DataSource objects to a WritableArray to be sent to the React Native layer.
|
|
29
|
+
* Each DataSource object contains information such as name, description, image URL, and connection status.
|
|
30
|
+
* @param dataSources A list of DataSource objects.
|
|
31
|
+
* @return A WritableArray to be sent to the React Native layer.
|
|
32
|
+
*/
|
|
33
|
+
fun dataSourcesToWritableArray(dataSources: List<DataSource>): WritableArray {
|
|
34
|
+
val array = Arguments.createArray()
|
|
35
|
+
for (dataSource in dataSources) {
|
|
36
|
+
val map = Arguments.createMap()
|
|
37
|
+
map.putString("name", dataSource.name)
|
|
38
|
+
map.putString("description", dataSource.description)
|
|
39
|
+
map.putString("imageUrl", dataSource.imageUrl)
|
|
40
|
+
map.putBoolean("connected", dataSource.connected)
|
|
41
|
+
dataSource.authorizationUrl?.let {
|
|
42
|
+
map.putString("authorizationUrl", it)
|
|
43
|
+
}
|
|
44
|
+
array.pushMap(map)
|
|
45
|
+
}
|
|
46
|
+
return array
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* ReadableToWritable is a utility object that provides methods to convert between
|
|
10
|
+
* React Native's ReadableMap and WritableMap, and Kotlin's HashMap.
|
|
11
|
+
* This is useful when you need to transform data between JavaScript and native code.
|
|
12
|
+
*/
|
|
13
|
+
object ReadableToWritable {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Converts a ReadableMap (from JavaScript/React Native) to a HashMap (native Kotlin data structure).
|
|
17
|
+
* It iterates through all the keys in the ReadableMap and converts its values based on their type.
|
|
18
|
+
*
|
|
19
|
+
* @param readableMap The ReadableMap to convert.
|
|
20
|
+
* @return A HashMap<String, Any> with equivalent values.
|
|
21
|
+
*/
|
|
22
|
+
fun readableMapToHashMap(readableMap: ReadableMap): HashMap<String, Any> {
|
|
23
|
+
val map = HashMap<String, Any>()
|
|
24
|
+
val iterator = readableMap.keySetIterator()
|
|
25
|
+
|
|
26
|
+
while (iterator.hasNextKey()) {
|
|
27
|
+
val key = iterator.nextKey()
|
|
28
|
+
when (readableMap.getType(key)) {
|
|
29
|
+
ReadableType.Boolean -> map[key] = readableMap.getBoolean(key)
|
|
30
|
+
ReadableType.Number -> map[key] = readableMap.getDouble(key)
|
|
31
|
+
ReadableType.String -> map[key] = readableMap.getString(key) ?: ""
|
|
32
|
+
ReadableType.Map -> map[key] = readableMapToHashMap(readableMap.getMap(key)!!)
|
|
33
|
+
ReadableType.Array -> map[key] = readableMap.getArray(key)!!.toArrayList()
|
|
34
|
+
else -> {} // Manejar otros tipos si es necesario
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return map
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Converts a HashMap (native Kotlin data structure) to a WritableMap (to be sent to JavaScript/React Native).
|
|
43
|
+
* It iterates through all the entries in the HashMap and converts its values based on their type.
|
|
44
|
+
*
|
|
45
|
+
* @param hashMap The HashMap<String, Any> to convert.
|
|
46
|
+
* @return A WritableMap with equivalent values.
|
|
47
|
+
*/
|
|
48
|
+
fun hashMapToWritableMap(hashMap: HashMap<String, Any>): WritableMap {
|
|
49
|
+
val writableMap = Arguments.createMap()
|
|
50
|
+
|
|
51
|
+
for ((key, value) in hashMap) {
|
|
52
|
+
when (value) {
|
|
53
|
+
is Boolean -> writableMap.putBoolean(key, value)
|
|
54
|
+
is Double -> writableMap.putDouble(key, value)
|
|
55
|
+
is String -> writableMap.putString(key, value)
|
|
56
|
+
is HashMap<*, *> -> writableMap.putMap(key, hashMapToWritableMap(value as HashMap<String, Any>))
|
|
57
|
+
is ArrayList<*> -> writableMap.putArray(key, Arguments.fromArray(value))
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return writableMap
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.rooksdk.utils
|
|
2
|
+
|
|
3
|
+
import java.time.LocalDate
|
|
4
|
+
import java.time.format.DateTimeFormatter
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* RookDateTime is a utility object for handling date-related operations.
|
|
8
|
+
* It provides methods to format and parse dates using the ISO_LOCAL_DATE format.
|
|
9
|
+
*/
|
|
10
|
+
object RookDateTime {
|
|
11
|
+
private val rookDateFormatter: DateTimeFormatter get() = DateTimeFormatter.ISO_LOCAL_DATE
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A DateTimeFormatter using the ISO_LOCAL_DATE pattern (e.g., "YYYY-MM-DD").
|
|
15
|
+
* It formats or parses dates in the standard ISO 8601 format.
|
|
16
|
+
*/
|
|
17
|
+
fun stringToLocalDate(string: String): LocalDate {
|
|
18
|
+
return LocalDate.parse(string, rookDateFormatter)
|
|
19
|
+
}
|
|
20
|
+
}
|