react-native-rook-sdk 2.1.2 → 4.0.0-beta.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/LICENSE +1 -1
- package/README.md +35 -3
- package/RNRookSdk.podspec +22 -0
- package/android/build.gradle +20 -41
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +11 -222
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +24 -33
- package/ios/DateHelper.swift +55 -0
- package/ios/Encodable.swift +25 -0
- package/ios/EncodableDataSource.swift +5 -6
- package/ios/EncodableDataSourceAuthorizer.swift +3 -4
- package/ios/HearRateMapper.swift +42 -0
- package/ios/RookBackground.swift +35 -0
- package/ios/RookConfiguration.swift +116 -0
- package/ios/RookData.swift +170 -0
- package/ios/RookEntry.swift +61 -0
- package/ios/RookPermissions.swift +78 -0
- package/ios/RookSdk-Bridging-Header.h +12 -0
- package/ios/RookSdk.h +14 -2
- package/ios/RookSdk.mm +549 -81
- package/ios/RookSources.swift +74 -116
- package/ios/RookSync.swift +126 -34
- package/ios/boost-boost_privacy-Bridging-Header.h +4 -0
- package/lib/module/NativeRookSdk.js +95 -0
- package/lib/module/NativeRookSdk.js.map +1 -0
- package/lib/module/context/RookSyncGateContext.js +2 -0
- package/lib/module/context/RookSyncGateContext.js.map +1 -1
- package/lib/module/context/RookSyncGateProvider.js +16 -15
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/context/RookSyncGateReducer.js +2 -0
- package/lib/module/context/RookSyncGateReducer.js.map +1 -1
- package/lib/module/context/RookSyncGateTypes.js +2 -0
- package/lib/module/hooks/useRookAPISources.js +66 -0
- package/lib/module/hooks/useRookAPISources.js.map +1 -0
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +12 -25
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealth.js +11 -23
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +10 -109
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookData.js +35 -33
- package/lib/module/hooks/useRookData.js.map +1 -1
- package/lib/module/hooks/useRookHealthConnect.js +9 -10
- package/lib/module/hooks/useRookHealthConnect.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +39 -77
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSamsungHealth.js +35 -0
- package/lib/module/hooks/useRookSamsungHealth.js.map +1 -0
- package/lib/module/hooks/useRookSync.js +23 -31
- package/lib/module/hooks/useRookSync.js.map +1 -1
- package/lib/module/hooks/useRookVariables.js +24 -18
- package/lib/module/hooks/useRookVariables.js.map +1 -1
- package/lib/module/index.js +18 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/hook/useRookAutoSync.js +22 -36
- package/lib/module/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/module/modules/types/sendMessageBroadcast.js +1 -1
- package/lib/module/modules/utils/errors.js +2 -0
- package/lib/module/modules/utils/errors.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/types/ActivityEvent.js +2 -0
- package/lib/module/types/AppleHealthPermissions.js +53 -0
- package/lib/module/types/AppleHealthPermissions.js.map +1 -0
- package/lib/module/types/AuthorizedSources.js +2 -0
- package/lib/module/types/BodySummary.js +2 -0
- package/lib/module/types/DataSource.js +10 -0
- package/lib/module/types/DataSource.js.map +1 -1
- package/lib/module/types/HeartRateEvent.js +2 -0
- package/lib/{commonjs/types/DataSource.js.map → module/types/HeartRateEvent.js.map} +1 -1
- package/lib/module/types/PermissionsType.js +1 -1
- package/lib/module/types/PhysicalSummary.js +2 -0
- package/lib/module/types/Rook.js +2 -0
- package/lib/{commonjs/types/SyncTypes.js.map → module/types/Rook.js.map} +1 -1
- package/lib/module/types/SDKSources.js +2 -0
- package/lib/module/types/SDKSources.js.map +1 -1
- package/lib/module/types/SamsungHealthPermissions.js +3 -0
- package/lib/module/types/SamsungHealthPermissions.js.map +1 -1
- package/lib/module/types/SleepSummary.js +2 -0
- package/lib/module/types/SummaryTypes.js +1 -1
- package/lib/module/types/SyncTypes.js +28 -1
- package/lib/module/types/SyncTypes.js.map +1 -1
- package/lib/module/utils/isModuleReady.js +2 -0
- package/lib/module/utils/isModuleReady.js.map +1 -1
- package/lib/module/utils/isRunningOnAndroid.js +2 -0
- package/lib/module/utils/isRunningOnAndroid.js.map +1 -1
- package/lib/module/utils/isRunningOniOS.js +2 -0
- package/lib/module/utils/isRunningOniOS.js.map +1 -1
- package/lib/module/utils/isValidDate.js +2 -0
- package/lib/module/utils/isValidDate.js.map +1 -1
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeRookSdk.d.ts +190 -0
- package/lib/typescript/src/NativeRookSdk.d.ts.map +1 -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.map +1 -1
- package/lib/typescript/src/hooks/useRookAPISources.d.ts +15 -0
- package/lib/typescript/src/hooks/useRookAPISources.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts +0 -1
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts +1 -2
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +0 -8
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts +2 -0
- package/lib/typescript/src/hooks/useRookData.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookHealthConnect.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts +11 -12
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts +7 -0
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookSync.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +19 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts.map +1 -1
- package/lib/typescript/src/types/AppleHealthPermissions.d.ts +50 -0
- package/lib/typescript/src/types/AppleHealthPermissions.d.ts.map +1 -0
- package/lib/typescript/src/types/AuthorizedSources.d.ts +3 -3
- package/lib/typescript/src/types/AuthorizedSources.d.ts.map +1 -1
- package/lib/typescript/src/types/DataSource.d.ts +8 -1
- package/lib/typescript/src/types/DataSource.d.ts.map +1 -1
- package/lib/typescript/src/types/HeartRateEvent.d.ts +24 -0
- package/lib/typescript/src/types/HeartRateEvent.d.ts.map +1 -0
- package/lib/typescript/src/types/PermissionsType.d.ts +0 -4
- package/lib/typescript/src/types/PermissionsType.d.ts.map +1 -1
- package/lib/typescript/src/types/Rook.d.ts +9 -0
- package/lib/typescript/src/types/Rook.d.ts.map +1 -0
- package/lib/typescript/src/types/SamsungHealthPermissions.d.ts +1 -0
- package/lib/typescript/src/types/SamsungHealthPermissions.d.ts.map +1 -1
- package/lib/typescript/src/types/SyncTypes.d.ts +28 -5
- package/lib/typescript/src/types/SyncTypes.d.ts.map +1 -1
- package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -1
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
- package/package.json +94 -98
- package/src/NativeRookSdk.ts +281 -0
- package/{lib/commonjs/context/RookSyncGateContext.js → src/context/RookSyncGateContext.ts} +10 -13
- package/src/context/RookSyncGateProvider.tsx +78 -0
- package/{lib/commonjs/context/RookSyncGateReducer.js → src/context/RookSyncGateReducer.ts} +12 -33
- package/src/context/RookSyncGateTypes.ts +34 -0
- package/src/hooks/useRookAPISources.ts +83 -0
- package/src/hooks/useRookAndroidBackgroundSteps.ts +81 -0
- package/src/hooks/useRookAppleHealth.ts +55 -0
- package/src/hooks/useRookConfiguration.ts +82 -0
- package/src/hooks/useRookData.ts +122 -0
- package/src/hooks/useRookHealthConnect.ts +59 -0
- package/src/hooks/useRookPermissions.ts +224 -0
- package/src/hooks/useRookSamsungHealth.ts +37 -0
- package/src/hooks/useRookSync.ts +157 -0
- package/src/hooks/useRookVariables.ts +77 -0
- package/src/index.tsx +28 -0
- package/src/modules/hook/useRookAutoSync.ts +305 -0
- package/src/modules/types/sendMessageBroadcast.ts +5 -0
- package/src/modules/utils/errors.ts +9 -0
- package/src/types/ActivityEvent.ts +159 -0
- package/src/types/AppleHealthPermissions.ts +49 -0
- package/src/types/AuthorizedSources.ts +33 -0
- package/src/types/BodySummary.ts +116 -0
- package/src/types/DataSource.ts +16 -0
- package/src/types/HeartRateEvent.ts +26 -0
- package/src/types/PermissionsType.ts +9 -0
- package/src/types/PhysicalSummary.ts +84 -0
- package/src/types/Rook.ts +8 -0
- package/src/types/SDKSources.ts +5 -0
- package/src/types/SamsungHealthPermissions.ts +16 -0
- package/src/types/SleepSummary.ts +66 -0
- package/src/types/SummaryTypes.ts +70 -0
- package/src/types/SyncTypes.ts +63 -0
- package/{lib/commonjs/utils/isModuleReady.js → src/utils/isModuleReady.ts} +4 -10
- package/src/utils/isRunningOnAndroid.ts +10 -0
- package/src/utils/isRunningOniOS.ts +10 -0
- package/{lib/commonjs/utils/isValidDate.js → src/utils/isValidDate.ts} +5 -10
- package/android/src/main/AndroidManifestNew.xml +0 -36
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +0 -65
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +0 -70
- package/android/src/main/java/com/rooksdk/broadcasts/SamsungHealthPermissionsReceiverTransmitter.kt +0 -52
- package/android/src/main/java/com/rooksdk/modules/RookBackgroundSyncModule.kt +0 -85
- package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +0 -148
- package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +0 -247
- package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +0 -309
- package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +0 -105
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +0 -496
- package/android/src/main/java/com/rooksdk/utils/DatasourcesUtils.kt +0 -63
- package/android/src/main/java/com/rooksdk/utils/PermissionConversion.kt +0 -21
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +0 -64
- package/android/src/main/java/com/rooksdk/utils/RookDateTime.kt +0 -20
- package/android/src/main/java/com/rooksdk/utils/SamsungAvailability.kt +0 -21
- package/android/src/main/java/com/rooksdk/utils/Source.kt +0 -6
- package/android/src/main/java/com/rooksdk/utils/StringToSyncType.kt +0 -58
- package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +0 -19
- package/android/src/main/java/com/rooksdk/utils/serializers/LocalDateSerializer.kt +0 -21
- package/android/src/main/res/drawable/ic_health_connect.xml +0 -19
- package/android/src/main/res/values/themes.xml +0 -3
- package/ios/EncodableRookDataSource.swift +0 -36
- package/ios/EncodableStatusDataSources.swift +0 -47
- package/ios/RookBackgroundModule.h +0 -5
- package/ios/RookBackgroundModule.mm +0 -89
- package/ios/RookConfigurationModule.h +0 -5
- package/ios/RookConfigurationModule.mm +0 -163
- package/ios/RookExternalModule.h +0 -5
- package/ios/RookExternalModule.m +0 -27
- package/ios/RookLocalData.swift +0 -152
- package/ios/RookPermissionsModule.h +0 -5
- package/ios/RookPermissionsModule.mm +0 -180
- package/ios/RookSourcesModule.h +0 -5
- package/ios/RookSourcesModule.mm +0 -67
- package/ios/RookSync.h +0 -5
- package/ios/RookSync.m +0 -27
- package/ios/RookSyncModule.h +0 -5
- package/ios/RookSyncModule.mm +0 -476
- package/ios/SwiftTest.swift +0 -18
- package/ios/react-native-rook-sdk-Bridging-Header.h +0 -12
- package/lib/commonjs/context/RookSyncGateContext.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateProvider.js +0 -98
- package/lib/commonjs/context/RookSyncGateProvider.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateReducer.js.map +0 -1
- package/lib/commonjs/context/RookSyncGateTypes.js +0 -6
- package/lib/commonjs/context/RookSyncGateTypes.js.map +0 -1
- package/lib/commonjs/context/index.js +0 -14
- package/lib/commonjs/context/index.js.map +0 -1
- package/lib/commonjs/hooks/index.js +0 -90
- package/lib/commonjs/hooks/index.js.map +0 -1
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +0 -100
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +0 -1
- package/lib/commonjs/hooks/useRookAppleHealth.js +0 -74
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +0 -1
- package/lib/commonjs/hooks/useRookAppleHealthVariables.js +0 -48
- package/lib/commonjs/hooks/useRookAppleHealthVariables.js.map +0 -1
- package/lib/commonjs/hooks/useRookConfiguration.js +0 -188
- package/lib/commonjs/hooks/useRookConfiguration.js.map +0 -1
- package/lib/commonjs/hooks/useRookData.js +0 -100
- package/lib/commonjs/hooks/useRookData.js.map +0 -1
- package/lib/commonjs/hooks/useRookDataSources.js +0 -118
- package/lib/commonjs/hooks/useRookDataSources.js.map +0 -1
- package/lib/commonjs/hooks/useRookEvents.js +0 -225
- package/lib/commonjs/hooks/useRookEvents.js.map +0 -1
- package/lib/commonjs/hooks/useRookHealthConnect.js +0 -70
- package/lib/commonjs/hooks/useRookHealthConnect.js.map +0 -1
- package/lib/commonjs/hooks/useRookPermissions.js +0 -226
- package/lib/commonjs/hooks/useRookPermissions.js.map +0 -1
- package/lib/commonjs/hooks/useRookSummaries.js +0 -85
- package/lib/commonjs/hooks/useRookSummaries.js.map +0 -1
- package/lib/commonjs/hooks/useRookSync.js +0 -147
- package/lib/commonjs/hooks/useRookSync.js.map +0 -1
- package/lib/commonjs/hooks/useRookVariables.js +0 -69
- package/lib/commonjs/hooks/useRookVariables.js.map +0 -1
- package/lib/commonjs/index.js +0 -56
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/modules/hook/useRookAutoSync.js +0 -262
- package/lib/commonjs/modules/hook/useRookAutoSync.js.map +0 -1
- package/lib/commonjs/modules/types/sendMessageBroadcast.js +0 -2
- package/lib/commonjs/modules/types/sendMessageBroadcast.js.map +0 -1
- package/lib/commonjs/modules/utils/errors.js +0 -12
- package/lib/commonjs/modules/utils/errors.js.map +0 -1
- package/lib/commonjs/types/ActivityEvent.js +0 -6
- package/lib/commonjs/types/ActivityEvent.js.map +0 -1
- package/lib/commonjs/types/AuthorizedSources.js +0 -2
- package/lib/commonjs/types/AuthorizedSources.js.map +0 -1
- package/lib/commonjs/types/BodySummary.js +0 -6
- package/lib/commonjs/types/BodySummary.js.map +0 -1
- package/lib/commonjs/types/DataSource.js +0 -2
- package/lib/commonjs/types/PermissionsType.js +0 -2
- package/lib/commonjs/types/PermissionsType.js.map +0 -1
- package/lib/commonjs/types/PhysicalSummary.js +0 -6
- package/lib/commonjs/types/PhysicalSummary.js.map +0 -1
- package/lib/commonjs/types/SDKSources.js +0 -13
- package/lib/commonjs/types/SDKSources.js.map +0 -1
- package/lib/commonjs/types/SamsungHealthPermissions.js +0 -23
- package/lib/commonjs/types/SamsungHealthPermissions.js.map +0 -1
- package/lib/commonjs/types/SleepSummary.js +0 -6
- package/lib/commonjs/types/SleepSummary.js.map +0 -1
- package/lib/commonjs/types/SummaryTypes.js +0 -2
- package/lib/commonjs/types/SummaryTypes.js.map +0 -1
- package/lib/commonjs/types/SyncTypes.js +0 -6
- package/lib/commonjs/utils/credentials.js +0 -12
- package/lib/commonjs/utils/credentials.js.map +0 -1
- package/lib/commonjs/utils/getNativeModule.js +0 -29
- package/lib/commonjs/utils/getNativeModule.js.map +0 -1
- package/lib/commonjs/utils/getRookModule.js +0 -28
- package/lib/commonjs/utils/getRookModule.js.map +0 -1
- package/lib/commonjs/utils/isModuleReady.js.map +0 -1
- package/lib/commonjs/utils/isRunningOnAndroid.js +0 -15
- package/lib/commonjs/utils/isRunningOnAndroid.js.map +0 -1
- package/lib/commonjs/utils/isRunningOniOS.js +0 -15
- package/lib/commonjs/utils/isRunningOniOS.js.map +0 -1
- package/lib/commonjs/utils/isValidDate.js.map +0 -1
- package/lib/commonjs/utils/nativeModules.js +0 -28
- package/lib/commonjs/utils/nativeModules.js.map +0 -1
- package/lib/commonjs/utils/packageInfo.js +0 -13
- package/lib/commonjs/utils/packageInfo.js.map +0 -1
- package/lib/module/context/index.js +0 -2
- package/lib/module/context/index.js.map +0 -1
- package/lib/module/hooks/index.js +0 -13
- package/lib/module/hooks/index.js.map +0 -1
- package/lib/module/hooks/useRookAppleHealthVariables.js +0 -41
- package/lib/module/hooks/useRookAppleHealthVariables.js.map +0 -1
- package/lib/module/hooks/useRookDataSources.js +0 -110
- package/lib/module/hooks/useRookDataSources.js.map +0 -1
- package/lib/module/hooks/useRookEvents.js +0 -218
- package/lib/module/hooks/useRookEvents.js.map +0 -1
- package/lib/module/hooks/useRookSummaries.js +0 -78
- package/lib/module/hooks/useRookSummaries.js.map +0 -1
- package/lib/module/utils/credentials.js +0 -6
- package/lib/module/utils/credentials.js.map +0 -1
- package/lib/module/utils/getNativeModule.js +0 -23
- package/lib/module/utils/getNativeModule.js.map +0 -1
- package/lib/module/utils/getRookModule.js +0 -22
- package/lib/module/utils/getRookModule.js.map +0 -1
- package/lib/module/utils/nativeModules.js +0 -22
- package/lib/module/utils/nativeModules.js.map +0 -1
- package/lib/module/utils/packageInfo.js +0 -7
- package/lib/module/utils/packageInfo.js.map +0 -1
- package/lib/typescript/src/context/index.d.ts +0 -2
- package/lib/typescript/src/context/index.d.ts.map +0 -1
- package/lib/typescript/src/hooks/index.d.ts +0 -13
- package/lib/typescript/src/hooks/index.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useRookAppleHealthVariables.d.ts +0 -15
- package/lib/typescript/src/hooks/useRookAppleHealthVariables.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useRookDataSources.d.ts +0 -22
- package/lib/typescript/src/hooks/useRookDataSources.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useRookEvents.d.ts +0 -26
- package/lib/typescript/src/hooks/useRookEvents.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useRookSummaries.d.ts +0 -14
- package/lib/typescript/src/hooks/useRookSummaries.d.ts.map +0 -1
- package/lib/typescript/src/utils/credentials.d.ts +0 -5
- package/lib/typescript/src/utils/credentials.d.ts.map +0 -1
- package/lib/typescript/src/utils/getNativeModule.d.ts +0 -10
- package/lib/typescript/src/utils/getNativeModule.d.ts.map +0 -1
- package/lib/typescript/src/utils/getRookModule.d.ts +0 -9
- package/lib/typescript/src/utils/getRookModule.d.ts.map +0 -1
- package/lib/typescript/src/utils/nativeModules.d.ts +0 -23
- package/lib/typescript/src/utils/nativeModules.d.ts.map +0 -1
- package/lib/typescript/src/utils/packageInfo.d.ts +0 -6
- package/lib/typescript/src/utils/packageInfo.d.ts.map +0 -1
- package/react-native-rook-sdk.podspec +0 -45
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
import android.annotation.SuppressLint
|
|
2
|
-
import com.facebook.react.bridge.Arguments
|
|
3
|
-
import com.facebook.react.bridge.Callback
|
|
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.google.gson.Gson
|
|
10
|
-
import com.rookmotion.rook.sdk.RookContinuousUploadManager
|
|
11
|
-
import com.rookmotion.rook.sdk.RookDataSources
|
|
12
|
-
import com.rookmotion.rook.sdk.RookSyncManager
|
|
13
|
-
import com.rookmotion.rook.sdk.domain.model.SyncStatusWithData
|
|
14
|
-
import com.rooksdk.utils.DatasourcesUtils.dataSourcesToWritableArray
|
|
15
|
-
import com.rooksdk.utils.DatasourcesUtils.mapToDataSourceType
|
|
16
|
-
import com.rooksdk.utils.RookDateTime
|
|
17
|
-
import com.rooksdk.utils.SamsungAvailability
|
|
18
|
-
import com.rooksdk.utils.StringToSyncType
|
|
19
|
-
import io.tryrook.sdk.samsung.RookSamsung
|
|
20
|
-
import io.tryrook.sdk.samsung.domain.model.SHSyncStatusWithData
|
|
21
|
-
import kotlinx.coroutines.CoroutineScope
|
|
22
|
-
import kotlinx.coroutines.Dispatchers
|
|
23
|
-
import kotlinx.coroutines.SupervisorJob
|
|
24
|
-
import kotlinx.coroutines.launch
|
|
25
|
-
import org.jetbrains.annotations.Debug
|
|
26
|
-
|
|
27
|
-
class RookSyncModule(
|
|
28
|
-
reactContext: ReactApplicationContext,
|
|
29
|
-
private val rookSamsung: RookSamsung
|
|
30
|
-
): ReactContextBaseJavaModule(reactContext) {
|
|
31
|
-
|
|
32
|
-
private val rookContinuousUploadManager by lazy {
|
|
33
|
-
RookContinuousUploadManager(reactContext)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private val rookSync by lazy {
|
|
37
|
-
RookSyncManager(reactContext)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private val scope: CoroutineScope by lazy {
|
|
41
|
-
CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private val rookDataSources: RookDataSources by lazy {
|
|
45
|
-
RookDataSources(reactApplicationContext)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Schedules a background sync for yesterday's data, which automatically retrieves and processes data
|
|
50
|
-
* from connected devices or platforms.
|
|
51
|
-
* @param promise A promise object to handle the result (resolved on success, rejected on failure).
|
|
52
|
-
*/
|
|
53
|
-
@SuppressLint("MissingPermission")
|
|
54
|
-
@ReactMethod
|
|
55
|
-
fun scheduleYesterdaySync(promise: Promise) {
|
|
56
|
-
scope.launch {
|
|
57
|
-
rookContinuousUploadManager.launchInForegroundService(true)
|
|
58
|
-
.fold({
|
|
59
|
-
promise.resolve(true)
|
|
60
|
-
},{
|
|
61
|
-
promise.reject(it)
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@ReactMethod
|
|
67
|
-
fun enableSamsungSync(promise: Promise) {
|
|
68
|
-
scope.launch {
|
|
69
|
-
rookSamsung.schedule(true)
|
|
70
|
-
promise.resolve(true)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
@ReactMethod
|
|
75
|
-
fun isSamsungSyncEnabled(promise: Promise) {
|
|
76
|
-
scope.launch {
|
|
77
|
-
rookSamsung.isScheduled().fold(
|
|
78
|
-
{
|
|
79
|
-
promise.resolve(it)
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
promise.reject(it)
|
|
83
|
-
}
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@ReactMethod
|
|
89
|
-
fun disableSamsungSync(promise: Promise) {
|
|
90
|
-
scope.launch {
|
|
91
|
-
rookSamsung.cancel()
|
|
92
|
-
promise.resolve(true)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@ReactMethod
|
|
97
|
-
fun syncTodaySamsungHealthStepsCount(promise: Promise) {
|
|
98
|
-
scope.launch {
|
|
99
|
-
rookSamsung.getTodayStepsCount().fold({
|
|
100
|
-
when (it) {
|
|
101
|
-
SHSyncStatusWithData.RecordsNotFound -> {
|
|
102
|
-
promise.reject("SamsungStepsCount", "Records Not Found")
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
is SHSyncStatusWithData.Synced -> {
|
|
106
|
-
val steps = it.data
|
|
107
|
-
promise.resolve(steps)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}, {
|
|
111
|
-
promise.reject(it)
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Synchronizes the step count for the current day from Health Connect.
|
|
118
|
-
* This method queries the Health Connect platform via the Rook SDK to retrieve
|
|
119
|
-
* the step count for today. If no records are found, it rejects the promise with an error message.
|
|
120
|
-
*
|
|
121
|
-
* @param promise A promise object that resolves with the step count if data is found,
|
|
122
|
-
* or rejects with an error if records are not found or synchronization fails.
|
|
123
|
-
*/
|
|
124
|
-
@ReactMethod
|
|
125
|
-
fun syncTodayHealthConnectStepsCount(promise: Promise) {
|
|
126
|
-
scope.launch {
|
|
127
|
-
rookSync.getTodayStepsCount().fold(
|
|
128
|
-
{
|
|
129
|
-
when (it) {
|
|
130
|
-
SyncStatusWithData.RecordsNotFound -> {
|
|
131
|
-
promise.reject("HealthConnectStepsCount", "Records Not Found")
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
is SyncStatusWithData.Synced -> {
|
|
135
|
-
val steps = it.data
|
|
136
|
-
promise.resolve(steps)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
promise.reject(it)
|
|
142
|
-
}
|
|
143
|
-
)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @deprecated
|
|
150
|
-
* Retrieves the available data sources that can be connected to the app.
|
|
151
|
-
* This method fetches data sources such as Garmin, Fitbit, Oura, etc.,
|
|
152
|
-
* that the user can authorize to sync their health data.
|
|
153
|
-
*
|
|
154
|
-
* @param options Optional parameters that may include a redirect URL to be used during authorization.
|
|
155
|
-
* @param promise A promise object that resolves with a list of available data sources
|
|
156
|
-
* or rejects with an error if the operation fails.
|
|
157
|
-
*/
|
|
158
|
-
@ReactMethod
|
|
159
|
-
fun getAvailableDataSources(options: ReadableMap?, promise: Promise) {
|
|
160
|
-
var redirectURL: String? = null
|
|
161
|
-
|
|
162
|
-
if (options !== null) redirectURL = options.getString("redirectURL")
|
|
163
|
-
|
|
164
|
-
scope.launch {
|
|
165
|
-
rookDataSources.getAvailableDataSources(redirectURL).fold(
|
|
166
|
-
{ dataSources ->
|
|
167
|
-
promise.resolve(dataSourcesToWritableArray(dataSources))
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
promise.reject(it)
|
|
171
|
-
},
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Presents a view to the user where they can authorize and connect a specific data source.
|
|
178
|
-
* This method initiates the user interface for connecting a health data source (e.g., Garmin, Fitbit).
|
|
179
|
-
*
|
|
180
|
-
* @param options Optional parameters that may include a redirect URL for the authorization flow.
|
|
181
|
-
* @param promise A promise object that resolves with true if the data source view was presented successfully,
|
|
182
|
-
* or rejects with an error if the operation fails.
|
|
183
|
-
*/
|
|
184
|
-
@ReactMethod
|
|
185
|
-
fun presentDataSourceView(options: ReadableMap?, promise: Promise) {
|
|
186
|
-
var redirectURL: String? = null
|
|
187
|
-
|
|
188
|
-
if (options !== null) redirectURL = options.getString("redirectURL")
|
|
189
|
-
|
|
190
|
-
rookDataSources.presentDataSourceView(redirectURL).fold({
|
|
191
|
-
promise.resolve(true)
|
|
192
|
-
}, {
|
|
193
|
-
promise.reject(it)
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Revokes authorization for a specific data source, disconnecting it from the app.
|
|
199
|
-
* This method allows the user to revoke a previously authorized data source,
|
|
200
|
-
* such as Garmin, Fitbit, or Oura, preventing further data synchronization.
|
|
201
|
-
*
|
|
202
|
-
* @param source The name of the data source to revoke (e.g., "Garmin", "Fitbit").
|
|
203
|
-
* @param promise A promise object that resolves with true if the data source was revoked successfully,
|
|
204
|
-
* or rejects with an error if the operation fails or if the source is invalid.
|
|
205
|
-
*/
|
|
206
|
-
@ReactMethod
|
|
207
|
-
fun revokeDataSource(source: String, promise: Promise) {
|
|
208
|
-
val type = mapToDataSourceType(source)
|
|
209
|
-
|
|
210
|
-
if (type == null) {
|
|
211
|
-
promise.reject("Invalid", "Enter a valid data source")
|
|
212
|
-
return
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
scope.launch {
|
|
216
|
-
rookDataSources.revokeDataSource(type).fold({
|
|
217
|
-
promise.resolve(true)
|
|
218
|
-
}, {
|
|
219
|
-
promise.reject(it)
|
|
220
|
-
})
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
@ReactMethod
|
|
225
|
-
fun getAuthorizedDataSources(promise: Promise) {
|
|
226
|
-
scope.launch {
|
|
227
|
-
rookDataSources.getAuthorizedDataSources().fold(
|
|
228
|
-
{
|
|
229
|
-
val gson = Gson()
|
|
230
|
-
promise.resolve(gson.toJson(it))
|
|
231
|
-
}, {
|
|
232
|
-
promise.reject(it)
|
|
233
|
-
}
|
|
234
|
-
)
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
@ReactMethod
|
|
239
|
-
fun getAuthorizedDataSourcesV2(promise: Promise) {
|
|
240
|
-
scope.launch {
|
|
241
|
-
rookDataSources.getAuthorizedDataSourcesV2().fold(
|
|
242
|
-
{
|
|
243
|
-
val gson = Gson()
|
|
244
|
-
promise.resolve(gson.toJson(it))
|
|
245
|
-
}, {
|
|
246
|
-
promise.reject(it)
|
|
247
|
-
}
|
|
248
|
-
)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
@ReactMethod
|
|
253
|
-
fun getDataSourceAuthorizer(options: ReadableMap, promise: Promise) {
|
|
254
|
-
|
|
255
|
-
val source = options.getString("dataSource") ?: ""
|
|
256
|
-
val redirect = options.getString("redirectURL")
|
|
257
|
-
|
|
258
|
-
scope.launch {
|
|
259
|
-
rookDataSources.getDataSourceAuthorizer(dataSource = source, redirectUrl = redirect)
|
|
260
|
-
.fold({ value ->
|
|
261
|
-
val gson = Gson()
|
|
262
|
-
promise.resolve(gson.toJson(value))
|
|
263
|
-
}, {
|
|
264
|
-
promise.reject(it)
|
|
265
|
-
})
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
@ReactMethod
|
|
270
|
-
fun syncSHTodayCaloriesCount(promise: Promise) {
|
|
271
|
-
scope.launch {
|
|
272
|
-
rookSamsung.getTodayCaloriesCount().fold(
|
|
273
|
-
{
|
|
274
|
-
when (it) {
|
|
275
|
-
SHSyncStatusWithData.RecordsNotFound -> {
|
|
276
|
-
promise.reject("syncTodayHealthConnect", "Records Not Found")
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
is SHSyncStatusWithData.Synced -> {
|
|
280
|
-
val data = Arguments.createMap().apply {
|
|
281
|
-
putDouble("basal", it.data.basal)
|
|
282
|
-
putDouble("active", it.data.active)
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
promise.resolve(data)
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
promise.reject(it)
|
|
291
|
-
}
|
|
292
|
-
)
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Synchronizes the calories count for the current day from Health Connect.
|
|
298
|
-
* This method queries the Health Connect platform via the Rook SDK to retrieve
|
|
299
|
-
* the calories count for today. If no records are found, it rejects the promise with an error message.
|
|
300
|
-
*
|
|
301
|
-
* @param promise A promise object that resolves with the step count if data is found,
|
|
302
|
-
* or rejects with an error if records are not found or synchronization fails.
|
|
303
|
-
*/
|
|
304
|
-
@ReactMethod
|
|
305
|
-
fun syncTodayCaloriesCount(promise: Promise) {
|
|
306
|
-
scope.launch {
|
|
307
|
-
rookSync.getTodayCaloriesCount().fold(
|
|
308
|
-
{
|
|
309
|
-
when (it) {
|
|
310
|
-
SyncStatusWithData.RecordsNotFound -> {
|
|
311
|
-
promise.reject("syncTodayHealthConnect", "Records Not Found")
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
is SyncStatusWithData.Synced -> {
|
|
315
|
-
val data = Arguments.createMap().apply {
|
|
316
|
-
putDouble("basal", it.data.basal)
|
|
317
|
-
putDouble("active", it.data.active)
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
promise.resolve(data)
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
promise.reject(it)
|
|
326
|
-
}
|
|
327
|
-
)
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
@ReactMethod
|
|
332
|
-
fun sync(enableLogs: Boolean, callback: Callback) {
|
|
333
|
-
scope.launch {
|
|
334
|
-
rookSync.sync(enableLogs).fold({ result ->
|
|
335
|
-
callback.invoke(null, result)
|
|
336
|
-
}, {
|
|
337
|
-
val params = Arguments.createMap().apply {
|
|
338
|
-
putString("domain", it.localizedMessage ?: it.message)
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
callback.invoke(params, false)
|
|
342
|
-
})
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
@ReactMethod
|
|
347
|
-
fun syncByDate(date: String, callback: Callback) {
|
|
348
|
-
val localDate = RookDateTime.stringToLocalDate(date)
|
|
349
|
-
|
|
350
|
-
scope.launch {
|
|
351
|
-
rookSync.sync(localDate).fold({ result ->
|
|
352
|
-
callback.invoke(null, result)
|
|
353
|
-
}, {
|
|
354
|
-
val params = Arguments.createMap().apply {
|
|
355
|
-
putString("domain", it.localizedMessage ?: it.message)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
callback.invoke(params, false)
|
|
359
|
-
})
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
@ReactMethod
|
|
364
|
-
fun syncByDefinition(summary: String, date: String, callback: Callback) {
|
|
365
|
-
val localDate = RookDateTime.stringToLocalDate(date)
|
|
366
|
-
val type = StringToSyncType.stringToSummary(summary)
|
|
367
|
-
|
|
368
|
-
scope.launch {
|
|
369
|
-
rookSync.sync(localDate, type).fold({ result ->
|
|
370
|
-
callback.invoke(null, result)
|
|
371
|
-
}, {
|
|
372
|
-
val params = Arguments.createMap().apply {
|
|
373
|
-
putString("domain", it.localizedMessage ?: it.message)
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
callback.invoke(params, false)
|
|
377
|
-
})
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
@ReactMethod
|
|
382
|
-
fun syncEvent(date: String, event: String, promise: Promise) {
|
|
383
|
-
val localDate = RookDateTime.stringToLocalDate(date)
|
|
384
|
-
val type = StringToSyncType.stringToEvent(event)
|
|
385
|
-
|
|
386
|
-
scope.launch {
|
|
387
|
-
rookSync.syncEvents(localDate, type).fold({ result ->
|
|
388
|
-
promise.resolve(result)
|
|
389
|
-
}, {
|
|
390
|
-
promise.reject(it)
|
|
391
|
-
})
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
@ReactMethod
|
|
396
|
-
fun shSync(enableLogs: Boolean, callback: Callback) {
|
|
397
|
-
scope.launch {
|
|
398
|
-
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
399
|
-
val params = Arguments.createMap().apply {
|
|
400
|
-
putString("domain", "Samsung health is not available")
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
callback.invoke(params, false)
|
|
404
|
-
return@launch
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
rookSamsung.sync(enableLogs).fold(
|
|
408
|
-
{
|
|
409
|
-
callback(null, true)
|
|
410
|
-
}, {
|
|
411
|
-
val params = Arguments.createMap().apply {
|
|
412
|
-
putString("domain", it.localizedMessage ?: it.message)
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
callback.invoke(params, false)
|
|
416
|
-
}
|
|
417
|
-
)
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
@ReactMethod
|
|
422
|
-
fun shSyncByDate(date: String, callback: Callback) {
|
|
423
|
-
val localDate = RookDateTime.stringToLocalDate(date)
|
|
424
|
-
|
|
425
|
-
scope.launch {
|
|
426
|
-
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
427
|
-
val params = Arguments.createMap().apply {
|
|
428
|
-
putString("domain", "Samsung health is not available")
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
callback.invoke(params, false)
|
|
432
|
-
return@launch
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
rookSamsung.sync(localDate).fold({ result ->
|
|
436
|
-
callback.invoke(null, result)
|
|
437
|
-
}, {
|
|
438
|
-
val params = Arguments.createMap().apply {
|
|
439
|
-
putString("domain", it.localizedMessage ?: it.message)
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
callback.invoke(params, false)
|
|
443
|
-
})
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
@ReactMethod
|
|
448
|
-
fun shSyncByDefinition(summary: String, date: String, callback: Callback) {
|
|
449
|
-
val localDate = RookDateTime.stringToLocalDate(date)
|
|
450
|
-
val type = StringToSyncType.stringToSamsungPillar(summary)
|
|
451
|
-
|
|
452
|
-
scope.launch {
|
|
453
|
-
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
454
|
-
val params = Arguments.createMap().apply {
|
|
455
|
-
putString("domain", "Samsung health is not available")
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
callback.invoke(params, false)
|
|
459
|
-
return@launch
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
rookSamsung.sync(localDate, type).fold({ result ->
|
|
463
|
-
callback.invoke(null, result)
|
|
464
|
-
}, {
|
|
465
|
-
val params = Arguments.createMap().apply {
|
|
466
|
-
putString("domain", it.localizedMessage ?: it.message)
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
callback.invoke(params, false)
|
|
470
|
-
})
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
@ReactMethod
|
|
475
|
-
fun shSyncEvent(date: String, event: String, promise: Promise) {
|
|
476
|
-
val localDate = RookDateTime.stringToLocalDate(date)
|
|
477
|
-
val type = StringToSyncType.stringToSamsungEvent(event)
|
|
478
|
-
|
|
479
|
-
scope.launch {
|
|
480
|
-
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
481
|
-
promise.reject(Throwable("Samsung health is not available"))
|
|
482
|
-
return@launch
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
rookSamsung.syncEvents(localDate, type).fold({ result ->
|
|
486
|
-
promise.resolve(result)
|
|
487
|
-
}, {
|
|
488
|
-
promise.reject(it)
|
|
489
|
-
})
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
override fun getName(): String {
|
|
493
|
-
return "RookSyncModule"
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
package com.rooksdk.utils
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.Arguments
|
|
4
|
-
import com.facebook.react.bridge.ReadableArray
|
|
5
|
-
import com.facebook.react.bridge.WritableArray
|
|
6
|
-
import com.rookmotion.rook.sdk.domain.enums.DataSourceType
|
|
7
|
-
import com.rookmotion.rook.sdk.domain.model.DataSource
|
|
8
|
-
|
|
9
|
-
object DatasourcesUtils {
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Maps a data source string to its corresponding DataSourceType enum.
|
|
13
|
-
* @param string The data source name as a string (e.g., "Garmin", "Fitbit").
|
|
14
|
-
* @return The corresponding DataSourceType enum or null if the string does not match.
|
|
15
|
-
*/
|
|
16
|
-
fun mapToDataSourceType(string: String): DataSourceType? {
|
|
17
|
-
return when (string) {
|
|
18
|
-
"Garmin" -> DataSourceType.GARMIN
|
|
19
|
-
"Oura" -> DataSourceType.OURA
|
|
20
|
-
"Polar" -> DataSourceType.POLAR
|
|
21
|
-
"Fitbit" -> DataSourceType.FITBIT
|
|
22
|
-
"Withings" -> DataSourceType.WITHINGS
|
|
23
|
-
"Whoop" -> DataSourceType.WHOOP
|
|
24
|
-
else -> null
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Converts a list of DataSource objects to a WritableArray to be sent to the React Native layer.
|
|
30
|
-
* Each DataSource object contains information such as name, description, image URL, and connection status.
|
|
31
|
-
* @param dataSources A list of DataSource objects.
|
|
32
|
-
* @return A WritableArray to be sent to the React Native layer.
|
|
33
|
-
*/
|
|
34
|
-
fun dataSourcesToWritableArray(dataSources: List<DataSource>): WritableArray {
|
|
35
|
-
val array = Arguments.createArray()
|
|
36
|
-
for (dataSource in dataSources) {
|
|
37
|
-
val map = Arguments.createMap()
|
|
38
|
-
map.putString("name", dataSource.name)
|
|
39
|
-
map.putString("description", dataSource.description)
|
|
40
|
-
map.putString("imageUrl", dataSource.imageUrl)
|
|
41
|
-
map.putBoolean("connected", dataSource.connected)
|
|
42
|
-
dataSource.authorizationUrl?.let {
|
|
43
|
-
map.putString("authorizationURL", it)
|
|
44
|
-
}
|
|
45
|
-
array.pushMap(map)
|
|
46
|
-
}
|
|
47
|
-
return array
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
fun readableArrayToSourceList(sources: ReadableArray): List<Source> {
|
|
51
|
-
val rawList = sources.toArrayList()
|
|
52
|
-
|
|
53
|
-
return rawList
|
|
54
|
-
.mapNotNull { it as? String }
|
|
55
|
-
.mapNotNull {
|
|
56
|
-
try {
|
|
57
|
-
Source.valueOf(it)
|
|
58
|
-
} catch (e: IllegalArgumentException) {
|
|
59
|
-
null
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
package com.rooksdk.utils
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReadableArray
|
|
4
|
-
import io.tryrook.sdk.samsung.domain.enums.SamsungHealthPermission
|
|
5
|
-
|
|
6
|
-
object PermissionConversion {
|
|
7
|
-
|
|
8
|
-
fun parseSamsungPermissions(rawPermissions: ReadableArray): Set<SamsungHealthPermission> {
|
|
9
|
-
val rawList = rawPermissions.toArrayList()
|
|
10
|
-
|
|
11
|
-
return rawList
|
|
12
|
-
.mapNotNull { it as? String }
|
|
13
|
-
.mapNotNull {
|
|
14
|
-
try {
|
|
15
|
-
SamsungHealthPermission.valueOf(it)
|
|
16
|
-
} catch (e: IllegalArgumentException) {
|
|
17
|
-
null
|
|
18
|
-
}
|
|
19
|
-
}.toSet()
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
package com.rooksdk.utils
|
|
2
|
-
|
|
3
|
-
import io.tryrook.sdk.samsung.RookSamsung
|
|
4
|
-
import io.tryrook.sdk.samsung.domain.enums.SamsungHealthAvailability
|
|
5
|
-
|
|
6
|
-
object SamsungAvailability {
|
|
7
|
-
suspend fun getSamsungHealthAvailabilityOrDefault(rookSamsung: RookSamsung): SamsungHealthAvailability {
|
|
8
|
-
val result = rookSamsung.checkSamsungHealthAvailability()
|
|
9
|
-
val defaultValue = SamsungHealthAvailability.NOT_INSTALLED
|
|
10
|
-
|
|
11
|
-
return result.getOrDefault(defaultValue)
|
|
12
|
-
}
|
|
13
|
-
suspend fun isSamsungAvailable(rookSamsung: RookSamsung): Boolean {
|
|
14
|
-
val result = rookSamsung.checkSamsungHealthAvailability()
|
|
15
|
-
val defaultValue = SamsungHealthAvailability.NOT_INSTALLED
|
|
16
|
-
|
|
17
|
-
val availability = result.getOrDefault(defaultValue)
|
|
18
|
-
|
|
19
|
-
return availability == SamsungHealthAvailability.INSTALLED
|
|
20
|
-
}
|
|
21
|
-
}
|