react-native-rook-sdk 4.0.0 → 5.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 +21 -40
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +1709 -117
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +26 -42
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +34 -37
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +8 -14
- package/android/src/main/java/com/rooksdk/broadcasts/SamsungHealthPermissionsReceiverTransmitter.kt +8 -16
- package/android/src/main/java/com/rooksdk/utils/{DatasourcesUtils.kt → DatasourceUtils.kt} +10 -9
- package/android/src/main/java/com/rooksdk/utils/{PermissionConversion.kt → PermissionConvertions.kt} +1 -1
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +0 -1
- package/android/src/main/java/com/rooksdk/utils/RookGsonBuilder.kt +3 -0
- package/android/src/main/java/com/rooksdk/utils/SamsungAvailability.kt +1 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +0 -1
- package/android/src/main/java/com/rooksdk/utils/serializers/ZoneDateTimeSerializer.kt +18 -0
- package/ios/DateHelper.swift +4 -4
- package/ios/Encodable.swift +25 -0
- package/ios/EncodableDataSource.swift +2 -3
- package/ios/EncodableDataSourceAuthorizer.swift +2 -3
- package/ios/EncodableSDKState.swift +3 -2
- package/ios/{EncodableHeartRate.swift → HearRateMapper.swift} +3 -3
- package/ios/NutritionMapper.swift +3 -3
- package/ios/RookBackground.swift +5 -8
- package/ios/RookConfiguration.swift +33 -30
- package/ios/{RookLocalData.swift → RookData.swift} +76 -69
- package/ios/RookEntry.swift +62 -0
- package/ios/RookPermissions.swift +36 -40
- package/ios/RookSdk-Bridging-Header.h +12 -0
- package/ios/RookSdk.h +3 -3
- package/ios/RookSdk.mm +390 -134
- package/ios/RookSources.swift +60 -54
- package/ios/RookSync.swift +48 -78
- package/ios/boost-boost_privacy-Bridging-Header.h +4 -0
- package/lib/{commonjs/types/AppleHealthPermissions.js → module/NativeRookSdk.js} +50 -6
- 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 +17 -18
- 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 +10 -16
- package/lib/module/hooks/useRookAPISources.js.map +1 -1
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +11 -12
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookAppleHealth.js +9 -10
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +17 -22
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookData.js +33 -38
- 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 +34 -45
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSamsungHealth.js +8 -20
- package/lib/module/hooks/useRookSamsungHealth.js.map +1 -1
- package/lib/module/hooks/useRookSync.js +23 -32
- package/lib/module/hooks/useRookSync.js.map +1 -1
- package/lib/module/hooks/useRookVariables.js +26 -29
- package/lib/module/hooks/useRookVariables.js.map +1 -1
- package/lib/module/index.js +18 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/components/RookStateManager.js +31 -0
- package/lib/module/modules/components/RookStateManager.js.map +1 -0
- package/lib/module/modules/hook/useRookAutoSync.js +24 -36
- package/lib/module/modules/hook/useRookAutoSync.js.map +1 -1
- package/lib/module/modules/hook/useRookEmitter.js +61 -0
- package/lib/module/modules/hook/useRookEmitter.js.map +1 -0
- 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/AppleHealthNutritionEvent.js +2 -0
- package/lib/module/types/AppleHealthNutritionEvent.js.map +1 -1
- package/lib/module/types/AppleHealthPermissions.js +2 -0
- package/lib/module/types/AppleHealthPermissions.js.map +1 -1
- package/lib/module/types/AuthorizedSources.js +2 -0
- package/lib/module/types/BodySummary.js +2 -0
- package/lib/module/types/DataSource.js +2 -0
- package/lib/module/types/DataSource.js.map +1 -1
- package/lib/module/types/HCMealData.js +3 -1
- package/lib/module/types/HCMealData.js.map +1 -1
- package/lib/module/types/HeartRateEvent.js +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/BodySummary.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 +2 -0
- package/lib/module/types/SyncTypes.js.map +1 -1
- package/lib/module/types/WriteNutrition.js +2 -0
- package/lib/module/types/WriteNutrition.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 +705 -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.map +1 -1
- package/lib/typescript/src/hooks/useRookAndroidBackgroundSteps.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts +1 -1
- 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 +1 -1
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts +0 -6
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSync.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts +1 -1
- package/lib/typescript/src/hooks/useRookVariables.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +18 -8
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/modules/components/RookStateManager.d.ts +10 -0
- package/lib/typescript/src/modules/components/RookStateManager.d.ts.map +1 -0
- package/lib/typescript/src/modules/hook/useRookAutoSync.d.ts.map +1 -1
- package/lib/typescript/src/modules/hook/useRookEmitter.d.ts +4 -0
- package/lib/typescript/src/modules/hook/useRookEmitter.d.ts.map +1 -0
- package/lib/typescript/src/types/AppleHealthNutritionEvent.d.ts.map +1 -1
- package/lib/typescript/src/types/AuthorizedSources.d.ts +11 -0
- package/lib/typescript/src/types/AuthorizedSources.d.ts.map +1 -1
- package/lib/typescript/src/types/HCMealData.d.ts.map +1 -1
- package/lib/typescript/src/types/HeartRateEvent.d.ts +2 -2
- package/lib/typescript/src/types/HeartRateEvent.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 +5 -1
- 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 +839 -0
- package/{lib/commonjs/context/RookSyncGateContext.js → src/context/RookSyncGateContext.ts} +10 -13
- package/src/context/RookSyncGateProvider.tsx +82 -0
- package/{lib/commonjs/context/RookSyncGateReducer.js → src/context/RookSyncGateReducer.ts} +14 -41
- package/src/context/RookSyncGateTypes.ts +40 -0
- package/{lib/commonjs/hooks/useRookAPISources.js → src/hooks/useRookAPISources.ts} +40 -36
- package/src/hooks/useRookAndroidBackgroundSteps.ts +81 -0
- package/src/hooks/useRookAppleHealth.ts +55 -0
- package/src/hooks/useRookConfiguration.ts +106 -0
- package/src/hooks/useRookData.ts +133 -0
- package/src/hooks/useRookHealthConnect.ts +59 -0
- package/src/hooks/useRookPermissions.ts +240 -0
- package/src/hooks/useRookSamsungHealth.ts +37 -0
- package/src/hooks/useRookSync.ts +157 -0
- package/src/hooks/useRookVariables.ts +98 -0
- package/src/index.tsx +29 -0
- package/src/modules/components/RookStateManager.tsx +41 -0
- package/{lib/commonjs/modules/hook/useRookAutoSync.js → src/modules/hook/useRookAutoSync.ts} +141 -95
- package/src/modules/hook/useRookEmitter.ts +94 -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/AppleHealthNutritionEvent.ts +142 -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/{lib/commonjs/types/HCMealData.js → src/types/HCMealData.ts} +60 -11
- 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/src/types/WriteNutrition.ts +66 -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} +12 -14
- package/android/src/main/AndroidManifestNew.xml +0 -36
- package/android/src/main/java/com/rooksdk/modules/RookBackgroundSyncModule.kt +0 -99
- package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +0 -182
- package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +0 -301
- package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +0 -359
- package/android/src/main/java/com/rooksdk/modules/RookSourcesModule.kt +0 -102
- package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +0 -119
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +0 -551
- 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 -15
- package/ios/RookConfigurationModule.h +0 -5
- package/ios/RookConfigurationModule.mm +0 -22
- package/ios/RookExternalModule.h +0 -5
- package/ios/RookExternalModule.m +0 -31
- package/ios/RookPermissionsModule.h +0 -5
- package/ios/RookPermissionsModule.mm +0 -20
- package/ios/RookSourcesModule.h +0 -5
- package/ios/RookSourcesModule.mm +0 -18
- package/ios/RookSync.h +0 -5
- package/ios/RookSync.m +0 -35
- 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 -108
- 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 -76
- package/lib/commonjs/hooks/index.js.map +0 -1
- package/lib/commonjs/hooks/useRookAPISources.js.map +0 -1
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +0 -88
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +0 -1
- package/lib/commonjs/hooks/useRookAppleHealth.js +0 -63
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +0 -1
- package/lib/commonjs/hooks/useRookConfiguration.js +0 -113
- package/lib/commonjs/hooks/useRookConfiguration.js.map +0 -1
- package/lib/commonjs/hooks/useRookData.js +0 -116
- package/lib/commonjs/hooks/useRookData.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 -211
- package/lib/commonjs/hooks/useRookPermissions.js.map +0 -1
- package/lib/commonjs/hooks/useRookSamsungHealth.js +0 -54
- package/lib/commonjs/hooks/useRookSamsungHealth.js.map +0 -1
- package/lib/commonjs/hooks/useRookSync.js +0 -148
- package/lib/commonjs/hooks/useRookSync.js.map +0 -1
- package/lib/commonjs/hooks/useRookVariables.js +0 -93
- package/lib/commonjs/hooks/useRookVariables.js.map +0 -1
- package/lib/commonjs/index.js +0 -121
- package/lib/commonjs/index.js.map +0 -1
- 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/AppleHealthNutritionEvent.js +0 -77
- package/lib/commonjs/types/AppleHealthNutritionEvent.js.map +0 -1
- package/lib/commonjs/types/AppleHealthPermissions.js.map +0 -1
- package/lib/commonjs/types/AuthorizedSources.js +0 -6
- package/lib/commonjs/types/AuthorizedSources.js.map +0 -1
- package/lib/commonjs/types/BodySummary.js +0 -6
- package/lib/commonjs/types/DataSource.js +0 -16
- package/lib/commonjs/types/DataSource.js.map +0 -1
- package/lib/commonjs/types/DiagnosticState.js +0 -2
- package/lib/commonjs/types/DiagnosticState.js.map +0 -1
- package/lib/commonjs/types/HCMealData.js.map +0 -1
- package/lib/commonjs/types/HeartRateEvent.js +0 -2
- package/lib/commonjs/types/HeartRateEvent.js.map +0 -1
- 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 -33
- package/lib/commonjs/types/SyncTypes.js.map +0 -1
- package/lib/commonjs/types/WriteNutrition.js +0 -18
- package/lib/commonjs/types/WriteNutrition.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 -29
- 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 -11
- package/lib/module/hooks/index.js.map +0 -1
- package/lib/module/types/DiagnosticState.js +0 -2
- package/lib/module/types/DiagnosticState.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 -23
- 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 -11
- package/lib/typescript/src/hooks/index.d.ts.map +0 -1
- package/lib/typescript/src/types/DiagnosticState.d.ts +0 -13
- package/lib/typescript/src/types/DiagnosticState.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 -24
- 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,154 +1,152 @@
|
|
|
1
1
|
package com.rooksdk
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import androidx.core.content.ContextCompat
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.Callback
|
|
6
5
|
import com.facebook.react.bridge.Promise
|
|
7
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
-
import com.facebook.react.bridge.
|
|
9
|
-
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.ReadableArray
|
|
10
8
|
import com.facebook.react.bridge.ReadableMap
|
|
11
|
-
import com.facebook.react.
|
|
9
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
10
|
+
import com.google.gson.Gson
|
|
11
|
+
import com.rookmotion.rook.sdk.RookBackgroundSyncManager
|
|
12
12
|
import com.rookmotion.rook.sdk.RookConfigurationManager
|
|
13
13
|
import com.rookmotion.rook.sdk.RookPermissionsManager
|
|
14
|
+
import com.rookmotion.rook.sdk.RookStepsManager
|
|
15
|
+
import com.rookmotion.rook.sdk.RookSyncManager
|
|
16
|
+
import com.rookmotion.rook.sdk.RookWriteManager
|
|
14
17
|
import com.rookmotion.rook.sdk.domain.analytics.HCRookAnalytics
|
|
15
18
|
import com.rookmotion.rook.sdk.domain.analytics.HCRookFramework
|
|
19
|
+
import com.rookmotion.rook.sdk.domain.annotation.ExperimentalRookApi
|
|
20
|
+
import com.rookmotion.rook.sdk.domain.enums.BackgroundReadStatus
|
|
21
|
+
import com.rookmotion.rook.sdk.domain.enums.HealthConnectAvailability
|
|
22
|
+
import com.rookmotion.rook.sdk.domain.enums.RequestPermissionsStatus
|
|
23
|
+
import com.rookmotion.rook.sdk.domain.enums.SyncStatus
|
|
16
24
|
import com.rookmotion.rook.sdk.domain.environment.RookEnvironment
|
|
17
25
|
import com.rookmotion.rook.sdk.domain.exception.HCException
|
|
26
|
+
import com.rookmotion.rook.sdk.domain.exception.HCRecordsNotFoundException
|
|
27
|
+
import com.rookmotion.rook.sdk.domain.model.HCActivityEvent
|
|
28
|
+
import com.rookmotion.rook.sdk.domain.model.HCBodySummary
|
|
29
|
+
import com.rookmotion.rook.sdk.domain.model.HCPhysicalSummary
|
|
30
|
+
import com.rookmotion.rook.sdk.domain.model.HCSleepSummary
|
|
18
31
|
import com.rookmotion.rook.sdk.domain.model.RookConfiguration
|
|
32
|
+
import com.rookmotion.rook.sdk.domain.model.SyncStatusWithData
|
|
19
33
|
import com.rooksdk.broadcasts.AndroidPermissionsReceiverTransmitter
|
|
20
34
|
import com.rooksdk.broadcasts.HealthConnectPermissionsReceiverTransmitter
|
|
21
35
|
import com.rooksdk.broadcasts.SamsungHealthPermissionsReceiverTransmitter
|
|
36
|
+
import com.rooksdk.utils.DatasourceUtils
|
|
37
|
+
import com.rooksdk.utils.DatasourceUtils.mapToDataSourceType
|
|
38
|
+
import com.rooksdk.utils.PermissionConversion
|
|
22
39
|
import com.rooksdk.utils.ReadableToWritable
|
|
40
|
+
import com.rooksdk.utils.RookDateTime
|
|
41
|
+
import com.rooksdk.utils.RookGsonBuilder
|
|
23
42
|
import com.rooksdk.utils.SamsungAvailability
|
|
43
|
+
import com.rooksdk.utils.Source
|
|
44
|
+
import com.rooksdk.utils.StringToSyncType
|
|
24
45
|
import io.tryrook.api.sources.RookApiSources
|
|
25
46
|
import io.tryrook.api.sources.domain.environment.ApiEnvironment
|
|
47
|
+
import io.tryrook.api.sources.domain.exception.ApiException
|
|
26
48
|
import io.tryrook.api.sources.domain.model.ApiConfiguration
|
|
27
49
|
import io.tryrook.sdk.samsung.RookSamsung
|
|
28
50
|
import io.tryrook.sdk.samsung.domain.analytics.SHRookAnalytics
|
|
29
51
|
import io.tryrook.sdk.samsung.domain.analytics.SHRookFramework
|
|
52
|
+
import io.tryrook.sdk.samsung.domain.enums.SHRequestPermissionsStatus
|
|
53
|
+
import io.tryrook.sdk.samsung.domain.enums.SHSyncStatus
|
|
30
54
|
import io.tryrook.sdk.samsung.domain.enums.SamsungHealthAvailability
|
|
31
55
|
import io.tryrook.sdk.samsung.domain.enums.SamsungHealthPermission
|
|
32
56
|
import io.tryrook.sdk.samsung.domain.environment.SHEnvironment
|
|
33
57
|
import io.tryrook.sdk.samsung.domain.exception.SHException
|
|
58
|
+
import io.tryrook.sdk.samsung.domain.model.SHActivityEvent
|
|
59
|
+
import io.tryrook.sdk.samsung.domain.model.SHBodySummary
|
|
34
60
|
import io.tryrook.sdk.samsung.domain.model.SHConfiguration
|
|
61
|
+
import io.tryrook.sdk.samsung.domain.model.SHPhysicalSummary
|
|
62
|
+
import io.tryrook.sdk.samsung.domain.model.SHSleepSummary
|
|
63
|
+
import io.tryrook.sdk.samsung.domain.model.SHSyncStatusWithData
|
|
35
64
|
import kotlinx.coroutines.CoroutineScope
|
|
36
65
|
import kotlinx.coroutines.Dispatchers
|
|
37
66
|
import kotlinx.coroutines.SupervisorJob
|
|
38
|
-
import kotlinx.coroutines.cancel
|
|
39
67
|
import kotlinx.coroutines.launch
|
|
40
68
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* It provides methods for initializing the SDK, handling user configuration, syncing
|
|
45
|
-
* health data, and managing permissions.
|
|
46
|
-
*
|
|
47
|
-
* Main Responsibilities:
|
|
48
|
-
* - Initialize and configure the Rook SDK.
|
|
49
|
-
* - Manage user-related information such as user ID.
|
|
50
|
-
* - Sync health-related summaries and events (e.g., sleep, body metrics, physical activities).
|
|
51
|
-
* - Handle Health Connect permissions and check availability.
|
|
52
|
-
* - Transmit permission changes through Android and Health Connect.
|
|
53
|
-
* - Provide the ability to listen to permission changes using Android broadcast receivers.
|
|
54
|
-
* - Expose methods to JavaScript for requesting or syncing data.
|
|
55
|
-
*
|
|
56
|
-
* Key Components:
|
|
57
|
-
* - `RookConfigurationManager`: Manages configuration settings for the SDK.
|
|
58
|
-
* - `RookSummaryManager`: Handles syncing health data summaries (e.g., sleep, physical, body).
|
|
59
|
-
* - `RookEventManager`: Manages the synchronization of health-related events (e.g., physical activities, blood pressure, etc.).
|
|
60
|
-
* - `RookPermissionsManager`: Handles permission management and availability checks for Health Connect.
|
|
61
|
-
* - `RookStepsManager`: Manages steps data synchronization.
|
|
62
|
-
* - `CoroutineScope`: Used to launch asynchronous operations.
|
|
63
|
-
*/
|
|
64
|
-
class RookSdkModule(
|
|
65
|
-
reactContext: ReactApplicationContext,
|
|
66
|
-
private val rookConfigurationManager: RookConfigurationManager,
|
|
67
|
-
private val rookSamsung: RookSamsung,
|
|
68
|
-
private val rookApiSources: RookApiSources,
|
|
69
|
-
): ReactContextBaseJavaModule(reactContext) {
|
|
69
|
+
@ReactModule(name = RookSdkModule.NAME)
|
|
70
|
+
class RookSdkModule(reactContext: ReactApplicationContext) :
|
|
71
|
+
NativeRookSdkSpec(reactContext) {
|
|
70
72
|
|
|
71
|
-
private var scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
72
73
|
private var listenerCount = 0
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
override fun getName(): String {
|
|
76
|
+
return NAME
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
private val
|
|
79
|
-
|
|
79
|
+
private val rookHealthConnect by lazy {
|
|
80
|
+
RookSyncManager(reactContext)
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
private
|
|
83
|
-
|
|
83
|
+
private var scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
84
|
+
|
|
85
|
+
private val rookSync by lazy {
|
|
86
|
+
RookSyncManager(reactContext)
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
private val
|
|
87
|
-
|
|
89
|
+
private val rookPermissionsManager: RookPermissionsManager by lazy {
|
|
90
|
+
RookPermissionsManager(reactContext)
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
private val rookConfigurationManager: RookConfigurationManager by lazy {
|
|
94
|
+
RookConfigurationManager(reactContext)
|
|
92
95
|
}
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
androidPermissionsReceiverTransmitter.setReactApplicationContext(reactApplicationContext)
|
|
98
|
-
hcPermissionsReceiverTransmitter.setReactApplicationContext(reactApplicationContext)
|
|
99
|
-
shHealthPermissionsReceiverTransmitter.setReactApplicationContext(reactApplicationContext)
|
|
97
|
+
private val backgroundSyncManager: RookBackgroundSyncManager by lazy {
|
|
98
|
+
RookBackgroundSyncManager(reactContext)
|
|
99
|
+
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
IntentFilter(RookPermissionsManager.ACTION_ANDROID_PERMISSIONS),
|
|
105
|
-
ContextCompat.RECEIVER_EXPORTED
|
|
106
|
-
)
|
|
101
|
+
private val rookSamsung: RookSamsung by lazy {
|
|
102
|
+
RookSamsung(reactContext)
|
|
103
|
+
}
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
IntentFilter(RookPermissionsManager.ACTION_HEALTH_CONNECT_PERMISSIONS),
|
|
112
|
-
ContextCompat.RECEIVER_EXPORTED,
|
|
113
|
-
)
|
|
105
|
+
private val rookApiSources: RookApiSources by lazy {
|
|
106
|
+
RookApiSources(reactContext)
|
|
107
|
+
}
|
|
114
108
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
IntentFilter(SamsungHealthPermission.ACTION_SAMSUNG_HEALTH_PERMISSIONS),
|
|
119
|
-
ContextCompat.RECEIVER_EXPORTED
|
|
120
|
-
)
|
|
121
|
-
}
|
|
109
|
+
private val gsonBuilder: Gson by lazy {
|
|
110
|
+
RookGsonBuilder.getGsonBuilder()
|
|
111
|
+
}
|
|
122
112
|
|
|
123
|
-
|
|
113
|
+
private val rookStepsManager: RookStepsManager by lazy {
|
|
114
|
+
RookStepsManager(reactContext)
|
|
124
115
|
}
|
|
125
116
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (listenerCount == 0) {
|
|
130
|
-
stepsScope.cancel()
|
|
117
|
+
private fun tryToSetSamsungUserId() {
|
|
118
|
+
scope.launch {
|
|
119
|
+
val result = rookConfigurationManager.getUserID()
|
|
131
120
|
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
if (result != null) {
|
|
122
|
+
val user = rookSamsung.updateUserID(result)
|
|
123
|
+
user.getOrNull()
|
|
124
|
+
}
|
|
134
125
|
}
|
|
135
126
|
}
|
|
136
127
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
128
|
+
override fun initRook(
|
|
129
|
+
options: ReadableMap?,
|
|
130
|
+
promise: Promise?
|
|
131
|
+
) {
|
|
132
|
+
if (promise == null) return
|
|
133
|
+
|
|
134
|
+
if (options == null) {
|
|
135
|
+
promise.reject(code = "1001", message = "unknown exception")
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
145
139
|
try {
|
|
146
|
-
|
|
147
|
-
val
|
|
148
|
-
val
|
|
140
|
+
|
|
141
|
+
val clientUUID = options.getString("clientUUID")?.trim() ?: ""
|
|
142
|
+
val secret = options.getString("secret")?.trim() ?: ""
|
|
143
|
+
val packageName = options.getString("packageName")?.trim()
|
|
149
144
|
|
|
150
145
|
if (clientUUID.isBlank() || secret.isBlank()) {
|
|
151
|
-
promise.reject(
|
|
146
|
+
promise.reject(
|
|
147
|
+
code ="3",
|
|
148
|
+
message = "Requested operation needs an authorization level that your clientUUID doesn't have."
|
|
149
|
+
)
|
|
152
150
|
return
|
|
153
151
|
}
|
|
154
152
|
|
|
@@ -156,7 +154,7 @@ class RookSdkModule(
|
|
|
156
154
|
var shEnv = SHEnvironment.SANDBOX
|
|
157
155
|
var apiEnv = ApiEnvironment.SANDBOX
|
|
158
156
|
|
|
159
|
-
if (
|
|
157
|
+
if (options.getString("environment") == "production") {
|
|
160
158
|
environment = RookEnvironment.PRODUCTION
|
|
161
159
|
shEnv = SHEnvironment.SANDBOX
|
|
162
160
|
apiEnv = ApiEnvironment.PRODUCTION
|
|
@@ -183,7 +181,7 @@ class RookSdkModule(
|
|
|
183
181
|
secret = secret
|
|
184
182
|
)
|
|
185
183
|
|
|
186
|
-
val enableLogs =
|
|
184
|
+
val enableLogs = options.getBoolean("enableLogs")
|
|
187
185
|
if(enableLogs) {
|
|
188
186
|
rookConfigurationManager.enableLocalLogs()
|
|
189
187
|
rookSamsung.enableLocalLogs()
|
|
@@ -238,43 +236,1637 @@ class RookSdkModule(
|
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
238
|
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
override fun revokeDataSource(
|
|
242
|
+
userid: String?,
|
|
243
|
+
type: String?,
|
|
244
|
+
promise: Promise?
|
|
245
|
+
) {
|
|
246
|
+
if (promise == null) return
|
|
247
|
+
|
|
248
|
+
if (type == null || type == "") {
|
|
249
|
+
promise.reject(code = "1001", message = "the type is missing")
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (userid == null || userid == "") {
|
|
254
|
+
promise.reject(code = "1001", message = "the user_id is missing")
|
|
255
|
+
return
|
|
256
|
+
}
|
|
241
257
|
|
|
258
|
+
val parsed = mapToDataSourceType(type)
|
|
259
|
+
if(parsed == null) {
|
|
260
|
+
promise.reject(code = "1001", message = "Invalid datasource")
|
|
261
|
+
return
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
scope.launch {
|
|
265
|
+
rookApiSources.revokeDataSource(userID = userid, dataSource = parsed).fold({
|
|
266
|
+
promise.resolve(true)
|
|
267
|
+
}, {
|
|
268
|
+
if (it is ApiException) {
|
|
269
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
270
|
+
} else {
|
|
271
|
+
promise.reject("1001", it.message, it)
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
}
|
|
242
275
|
}
|
|
243
276
|
|
|
244
|
-
|
|
277
|
+
override fun getDataSourceAuthorizer(
|
|
278
|
+
props: ReadableMap?,
|
|
279
|
+
promise: Promise?
|
|
280
|
+
) {
|
|
281
|
+
if(promise == null) return
|
|
282
|
+
|
|
283
|
+
if (props == null){
|
|
284
|
+
promise.reject(code = "1001", message = "user and datasource missing")
|
|
285
|
+
return
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
val source = props.getString("dataSource") ?: ""
|
|
289
|
+
val redirect = props.getString("redirectURL")
|
|
290
|
+
val userid = props.getString("userID") ?: ""
|
|
291
|
+
|
|
292
|
+
if (source == "" || userid == "") {
|
|
293
|
+
promise.reject(code = "1001", message = "user and datasource missing")
|
|
294
|
+
return
|
|
295
|
+
}
|
|
296
|
+
|
|
245
297
|
scope.launch {
|
|
246
|
-
|
|
298
|
+
rookApiSources.getDataSourceAuthorizer(
|
|
299
|
+
dataSource = source,
|
|
300
|
+
redirectUrl = redirect,
|
|
301
|
+
userID = userid
|
|
302
|
+
).fold({ value ->
|
|
303
|
+
promise.resolve(gsonBuilder.toJson(value))
|
|
304
|
+
}, {
|
|
305
|
+
if (it is ApiException) {
|
|
306
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
307
|
+
} else {
|
|
308
|
+
promise.reject("1001", it.message, it)
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
}
|
|
247
313
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
314
|
+
override fun getAuthorizedDataSourcesV2(
|
|
315
|
+
userid: String?,
|
|
316
|
+
promise: Promise?
|
|
317
|
+
) {
|
|
318
|
+
if(promise == null) return
|
|
319
|
+
|
|
320
|
+
if(userid == null || userid == "") {
|
|
321
|
+
promise.reject(code = "1001", message = "missing user id")
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
scope.launch {
|
|
326
|
+
rookApiSources.getAuthorizedDataSourcesV2(
|
|
327
|
+
userID = userid
|
|
328
|
+
).fold(
|
|
329
|
+
{
|
|
330
|
+
promise.resolve(gsonBuilder.toJson(it))
|
|
331
|
+
}, {
|
|
332
|
+
if (it is ApiException) {
|
|
333
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
334
|
+
} else {
|
|
335
|
+
promise.reject("1001", it.message, it)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
override fun getUserID(promise: Promise?) {
|
|
343
|
+
if (promise == null) return
|
|
344
|
+
|
|
345
|
+
scope.launch {
|
|
346
|
+
try {
|
|
347
|
+
val user = rookConfigurationManager.getUserID()
|
|
348
|
+
promise.resolve(user)
|
|
349
|
+
}
|
|
350
|
+
catch (it: Exception) {
|
|
351
|
+
if (it is HCException) {
|
|
352
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
353
|
+
} else {
|
|
354
|
+
promise.reject("1001", it.message, it)
|
|
355
|
+
}
|
|
251
356
|
}
|
|
252
357
|
}
|
|
253
358
|
}
|
|
254
359
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
* This method emits a message event to the React Native side via the
|
|
258
|
-
* `ROOK_NOTIFICATION` channel, allowing communication from the native module.
|
|
259
|
-
*
|
|
260
|
-
* @param message A ReadableMap containing the message data to send.
|
|
261
|
-
* @param promise A promise object that resolves with true if the message was sent successfully.
|
|
262
|
-
*/
|
|
263
|
-
@ReactMethod
|
|
264
|
-
fun sendMessageToBroadcast(message: ReadableMap, promise: Promise) {
|
|
265
|
-
if (listenerCount <= 0) return
|
|
360
|
+
override fun updateUserID(userID: String?, promise: Promise?) {
|
|
361
|
+
if(promise == null) return
|
|
266
362
|
|
|
267
|
-
|
|
268
|
-
|
|
363
|
+
if (userID == null || userID == "") {
|
|
364
|
+
promise.reject(code = "1001", message = "Missing user id")
|
|
365
|
+
return
|
|
366
|
+
}
|
|
269
367
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
368
|
+
scope.launch {
|
|
369
|
+
try {
|
|
370
|
+
if (SamsungAvailability.isSamsungAvailable(rookSamsung)) {
|
|
371
|
+
val samsungResult = rookSamsung.updateUserID(userID)
|
|
273
372
|
|
|
274
|
-
|
|
373
|
+
if (samsungResult.isFailure) {
|
|
374
|
+
println("We couldn't initiate the user id in Samsung Health")
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
samsungResult.getOrThrow()
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
val healthConnectResult = rookConfigurationManager.updateUserID(userID)
|
|
381
|
+
|
|
382
|
+
if (healthConnectResult.isFailure) {
|
|
383
|
+
println("We couldn't initiate the user id in Health Connect")
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
healthConnectResult.getOrThrow()
|
|
387
|
+
|
|
388
|
+
promise.resolve(true)
|
|
389
|
+
} catch (it: Exception) {
|
|
390
|
+
if (it is HCException) {
|
|
391
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
392
|
+
} else {
|
|
393
|
+
promise.reject("1001", it.message, it)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
override fun removeUserFromRook(
|
|
400
|
+
sources: ReadableArray?,
|
|
401
|
+
promise: Promise?
|
|
402
|
+
) {
|
|
403
|
+
if(promise == null)return
|
|
404
|
+
if (sources == null) {
|
|
405
|
+
promise.reject(code = "1001", message = "Missing datasource")
|
|
406
|
+
return
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
scope.launch {
|
|
410
|
+
try {
|
|
411
|
+
val sources = DatasourceUtils.readableArrayToSourceList(sources)
|
|
412
|
+
|
|
413
|
+
if(Source.HEALTH_CONNECT in sources) {
|
|
414
|
+
val hcResult = rookConfigurationManager.deleteUserFromRook()
|
|
415
|
+
hcResult.getOrThrow()
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if(Source.SAMSUNG_HEALTH in sources && SamsungAvailability.isSamsungAvailable(rookSamsung)) {
|
|
419
|
+
val hcResult = rookSamsung.deleteUserFromRook()
|
|
420
|
+
hcResult.getOrThrow()
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
promise.resolve(true)
|
|
424
|
+
}
|
|
425
|
+
catch (it: Exception) {
|
|
426
|
+
if (it is HCException) {
|
|
427
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
428
|
+
} else {
|
|
429
|
+
promise.reject("1001", it.message, it)
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
override fun syncUserTimeZone(promise: Promise?) {
|
|
436
|
+
if(promise == null) return
|
|
437
|
+
|
|
438
|
+
scope.launch {
|
|
439
|
+
val result = rookConfigurationManager.syncUserTimeZone()
|
|
440
|
+
|
|
441
|
+
result.fold({
|
|
442
|
+
promise.resolve(true)
|
|
443
|
+
}, {
|
|
444
|
+
if (it is HCException) {
|
|
445
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
446
|
+
} else {
|
|
447
|
+
promise.reject("1001", it.message, it)
|
|
448
|
+
}
|
|
449
|
+
})
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
override fun getHealthConnectDiagnosticState(promise: Promise?) {
|
|
454
|
+
if (promise == null) return
|
|
455
|
+
|
|
456
|
+
scope.launch {
|
|
457
|
+
try {
|
|
458
|
+
val result = rookConfigurationManager.getDiagnosticState().getOrThrow()
|
|
459
|
+
promise.resolve(gsonBuilder.toJson(result))
|
|
460
|
+
} catch (it: Exception) {
|
|
461
|
+
if (it is HCException) {
|
|
462
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
463
|
+
} else {
|
|
464
|
+
promise.reject("1001", it.message, it)
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
override fun getSamsungHealthDiagnosticState(promise: Promise?) {
|
|
471
|
+
if (promise == null) return
|
|
472
|
+
|
|
473
|
+
scope.launch {
|
|
474
|
+
try {
|
|
475
|
+
val result = rookSamsung.getDiagnosticState().getOrThrow()
|
|
476
|
+
promise.resolve(gsonBuilder.toJson(result))
|
|
477
|
+
} catch (it: Exception) {
|
|
478
|
+
if (it is HCException) {
|
|
479
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
480
|
+
} else {
|
|
481
|
+
promise.reject("1001", it.message, it)
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
override fun isStepsAvailable(promise: Promise?) {
|
|
488
|
+
if (promise == null) return
|
|
489
|
+
promise.resolve(rookStepsManager.isAvailable())
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
override fun enableBackgroundAndroidSteps(promise: Promise?) {
|
|
493
|
+
if(promise == null) return
|
|
494
|
+
|
|
495
|
+
rookStepsManager.enableBackgroundAndroidSteps().fold({
|
|
496
|
+
promise.resolve(true)
|
|
497
|
+
}, {
|
|
498
|
+
if (it is HCException) {
|
|
499
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
500
|
+
} else {
|
|
501
|
+
promise.reject("1001", it.message, it)
|
|
502
|
+
}
|
|
503
|
+
})
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
override fun disableBackgroundAndroidSteps(promise: Promise?) {
|
|
507
|
+
if(promise == null) return
|
|
508
|
+
|
|
509
|
+
rookStepsManager
|
|
510
|
+
.disableBackgroundAndroidSteps()
|
|
511
|
+
.fold({
|
|
512
|
+
promise.resolve(true)
|
|
513
|
+
}, {
|
|
514
|
+
if (it is HCException) {
|
|
515
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
516
|
+
} else {
|
|
517
|
+
promise.reject("1001", it.message, it)
|
|
518
|
+
}
|
|
519
|
+
})
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
override fun isBackgroundAndroidStepsActive(promise: Promise?) {
|
|
523
|
+
if(promise == null) return
|
|
524
|
+
|
|
525
|
+
scope.launch {
|
|
526
|
+
val response = rookStepsManager.isBackgroundAndroidStepsActive()
|
|
527
|
+
promise.resolve(response)
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
override fun syncTodayAndroidStepsCount(promise: Promise?) {
|
|
532
|
+
if(promise == null) return
|
|
533
|
+
|
|
534
|
+
scope.launch {
|
|
535
|
+
rookStepsManager
|
|
536
|
+
.syncTodayAndroidStepsCount()
|
|
537
|
+
.fold({
|
|
538
|
+
promise.resolve(it.toString())
|
|
539
|
+
}, {
|
|
540
|
+
if (it is HCException) {
|
|
541
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
542
|
+
} else {
|
|
543
|
+
promise.reject("1001", it.message, it)
|
|
544
|
+
}
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
override fun androidHasBackgroundPermissions(promise: Promise?) {
|
|
550
|
+
if(promise == null) return
|
|
551
|
+
|
|
552
|
+
try {
|
|
553
|
+
val result = rookPermissionsManager.checkAndroidPermissions()
|
|
554
|
+
promise.resolve(result)
|
|
555
|
+
}
|
|
556
|
+
catch (it: Exception) {
|
|
557
|
+
if (it is HCException) {
|
|
558
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
559
|
+
} else {
|
|
560
|
+
promise.reject("1001", it.message, it)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
override fun checkHealthConnectAvailability(promise: Promise?) {
|
|
566
|
+
if(promise == null) return
|
|
567
|
+
|
|
568
|
+
val r = rookPermissionsManager.checkHealthConnectAvailability()
|
|
569
|
+
|
|
570
|
+
when(r) {
|
|
571
|
+
HealthConnectAvailability.INSTALLED -> promise.resolve("INSTALLED")
|
|
572
|
+
HealthConnectAvailability.NOT_INSTALLED -> promise.resolve("NOT_INSTALLED")
|
|
573
|
+
HealthConnectAvailability.NOT_SUPPORTED -> promise.resolve("NOT_SUPPORTED")
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
override fun checkHealthConnectBackgroundReadStatus(promise: Promise?) {
|
|
578
|
+
if(promise == null) return
|
|
579
|
+
|
|
580
|
+
scope.launch {
|
|
581
|
+
rookPermissionsManager.checkBackgroundReadStatus().fold(
|
|
582
|
+
{ status ->
|
|
583
|
+
when (status) {
|
|
584
|
+
BackgroundReadStatus.UNAVAILABLE -> promise.resolve("UNAVAILABLE")
|
|
585
|
+
BackgroundReadStatus.PERMISSION_NOT_GRANTED -> promise.resolve("PERMISSION_NOT_GRANTED")
|
|
586
|
+
BackgroundReadStatus.PERMISSION_GRANTED -> promise.resolve("PERMISSION_GRANTED")
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
if (it is HCException) {
|
|
591
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
592
|
+
} else {
|
|
593
|
+
promise.reject("1001", it.message, it)
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
)
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
override fun checkSamsungAvailability(promise: Promise?) {
|
|
601
|
+
if (promise == null) return
|
|
602
|
+
|
|
603
|
+
scope.launch {
|
|
604
|
+
rookSamsung.checkSamsungHealthAvailability().fold(
|
|
605
|
+
{ availability ->
|
|
606
|
+
when (availability) {
|
|
607
|
+
SamsungHealthAvailability.INSTALLED -> promise.resolve("INSTALLED")
|
|
608
|
+
SamsungHealthAvailability.NOT_INSTALLED -> promise.resolve("NOT_INSTALLED")
|
|
609
|
+
SamsungHealthAvailability.OUTDATED -> promise.resolve("OUTDATED")
|
|
610
|
+
SamsungHealthAvailability.DISABLED -> promise.resolve("DISABLED")
|
|
611
|
+
SamsungHealthAvailability.NOT_READY -> promise.resolve("NOT_READY")
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
promise.reject(it)
|
|
616
|
+
},
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
override fun healthConnectHasPartialPermissions(promise: Promise?) {
|
|
623
|
+
if(promise == null) return
|
|
624
|
+
|
|
625
|
+
scope.launch {
|
|
626
|
+
val result = rookPermissionsManager.checkHealthConnectPermissionsPartially()
|
|
627
|
+
|
|
628
|
+
result.fold({
|
|
629
|
+
promise.resolve(it)
|
|
630
|
+
}, {
|
|
631
|
+
if (it is HCException) {
|
|
632
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
633
|
+
} else {
|
|
634
|
+
promise.reject("1001", it.message, it)
|
|
635
|
+
}
|
|
636
|
+
})
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
override fun healthConnectHasPermissions(promise: Promise?) {
|
|
641
|
+
if(promise == null) return
|
|
642
|
+
|
|
643
|
+
scope.launch {
|
|
644
|
+
val result = rookPermissionsManager.checkHealthConnectPermissions()
|
|
645
|
+
|
|
646
|
+
result.fold({
|
|
647
|
+
promise.resolve(it)
|
|
648
|
+
}, {
|
|
649
|
+
if (it is HCException) {
|
|
650
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
651
|
+
} else {
|
|
652
|
+
promise.reject("1001", it.message, it)
|
|
653
|
+
}
|
|
654
|
+
})
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
override fun samsungHealthHasPermissions(promise: Promise?) {
|
|
659
|
+
if(promise == null) return
|
|
660
|
+
|
|
661
|
+
scope.launch {
|
|
662
|
+
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
663
|
+
promise.reject(Throwable("Samsung health is not available"))
|
|
664
|
+
return@launch
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
rookSamsung.checkSamsungHealthPermissions(SamsungHealthPermission.entries.toSet()).fold(
|
|
668
|
+
{ hasAllPermissions ->
|
|
669
|
+
promise.resolve(hasAllPermissions)
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
if (it is SHException) {
|
|
673
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
674
|
+
} else {
|
|
675
|
+
promise.reject("1001", it.message, it)
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
)
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
override fun samsungHealthHasPartialPermissions(promise: Promise?) {
|
|
683
|
+
if(promise == null) return
|
|
684
|
+
|
|
685
|
+
scope.launch {
|
|
686
|
+
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
687
|
+
promise.reject(Throwable("Samsung health is not available"))
|
|
688
|
+
return@launch
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
rookSamsung.checkSamsungHealthPermissionsPartially(SamsungHealthPermission.entries.toSet()).fold(
|
|
692
|
+
{ hasAllPermissions ->
|
|
693
|
+
promise.resolve(hasAllPermissions)
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
if (it is SHException) {
|
|
697
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
698
|
+
} else {
|
|
699
|
+
promise.reject("1001", it.message, it)
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
)
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
override fun openHealthConnectSettings(promise: Promise?) {
|
|
707
|
+
if (promise == null) return
|
|
708
|
+
|
|
709
|
+
scope.launch {
|
|
710
|
+
val result = rookPermissionsManager.openHealthConnectSettings()
|
|
711
|
+
|
|
712
|
+
result.fold({
|
|
713
|
+
promise.resolve(true)
|
|
714
|
+
},{
|
|
715
|
+
if (it is HCException) {
|
|
716
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
717
|
+
} else {
|
|
718
|
+
promise.reject("1001", it.message, it)
|
|
719
|
+
}
|
|
720
|
+
})
|
|
721
|
+
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
override fun requestAndroidBackgroundPermissions(promise: Promise?) {
|
|
726
|
+
if (promise == null) return
|
|
727
|
+
|
|
728
|
+
try {
|
|
729
|
+
val response = rookPermissionsManager.requestAndroidPermissions()
|
|
730
|
+
|
|
731
|
+
if (response == RequestPermissionsStatus.REQUEST_SENT)
|
|
732
|
+
promise.resolve("REQUEST_SENT")
|
|
733
|
+
else promise.resolve("ALREADY_GRANTED")
|
|
734
|
+
}
|
|
735
|
+
catch (it: Exception) {
|
|
736
|
+
if (it is HCException) {
|
|
737
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
738
|
+
} else {
|
|
739
|
+
promise.reject("1001", it.message, it)
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
override fun requestHealthConnectPermissions(promise: Promise?) {
|
|
745
|
+
if (promise == null) return
|
|
746
|
+
|
|
747
|
+
scope.launch {
|
|
748
|
+
rookPermissionsManager.requestHealthConnectPermissions().fold({
|
|
749
|
+
when(it) {
|
|
750
|
+
RequestPermissionsStatus.REQUEST_SENT -> {
|
|
751
|
+
promise.resolve("REQUEST_SENT")
|
|
752
|
+
}
|
|
753
|
+
RequestPermissionsStatus .ALREADY_GRANTED -> {
|
|
754
|
+
promise.resolve("ALREADY_GRANTED")
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}, {
|
|
758
|
+
if (it is HCException) {
|
|
759
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
760
|
+
} else {
|
|
761
|
+
promise.reject("1001", it.message, it)
|
|
762
|
+
}
|
|
763
|
+
})
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
override fun requestSamsungHealthPermissions(
|
|
769
|
+
permissions: ReadableArray?,
|
|
770
|
+
promise: Promise?
|
|
771
|
+
) {
|
|
772
|
+
if (promise == null) return
|
|
773
|
+
|
|
774
|
+
if (permissions == null){
|
|
775
|
+
promise.reject(code = "1001", message = "Missing permissions")
|
|
776
|
+
return
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
val shPermissions = PermissionConversion.parseSamsungPermissions(permissions)
|
|
780
|
+
|
|
781
|
+
scope.launch {
|
|
782
|
+
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)) {
|
|
783
|
+
promise.reject(Throwable("Samsung Health is not available"))
|
|
784
|
+
return@launch
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
rookSamsung.requestSamsungHealthPermissions(shPermissions).fold(
|
|
788
|
+
{
|
|
789
|
+
when (it) {
|
|
790
|
+
SHRequestPermissionsStatus.ALREADY_GRANTED -> promise.resolve("ALREADY_GRANTED")
|
|
791
|
+
SHRequestPermissionsStatus.REQUEST_SENT -> promise.resolve("REQUEST_SENT")
|
|
792
|
+
}
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
if (it is SHException) {
|
|
796
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
797
|
+
} else {
|
|
798
|
+
promise.reject("1001", it.message, it)
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
)
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
override fun revokeHealthConnectPermissions(promise: Promise?) {
|
|
806
|
+
if(promise == null) return
|
|
807
|
+
|
|
808
|
+
scope.launch {
|
|
809
|
+
rookPermissionsManager.revokeHealthConnectPermissions()
|
|
810
|
+
.fold({
|
|
811
|
+
promise.resolve(true)
|
|
812
|
+
}, {
|
|
813
|
+
if (it is HCException) {
|
|
814
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
815
|
+
} else {
|
|
816
|
+
promise.reject("1001", it.message, it)
|
|
817
|
+
}
|
|
818
|
+
})
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
override fun shouldRequestAndroidBackgroundPermissions(promise: Promise?) {
|
|
823
|
+
if (promise == null) return
|
|
824
|
+
|
|
825
|
+
val activity = reactApplicationContext.currentActivity
|
|
826
|
+
|
|
827
|
+
if (activity == null) {
|
|
828
|
+
promise.reject(Exception("Error trying to request permissions"))
|
|
829
|
+
return
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
try {
|
|
833
|
+
val r = RookPermissionsManager.shouldRequestAndroidPermissions(activity)
|
|
834
|
+
promise.resolve(r)
|
|
835
|
+
}
|
|
836
|
+
catch (it: Exception) {
|
|
837
|
+
if (it is HCException) {
|
|
838
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
839
|
+
} else {
|
|
840
|
+
promise.reject("1001", it.message, it)
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
override fun getHealthConnectSleepSummary(
|
|
846
|
+
date: String?,
|
|
847
|
+
promise: Promise?
|
|
848
|
+
) {
|
|
849
|
+
if (promise == null) return
|
|
850
|
+
|
|
851
|
+
if (date == null || date == ""){
|
|
852
|
+
promise.reject(code = "1001", message = "Missing date")
|
|
853
|
+
return
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
857
|
+
|
|
858
|
+
scope.launch {
|
|
859
|
+
rookHealthConnect.getSleepSummary(localDate).fold(
|
|
860
|
+
{
|
|
861
|
+
when (it) {
|
|
862
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
863
|
+
promise.reject("HealthConnectSleepSummary", "Records Not Found For Date: $date")
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
is SyncStatusWithData.Synced<List<HCSleepSummary>> -> {
|
|
867
|
+
val result =gsonBuilder.toJson(it.data)
|
|
868
|
+
promise.resolve(result)
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
if (it is HCException) {
|
|
874
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
875
|
+
} else {
|
|
876
|
+
promise.reject("1001", it.message, it)
|
|
877
|
+
}
|
|
878
|
+
},
|
|
879
|
+
)
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
override fun getSamsungSleepSummary(
|
|
884
|
+
date: String?,
|
|
885
|
+
promise: Promise?
|
|
886
|
+
) {
|
|
887
|
+
if (promise == null) return
|
|
888
|
+
|
|
889
|
+
if (date == null || date == ""){
|
|
890
|
+
promise.reject(code = "1001", message = "Missin date")
|
|
891
|
+
return
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
895
|
+
|
|
896
|
+
scope.launch {
|
|
897
|
+
rookSamsung.getSleepSummary(localDate).fold(
|
|
898
|
+
{
|
|
899
|
+
when (it) {
|
|
900
|
+
SHSyncStatusWithData.RecordsNotFound -> {
|
|
901
|
+
promise.reject("SamsungSleepSummary", "Records Not Found For Date: $date")
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
is SHSyncStatusWithData.Synced<List<SHSleepSummary>> -> {
|
|
905
|
+
promise.resolve(gsonBuilder.toJson(it.data))
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
if (it is SHException) {
|
|
911
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
912
|
+
} else {
|
|
913
|
+
promise.reject("1001", it.message, it)
|
|
914
|
+
}
|
|
915
|
+
},
|
|
916
|
+
)
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
override fun getHealthConnectBodySummary(
|
|
921
|
+
date: String?,
|
|
922
|
+
promise: Promise?
|
|
923
|
+
) {
|
|
924
|
+
if (promise == null) return
|
|
925
|
+
|
|
926
|
+
if (date == null || date == ""){
|
|
927
|
+
promise.reject(code = "1001", message = "missing date")
|
|
928
|
+
return
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
932
|
+
|
|
933
|
+
scope.launch {
|
|
934
|
+
rookHealthConnect.getBodySummary(localDate).fold(
|
|
935
|
+
{
|
|
936
|
+
when (it) {
|
|
937
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
938
|
+
promise.reject("HealthConnectBodySummary", "Records Not Found For Date: $date")
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
is SyncStatusWithData.Synced<HCBodySummary> -> {
|
|
942
|
+
promise.resolve(gsonBuilder.toJson(it.data))
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
if (it is HCException) {
|
|
948
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
949
|
+
} else {
|
|
950
|
+
promise.reject("1001", it.message, it)
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
)
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
override fun getSamsungBodySummary(
|
|
958
|
+
date: String?,
|
|
959
|
+
promise: Promise?
|
|
960
|
+
) {
|
|
961
|
+
if (promise == null) return
|
|
962
|
+
|
|
963
|
+
if (date == null || date == ""){
|
|
964
|
+
promise.reject(code = "1001", message = "missing date")
|
|
965
|
+
return
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
969
|
+
|
|
970
|
+
scope.launch {
|
|
971
|
+
rookSamsung.getBodySummary(localDate).fold(
|
|
972
|
+
{
|
|
973
|
+
when (it) {
|
|
974
|
+
SHSyncStatusWithData.RecordsNotFound -> {
|
|
975
|
+
promise.reject("SamsungBodySummary", "Records Not Found For Date: $date")
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
is SHSyncStatusWithData.Synced<SHBodySummary> -> {
|
|
979
|
+
promise.resolve(gsonBuilder.toJson(it.data))
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
},
|
|
983
|
+
{
|
|
984
|
+
if (it is SHException) {
|
|
985
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
986
|
+
} else {
|
|
987
|
+
promise.reject("1001", it.message, it)
|
|
988
|
+
}
|
|
989
|
+
},
|
|
990
|
+
)
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
override fun getHealthConnectPhysicalSummary(
|
|
995
|
+
date: String?,
|
|
996
|
+
promise: Promise?
|
|
997
|
+
) {
|
|
998
|
+
if (promise == null) return
|
|
999
|
+
|
|
1000
|
+
if (date == null || date == ""){
|
|
1001
|
+
promise.reject(code = "1001", message = "missing date")
|
|
1002
|
+
return
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1006
|
+
|
|
1007
|
+
scope.launch {
|
|
1008
|
+
rookHealthConnect.getPhysicalSummary(localDate).fold(
|
|
1009
|
+
{
|
|
1010
|
+
when (it) {
|
|
1011
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
1012
|
+
promise.reject("HealthConnectPhysicalSummary", "Records Not Found For Date: $date")
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
is SyncStatusWithData.Synced<HCPhysicalSummary> -> {
|
|
1016
|
+
promise.resolve(gsonBuilder.toJson(it.data))
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
if (it is HCException) {
|
|
1022
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1023
|
+
} else {
|
|
1024
|
+
promise.reject("1001", it.message, it)
|
|
1025
|
+
}
|
|
1026
|
+
},
|
|
1027
|
+
)
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
override fun getSamsungPhysicalSummary(
|
|
1032
|
+
date: String?,
|
|
1033
|
+
promise: Promise?
|
|
1034
|
+
) {
|
|
1035
|
+
if (promise == null) return
|
|
1036
|
+
|
|
1037
|
+
if (date == null || date == ""){
|
|
1038
|
+
promise.reject(code = "1001", message = "missing date")
|
|
1039
|
+
return
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1043
|
+
|
|
1044
|
+
scope.launch {
|
|
1045
|
+
rookSamsung.getPhysicalSummary(localDate).fold(
|
|
1046
|
+
{
|
|
1047
|
+
when (it) {
|
|
1048
|
+
SHSyncStatusWithData.RecordsNotFound -> {
|
|
1049
|
+
promise.reject("SamsungPhysicalSummary", "Records Not Found For Date: $date")
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
is SHSyncStatusWithData.Synced<SHPhysicalSummary> -> {
|
|
1053
|
+
promise.resolve(gsonBuilder.toJson(it.data))
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
},
|
|
1057
|
+
{
|
|
1058
|
+
if (it is SHException) {
|
|
1059
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1060
|
+
} else {
|
|
1061
|
+
promise.reject("1001", it.message, it)
|
|
1062
|
+
}
|
|
1063
|
+
},
|
|
1064
|
+
)
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
override fun getHealthConnectActivityEvents(
|
|
1069
|
+
date: String?,
|
|
1070
|
+
promise: Promise?
|
|
1071
|
+
) {
|
|
1072
|
+
if (promise == null) return
|
|
1073
|
+
|
|
1074
|
+
if (date == null || date == ""){
|
|
1075
|
+
promise.reject(code = "1001", message = "missing date")
|
|
1076
|
+
return
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1080
|
+
|
|
1081
|
+
scope.launch {
|
|
1082
|
+
rookHealthConnect.getActivityEvents(localDate).fold(
|
|
1083
|
+
{
|
|
1084
|
+
when (it) {
|
|
1085
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
1086
|
+
promise.reject("HealthConnectActivityEvents", "Records Not Found For Date: $date")
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
is SyncStatusWithData.Synced<List<HCActivityEvent>> -> {
|
|
1090
|
+
promise.resolve(gsonBuilder.toJson(it.data))
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
{
|
|
1095
|
+
if (it is HCException) {
|
|
1096
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1097
|
+
} else {
|
|
1098
|
+
promise.reject("1001", it.message, it)
|
|
1099
|
+
}
|
|
1100
|
+
},
|
|
1101
|
+
)
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
override fun getSamsungActivityEvents(
|
|
1106
|
+
date: String?,
|
|
1107
|
+
promise: Promise?
|
|
1108
|
+
) {
|
|
1109
|
+
if (promise == null) return
|
|
1110
|
+
|
|
1111
|
+
if (date == null || date == ""){
|
|
1112
|
+
promise.reject(code = "1001", message = "missing date")
|
|
1113
|
+
return
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1117
|
+
|
|
1118
|
+
scope.launch {
|
|
1119
|
+
rookSamsung.getActivityEvents(localDate).fold(
|
|
1120
|
+
{
|
|
1121
|
+
when (it) {
|
|
1122
|
+
SHSyncStatusWithData.RecordsNotFound -> {
|
|
1123
|
+
promise.reject("SamsungActivityEvents", "Records Not Found For Date: $date")
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
is SHSyncStatusWithData.Synced<List<SHActivityEvent>> -> {
|
|
1127
|
+
promise.resolve(gsonBuilder.toJson(it.data))
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
{
|
|
1132
|
+
if (it is SHException) {
|
|
1133
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1134
|
+
} else {
|
|
1135
|
+
promise.reject("1001", it.message, it)
|
|
1136
|
+
}
|
|
1137
|
+
},
|
|
1138
|
+
)
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
@OptIn(ExperimentalRookApi::class)
|
|
1143
|
+
override fun writeHealthConnectMealData(
|
|
1144
|
+
meal: ReadableMap?,
|
|
1145
|
+
promise: Promise?
|
|
1146
|
+
) {
|
|
1147
|
+
if (promise == null) return
|
|
1148
|
+
|
|
1149
|
+
if (meal == null){
|
|
1150
|
+
promise.reject(code = "1001", message = "Missing meal data")
|
|
1151
|
+
return
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
val mealData = ReadableToWritable.mapReadableMapToHCMealData(meal)
|
|
1155
|
+
|
|
1156
|
+
scope.launch {
|
|
1157
|
+
RookWriteManager.writeNutritionEvent(reactApplicationContext, mealData).fold({
|
|
1158
|
+
promise.resolve(true)
|
|
1159
|
+
}, {
|
|
1160
|
+
if (it is HCException) {
|
|
1161
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1162
|
+
} else {
|
|
1163
|
+
promise.reject("1001", it.message, it)
|
|
1164
|
+
}
|
|
1165
|
+
})
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
override fun enableSamsungSync(promise: Promise?) {
|
|
1170
|
+
if (promise == null) return
|
|
1171
|
+
|
|
1172
|
+
scope.launch {
|
|
1173
|
+
rookSamsung.schedule(true)
|
|
1174
|
+
promise.resolve(true)
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
override fun disableSamsungSync(promise: Promise?) {
|
|
1179
|
+
if (promise == null) return
|
|
1180
|
+
|
|
1181
|
+
scope.launch {
|
|
1182
|
+
rookSamsung.cancel()
|
|
1183
|
+
promise.resolve(true)
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
override fun isSamsungSyncEnabled(promise: Promise?) {
|
|
1188
|
+
if (promise == null) return
|
|
1189
|
+
|
|
1190
|
+
scope.launch {
|
|
1191
|
+
rookSamsung.isScheduled().fold(
|
|
1192
|
+
{
|
|
1193
|
+
promise.resolve(it)
|
|
1194
|
+
},
|
|
1195
|
+
{
|
|
1196
|
+
if (it is SHException) {
|
|
1197
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1198
|
+
} else {
|
|
1199
|
+
promise.reject("1001", it.message, it)
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
)
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
override fun scheduleBackgroundSync(
|
|
1207
|
+
enableLogs: Boolean?,
|
|
1208
|
+
promise: Promise?
|
|
1209
|
+
) {
|
|
1210
|
+
if (promise == null) return
|
|
1211
|
+
|
|
1212
|
+
try {
|
|
1213
|
+
backgroundSyncManager.schedule(enableLogs ?: false)
|
|
1214
|
+
promise.resolve(true)
|
|
1215
|
+
}
|
|
1216
|
+
catch (e: Exception) {
|
|
1217
|
+
if (e is HCException) {
|
|
1218
|
+
promise.reject(e.code.toString(), e.message, e)
|
|
1219
|
+
} else {
|
|
1220
|
+
promise.reject("1001", e.message, e)
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
override fun cancelBackgroundSync(promise: Promise?) {
|
|
1226
|
+
if (promise == null) return
|
|
1227
|
+
|
|
1228
|
+
scope.launch {
|
|
1229
|
+
try {
|
|
1230
|
+
backgroundSyncManager.cancel()
|
|
1231
|
+
promise.resolve(true)
|
|
1232
|
+
} catch (e: Exception) {
|
|
1233
|
+
if (e is HCException) {
|
|
1234
|
+
promise.reject(e.code.toString(), e.message, e)
|
|
1235
|
+
} else {
|
|
1236
|
+
promise.reject("1001", e.message, e)
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
override fun isBackgroundSyncEnabled(promise: Promise?) {
|
|
1243
|
+
if (promise == null) return
|
|
1244
|
+
|
|
1245
|
+
scope.launch {
|
|
1246
|
+
backgroundSyncManager.isScheduled().fold(
|
|
1247
|
+
{
|
|
1248
|
+
promise.resolve(it)
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
if (it is HCException) {
|
|
1252
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1253
|
+
} else {
|
|
1254
|
+
promise.reject("1001", it.message, it)
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
)
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
override fun syncTodaySamsungHealthStepsCount(promise: Promise?) {
|
|
1262
|
+
if (promise == null) return
|
|
1263
|
+
|
|
1264
|
+
scope.launch {
|
|
1265
|
+
rookSamsung.getTodayStepsCount().fold({
|
|
1266
|
+
when (it) {
|
|
1267
|
+
SHSyncStatusWithData.RecordsNotFound -> {
|
|
1268
|
+
promise.reject("SamsungStepsCount", "Records Not Found")
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
is SHSyncStatusWithData.Synced -> {
|
|
1272
|
+
val steps = it.data
|
|
1273
|
+
promise.resolve(steps)
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
}, {
|
|
1277
|
+
if (it is SHException) {
|
|
1278
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1279
|
+
} else {
|
|
1280
|
+
promise.reject("1001", it.message, it)
|
|
1281
|
+
}
|
|
1282
|
+
})
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
override fun syncTodayHealthConnectStepsCount(promise: Promise?) {
|
|
1287
|
+
if (promise == null) return
|
|
1288
|
+
|
|
1289
|
+
scope.launch {
|
|
1290
|
+
rookSync.getTodayStepsCount().fold(
|
|
1291
|
+
{
|
|
1292
|
+
when (it) {
|
|
1293
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
1294
|
+
promise.reject("HealthConnectStepsCount", "Records Not Found")
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
is SyncStatusWithData.Synced -> {
|
|
1298
|
+
val steps = it.data
|
|
1299
|
+
promise.resolve(steps)
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
},
|
|
1303
|
+
{
|
|
1304
|
+
if (it is HCException) {
|
|
1305
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1306
|
+
} else {
|
|
1307
|
+
promise.reject("1001", it.message, it)
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
)
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
override fun syncTodayCaloriesCount(promise: Promise?) {
|
|
1315
|
+
if (promise == null) return
|
|
1316
|
+
|
|
1317
|
+
scope.launch {
|
|
1318
|
+
rookSync.getTodayCaloriesCount().fold(
|
|
1319
|
+
{
|
|
1320
|
+
when (it) {
|
|
1321
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
1322
|
+
promise.reject("7", "The SDK could not find any health data related with calories")
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
is SyncStatusWithData.Synced -> {
|
|
1326
|
+
val data = Arguments.createMap().apply {
|
|
1327
|
+
putDouble("basal", it.data.basal ?: 0.0)
|
|
1328
|
+
putDouble("active", it.data.active ?: 0.0)
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
promise.resolve(data)
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
if (it is HCException) {
|
|
1337
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1338
|
+
} else {
|
|
1339
|
+
promise.reject("1001", it.message, it)
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
)
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
override fun syncSHTodayCaloriesCount(promise: Promise?) {
|
|
1347
|
+
if (promise == null) return
|
|
1348
|
+
|
|
1349
|
+
scope.launch {
|
|
1350
|
+
rookSamsung.getTodayCaloriesCount().fold(
|
|
1351
|
+
{
|
|
1352
|
+
when (it) {
|
|
1353
|
+
SHSyncStatusWithData.RecordsNotFound -> {
|
|
1354
|
+
promise.reject("7", "The SDK could not find any health data related with calories")
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
is SHSyncStatusWithData.Synced -> {
|
|
1358
|
+
val data = Arguments.createMap().apply {
|
|
1359
|
+
putDouble("basal", it.data.basal ?: 0.0)
|
|
1360
|
+
putDouble("active", it.data.active ?: 0.0)
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
promise.resolve(data)
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
{
|
|
1368
|
+
if (it is SHException) {
|
|
1369
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1370
|
+
} else {
|
|
1371
|
+
promise.reject("1001", it.message, it)
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
)
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
override fun getTodayHeartRate(promise: Promise?) {
|
|
1379
|
+
if (promise == null) return
|
|
1380
|
+
|
|
1381
|
+
scope.launch {
|
|
1382
|
+
rookSync.getTodayHeartRate().fold(
|
|
1383
|
+
{ syncStatus ->
|
|
1384
|
+
when (syncStatus) {
|
|
1385
|
+
SyncStatusWithData.RecordsNotFound -> {
|
|
1386
|
+
promise.reject("7", "The SDK could not find any health data related with calories")
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
is SyncStatusWithData.Synced -> {
|
|
1390
|
+
promise.resolve(gsonBuilder.toJson(syncStatus.data))
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
},
|
|
1394
|
+
{
|
|
1395
|
+
if (it is HCException) {
|
|
1396
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1397
|
+
} else {
|
|
1398
|
+
promise.reject("1001", it.message, it)
|
|
1399
|
+
}
|
|
1400
|
+
},
|
|
1401
|
+
)
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
override fun getSHTodayHeartRate(promise: Promise?) {
|
|
1406
|
+
if (promise == null) return
|
|
1407
|
+
scope.launch {
|
|
1408
|
+
rookSamsung.getTodayHeartRate().fold(
|
|
1409
|
+
{ syncStatus ->
|
|
1410
|
+
when (syncStatus) {
|
|
1411
|
+
SHSyncStatusWithData.RecordsNotFound -> {
|
|
1412
|
+
promise.reject("7", "The SDK could not find any health data related with calories")
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
is SHSyncStatusWithData.Synced -> {
|
|
1416
|
+
promise.resolve(gsonBuilder.toJson(syncStatus.data))
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
},
|
|
1420
|
+
{
|
|
1421
|
+
if (it is HCException) {
|
|
1422
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1423
|
+
} else {
|
|
1424
|
+
promise.reject("1001", it.message, it)
|
|
1425
|
+
}
|
|
1426
|
+
},
|
|
1427
|
+
)
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
override fun sync(cb: Callback?) {
|
|
1432
|
+
if (cb == null) return
|
|
1433
|
+
|
|
1434
|
+
scope.launch {
|
|
1435
|
+
rookSync.sync(true).fold({ result ->
|
|
1436
|
+
cb.invoke(null, result)
|
|
1437
|
+
}, {
|
|
1438
|
+
val params = Arguments.createMap().apply {
|
|
1439
|
+
if (it is HCException) {
|
|
1440
|
+
putString(it.code.toString(), it.message)
|
|
1441
|
+
} else {
|
|
1442
|
+
putString("1001", it.localizedMessage ?: it.message)
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
cb.invoke(params, false)
|
|
1447
|
+
})
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
override fun syncByDate(date: String?, cb: Callback?) {
|
|
1452
|
+
if(cb == null ) return
|
|
1453
|
+
|
|
1454
|
+
if (date == null || date == "") {
|
|
1455
|
+
cb.invoke(null, false)
|
|
1456
|
+
return
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1460
|
+
|
|
1461
|
+
scope.launch {
|
|
1462
|
+
val result = rookSync.sync(localDate)
|
|
1463
|
+
|
|
1464
|
+
try {
|
|
1465
|
+
val sleepSummaryStatus = result.sleepSummary.getOrThrow()
|
|
1466
|
+
val physicalSummaryStatus = result.physicalSummary.getOrThrow()
|
|
1467
|
+
val bodySummaryStatus = result.bodySummary.getOrThrow()
|
|
1468
|
+
|
|
1469
|
+
val noSleepData = sleepSummaryStatus == SyncStatus.RECORDS_NOT_FOUND
|
|
1470
|
+
val noPhysicalData = physicalSummaryStatus == SyncStatus.RECORDS_NOT_FOUND
|
|
1471
|
+
val noBodyData = bodySummaryStatus == SyncStatus.RECORDS_NOT_FOUND
|
|
1472
|
+
|
|
1473
|
+
if (noSleepData && noPhysicalData && noBodyData) {
|
|
1474
|
+
val throwable = HCRecordsNotFoundException("Sleep, Physical and Body summary")
|
|
1475
|
+
|
|
1476
|
+
val params = Arguments.createMap().apply {
|
|
1477
|
+
putString(throwable.code.toString(), throwable.message)
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
cb.invoke(params, false)
|
|
1481
|
+
} else {
|
|
1482
|
+
cb.invoke(null, true)
|
|
1483
|
+
}
|
|
1484
|
+
} catch (e: Exception) {
|
|
1485
|
+
val params = Arguments.createMap().apply {
|
|
1486
|
+
if (e is HCException){
|
|
1487
|
+
putString(e.code.toString(), e.message)
|
|
1488
|
+
} else {
|
|
1489
|
+
putString("1001", e.message ?: "Unknown error")
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
cb.invoke(params, false)
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
override fun syncByDefinition(
|
|
1499
|
+
summary: String?,
|
|
1500
|
+
date: String?,
|
|
1501
|
+
cb: Callback?
|
|
1502
|
+
) {
|
|
1503
|
+
if(cb == null ) return
|
|
1504
|
+
|
|
1505
|
+
if (date == null || date == "" || summary == null || summary == "") {
|
|
1506
|
+
cb.invoke(null, false)
|
|
1507
|
+
return
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1511
|
+
|
|
1512
|
+
val type = StringToSyncType.stringToSummary(summary)
|
|
1513
|
+
|
|
1514
|
+
scope.launch {
|
|
1515
|
+
val result = rookSync.sync(localDate, type)
|
|
1516
|
+
result.onSuccess {
|
|
1517
|
+
when (it) {
|
|
1518
|
+
SyncStatus.RECORDS_NOT_FOUND -> {
|
|
1519
|
+
val throwable = HCRecordsNotFoundException(type.toString())
|
|
1520
|
+
|
|
1521
|
+
val params = Arguments.createMap().apply {
|
|
1522
|
+
putString(throwable.code.toString(), throwable.message)
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
cb.invoke(params, false)
|
|
1526
|
+
}
|
|
1527
|
+
SyncStatus.SYNCED -> cb.invoke(null, true)
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
result.onFailure {
|
|
1532
|
+
val params = Arguments.createMap().apply {
|
|
1533
|
+
if (it is HCException) {
|
|
1534
|
+
putString(it.code.toString(), it.message)
|
|
1535
|
+
} else {
|
|
1536
|
+
putString("1001", it.localizedMessage ?: it.message)
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
cb.invoke(params, false)
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
override fun syncEvent(
|
|
1546
|
+
date: String?,
|
|
1547
|
+
event: String?,
|
|
1548
|
+
promise: Promise?
|
|
1549
|
+
) {
|
|
1550
|
+
if (promise == null) return
|
|
1551
|
+
if (event == null || event == "" || date == null || date == "") {
|
|
1552
|
+
promise.reject(code = "1001", message = "Missing parameters")
|
|
1553
|
+
return
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1557
|
+
val type = StringToSyncType.stringToEvent(event)
|
|
1558
|
+
|
|
1559
|
+
scope.launch {
|
|
1560
|
+
rookSync.syncEvents(localDate, type).fold({ result ->
|
|
1561
|
+
when(result) {
|
|
1562
|
+
SyncStatus.RECORDS_NOT_FOUND -> {
|
|
1563
|
+
val throwable = HCRecordsNotFoundException(type.toString())
|
|
1564
|
+
|
|
1565
|
+
promise.reject(throwable.code.toString(), throwable.message, throwable)
|
|
1566
|
+
}
|
|
1567
|
+
SyncStatus.SYNCED -> promise.resolve(true)
|
|
1568
|
+
}
|
|
1569
|
+
}, {
|
|
1570
|
+
if (it is HCException) {
|
|
1571
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1572
|
+
} else {
|
|
1573
|
+
promise.reject("1001", it.message, it)
|
|
1574
|
+
}
|
|
1575
|
+
})
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
override fun shSync(enableLogs: Boolean, cb: Callback?) {
|
|
1580
|
+
if (cb == null) return
|
|
1581
|
+
|
|
1582
|
+
scope.launch {
|
|
1583
|
+
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
1584
|
+
val params = Arguments.createMap().apply {
|
|
1585
|
+
putString("5", "Samsung health is not available")
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
cb.invoke(params, false)
|
|
1589
|
+
return@launch
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
rookSamsung.sync(enableLogs).fold(
|
|
1593
|
+
{
|
|
1594
|
+
cb(null, true)
|
|
1595
|
+
}, {
|
|
1596
|
+
val params = Arguments.createMap().apply {
|
|
1597
|
+
if (it is SHException) {
|
|
1598
|
+
putString(it.code.toString(), it.message)
|
|
1599
|
+
} else {
|
|
1600
|
+
putString("1001", it.localizedMessage ?: it.message)
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
cb.invoke(params, false)
|
|
1605
|
+
}
|
|
1606
|
+
)
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
override fun shSyncByDate(date: String?, cb: Callback?) {
|
|
1611
|
+
if (cb == null) return
|
|
1612
|
+
|
|
1613
|
+
val localDate = RookDateTime.stringToLocalDate(date ?: "")
|
|
1614
|
+
|
|
1615
|
+
scope.launch {
|
|
1616
|
+
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
1617
|
+
val params = Arguments.createMap().apply {
|
|
1618
|
+
putString("5", "Samsung health is not available")
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
cb.invoke(params, false)
|
|
1622
|
+
return@launch
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
val result = rookSamsung.sync(localDate)
|
|
1626
|
+
|
|
1627
|
+
try {
|
|
1628
|
+
val sleepSummaryStatus = result.sleepSummary.getOrThrow()
|
|
1629
|
+
val physicalSummaryStatus = result.physicalSummary.getOrThrow()
|
|
1630
|
+
val bodySummaryStatus = result.bodySummary.getOrThrow()
|
|
1631
|
+
|
|
1632
|
+
val noSleepData = sleepSummaryStatus == SHSyncStatus.RECORDS_NOT_FOUND
|
|
1633
|
+
val noPhysicalData = physicalSummaryStatus == SHSyncStatus.RECORDS_NOT_FOUND
|
|
1634
|
+
val noBodyData = bodySummaryStatus == SHSyncStatus.RECORDS_NOT_FOUND
|
|
1635
|
+
|
|
1636
|
+
if (noSleepData && noPhysicalData && noBodyData) {
|
|
1637
|
+
val throwable = HCRecordsNotFoundException("Sleep, Physical and Body summary")
|
|
1638
|
+
|
|
1639
|
+
val params = Arguments.createMap().apply {
|
|
1640
|
+
putString(throwable.code.toString(), throwable.message)
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
cb.invoke(params, false)
|
|
1644
|
+
} else {
|
|
1645
|
+
cb.invoke(null, true)
|
|
1646
|
+
}
|
|
1647
|
+
} catch (e: Exception) {
|
|
1648
|
+
val params = Arguments.createMap().apply {
|
|
1649
|
+
if (e is HCException){
|
|
1650
|
+
putString(e.code.toString(), e.message)
|
|
1651
|
+
} else {
|
|
1652
|
+
putString("1001", e.message ?: "Unknown error")
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
cb.invoke(params, false)
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
override fun shSyncByDefinition(
|
|
1662
|
+
summary: String?,
|
|
1663
|
+
date: String?,
|
|
1664
|
+
cb: Callback?
|
|
1665
|
+
) {
|
|
1666
|
+
if (cb == null) return
|
|
1667
|
+
if (summary == null || date == null) {
|
|
1668
|
+
cb.invoke(null, false)
|
|
1669
|
+
return
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1673
|
+
val type = StringToSyncType.stringToSamsungPillar(summary)
|
|
1674
|
+
|
|
1675
|
+
scope.launch {
|
|
1676
|
+
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
1677
|
+
val params = Arguments.createMap().apply {
|
|
1678
|
+
putString("5", "Samsung health is not available")
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
cb.invoke(params, false)
|
|
1682
|
+
return@launch
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
val result = rookSamsung.sync(localDate, type)
|
|
1686
|
+
result.onSuccess {
|
|
1687
|
+
when (it) {
|
|
1688
|
+
SHSyncStatus.RECORDS_NOT_FOUND -> {
|
|
1689
|
+
val throwable = HCRecordsNotFoundException(type.toString())
|
|
1690
|
+
|
|
1691
|
+
val params = Arguments.createMap().apply {
|
|
1692
|
+
putString(throwable.code.toString(), throwable.message)
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
cb.invoke(params, false)
|
|
1696
|
+
}
|
|
1697
|
+
SHSyncStatus.SYNCED -> cb.invoke(null, true)
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
result.onFailure {
|
|
1702
|
+
val params = Arguments.createMap().apply {
|
|
1703
|
+
if (it is HCException) {
|
|
1704
|
+
putString(it.code.toString(), it.message)
|
|
1705
|
+
} else {
|
|
1706
|
+
putString("1001", it.localizedMessage ?: it.message)
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
cb.invoke(params, false)
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
override fun shSyncEvent(
|
|
1716
|
+
date: String?,
|
|
1717
|
+
event: String?,
|
|
1718
|
+
promise: Promise?
|
|
1719
|
+
) {
|
|
1720
|
+
if(promise == null) return
|
|
1721
|
+
if (event == null || date == null){
|
|
1722
|
+
promise.reject(code = "1001", message = "Missing parameters")
|
|
1723
|
+
return
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
val localDate = RookDateTime.stringToLocalDate(date)
|
|
1727
|
+
val type = StringToSyncType.stringToSamsungEvent(event)
|
|
1728
|
+
|
|
1729
|
+
scope.launch {
|
|
1730
|
+
if (!SamsungAvailability.isSamsungAvailable(rookSamsung)){
|
|
1731
|
+
promise.reject(
|
|
1732
|
+
"5",
|
|
1733
|
+
"Samsung health is not available",
|
|
1734
|
+
Throwable("Samsung health is not available")
|
|
1735
|
+
)
|
|
1736
|
+
return@launch
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
rookSamsung.syncEvents(localDate, type).fold({ result ->
|
|
1740
|
+
when(result) {
|
|
1741
|
+
SHSyncStatus.RECORDS_NOT_FOUND -> {
|
|
1742
|
+
val throwable = HCRecordsNotFoundException(type.toString())
|
|
1743
|
+
|
|
1744
|
+
promise.reject(throwable.code.toString(), throwable.message, throwable)
|
|
1745
|
+
}
|
|
1746
|
+
SHSyncStatus.SYNCED -> promise.resolve(true)
|
|
1747
|
+
}
|
|
1748
|
+
}, {
|
|
1749
|
+
if (it is HCException) {
|
|
1750
|
+
promise.reject(it.code.toString(), it.message, it)
|
|
1751
|
+
} else {
|
|
1752
|
+
promise.reject("1001", it.message, it)
|
|
1753
|
+
}
|
|
1754
|
+
})
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
override fun sendMessage(
|
|
1759
|
+
message: ReadableMap?,
|
|
1760
|
+
promise: Promise?
|
|
1761
|
+
) {
|
|
1762
|
+
if (message == null || promise == null || !reactApplicationContext.hasActiveReactInstance())
|
|
1763
|
+
return
|
|
1764
|
+
|
|
1765
|
+
val hash = ReadableToWritable.readableMapToHashMap(message)
|
|
1766
|
+
val writable = ReadableToWritable.hashMapToWritableMap(hash)
|
|
1767
|
+
|
|
1768
|
+
emitOnRookMessage(writable)
|
|
1769
|
+
promise.resolve(true)
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
|
|
1773
|
+
// ios methods
|
|
1774
|
+
private fun rejectFunction(promise: Promise) {
|
|
1775
|
+
promise.reject("1001", "This method is only available in android")
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
override fun getDiagnosticState(promise: Promise?) {
|
|
1779
|
+
if (promise == null) return
|
|
1780
|
+
rejectFunction(promise)
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
override fun enableBackGroundUpdates(promise: Promise?) {
|
|
1784
|
+
if (promise == null) return
|
|
1785
|
+
rejectFunction(promise)
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
override fun disableBackGroundUpdates(promise: Promise?) {
|
|
1789
|
+
if (promise == null) return
|
|
1790
|
+
rejectFunction(promise)
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
override fun isBackgroundUpdatesEnabled(promise: Promise?) {
|
|
1794
|
+
if (promise == null) return
|
|
1795
|
+
rejectFunction(promise)
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
override fun appleHealthHasPermissions(
|
|
1799
|
+
param: String?,
|
|
1800
|
+
promise: Promise?
|
|
1801
|
+
) {
|
|
1802
|
+
if (promise == null) return
|
|
1803
|
+
rejectFunction(promise)
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
override fun openAppleHealthSettings(promise: Promise?) {
|
|
1807
|
+
if (promise == null) return
|
|
1808
|
+
rejectFunction(promise)
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
override fun requestAppleHealthPermissions(
|
|
1812
|
+
permissions: ReadableArray?,
|
|
1813
|
+
promise: Promise?
|
|
1814
|
+
) {
|
|
1815
|
+
if (promise == null) return
|
|
1816
|
+
rejectFunction(promise)
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
override fun requestAppleWriteNutritionPermission(promise: Promise?) {
|
|
1820
|
+
if (promise == null) return
|
|
1821
|
+
rejectFunction(promise)
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
override fun getAppleHealthSleepSummary(
|
|
1825
|
+
date: String?,
|
|
1826
|
+
promise: Promise?
|
|
1827
|
+
) {
|
|
1828
|
+
if (promise == null) return
|
|
1829
|
+
rejectFunction(promise)
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
override fun getAppleHealthBodySummary(
|
|
1833
|
+
date: String?,
|
|
1834
|
+
promise: Promise?
|
|
1835
|
+
) {
|
|
1836
|
+
if (promise == null) return
|
|
1837
|
+
rejectFunction(promise)
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
override fun getAppleHealthPhysicalSummary(
|
|
1841
|
+
date: String?,
|
|
1842
|
+
promise: Promise?
|
|
1843
|
+
) {
|
|
1844
|
+
if (promise == null) return
|
|
1845
|
+
rejectFunction(promise)
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
override fun getAppleHealthActivityEvents(
|
|
1849
|
+
date: String?,
|
|
1850
|
+
promise: Promise?
|
|
1851
|
+
) {
|
|
1852
|
+
if (promise == null) return
|
|
1853
|
+
rejectFunction(promise)
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
override fun writeAppleHealthMealData(
|
|
1857
|
+
meal: ReadableMap?,
|
|
1858
|
+
promise: Promise?
|
|
1859
|
+
) {
|
|
1860
|
+
if (promise == null) return
|
|
1861
|
+
rejectFunction(promise)
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
override fun getTodayAppleHealthSteps(promise: Promise?) {
|
|
1865
|
+
if (promise == null) return
|
|
1866
|
+
rejectFunction(promise)
|
|
275
1867
|
}
|
|
276
1868
|
|
|
277
1869
|
companion object {
|
|
278
|
-
const val NAME = "
|
|
1870
|
+
const val NAME = "RNRookSdk"
|
|
279
1871
|
}
|
|
280
1872
|
}
|