react-native-rook-sdk 4.0.0-beta.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +3 -35
- package/android/build.gradle +45 -20
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +2 -1
- package/android/src/main/AndroidManifestNew.xml +36 -0
- package/android/src/main/java/com/rooksdk/RookSdkModule.kt +263 -11
- package/android/src/main/java/com/rooksdk/RookSdkPackage.kt +42 -26
- package/android/src/main/java/com/rooksdk/broadcasts/AndroidPermissionsReceiverTransmitter.kt +65 -0
- package/android/src/main/java/com/rooksdk/broadcasts/HealthConnectPermissionsReceiverTransmitter.kt +70 -0
- package/android/src/main/java/com/rooksdk/broadcasts/SamsungHealthPermissionsReceiverTransmitter.kt +52 -0
- package/android/src/main/java/com/rooksdk/modules/RookBackgroundSyncModule.kt +99 -0
- package/android/src/main/java/com/rooksdk/modules/RookConfigurationModule.kt +182 -0
- package/android/src/main/java/com/rooksdk/modules/RookLocalData.kt +301 -0
- package/android/src/main/java/com/rooksdk/modules/RookPermissionsModule.kt +382 -0
- package/android/src/main/java/com/rooksdk/modules/RookSourcesModule.kt +102 -0
- package/android/src/main/java/com/rooksdk/modules/RookStepsModule.kt +189 -0
- package/android/src/main/java/com/rooksdk/modules/RookSyncModule.kt +551 -0
- package/android/src/main/java/com/rooksdk/utils/DatasourcesUtils.kt +34 -0
- package/android/src/main/java/com/rooksdk/utils/PermissionConversion.kt +21 -0
- package/android/src/main/java/com/rooksdk/utils/ReadableToWritable.kt +145 -0
- package/android/src/main/java/com/rooksdk/utils/RookDateTime.kt +26 -0
- package/android/src/main/java/com/rooksdk/utils/RookGsonBuilder.kt +17 -0
- package/android/src/main/java/com/rooksdk/utils/SamsungAvailability.kt +21 -0
- package/android/src/main/java/com/rooksdk/utils/Source.kt +6 -0
- package/android/src/main/java/com/rooksdk/utils/StringToSyncType.kt +41 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/InstantSerializer.kt +19 -0
- package/android/src/main/java/com/rooksdk/utils/serializers/LocalDateSerializer.kt +21 -0
- package/android/src/main/res/drawable/ic_health_connect.xml +19 -0
- package/android/src/main/res/values/themes.xml +3 -0
- package/ios/DateHelper.swift +4 -4
- package/ios/EncodableDataSource.swift +3 -2
- package/ios/EncodableDataSourceAuthorizer.swift +3 -2
- package/ios/{HearRateMapper.swift → EncodableHeartRate.swift} +3 -3
- package/ios/EncodableRookDataSource.swift +36 -0
- package/ios/EncodableSDKState.swift +94 -0
- package/ios/EncodableStatusDataSources.swift +47 -0
- package/ios/NutritionMapper.swift +114 -0
- package/ios/RookBackground.swift +8 -5
- package/ios/RookBackgroundModule.h +5 -0
- package/ios/RookBackgroundModule.mm +15 -0
- package/ios/RookConfiguration.swift +34 -24
- package/ios/RookConfigurationModule.h +5 -0
- package/ios/RookConfigurationModule.mm +22 -0
- package/ios/RookExternalModule.h +5 -0
- package/ios/RookExternalModule.m +31 -0
- package/ios/{RookData.swift → RookLocalData.swift} +70 -48
- package/ios/RookPermissions.swift +33 -5
- package/ios/RookPermissionsModule.h +5 -0
- package/ios/RookPermissionsModule.mm +20 -0
- package/ios/RookSdk.h +2 -14
- package/ios/RookSdk.mm +97 -546
- package/ios/RookSources.swift +54 -60
- package/ios/RookSourcesModule.h +5 -0
- package/ios/RookSourcesModule.mm +18 -0
- package/ios/RookSync.h +5 -0
- package/ios/RookSync.m +35 -0
- package/ios/RookSync.swift +78 -48
- package/ios/SwiftTest.swift +18 -0
- package/ios/react-native-rook-sdk-Bridging-Header.h +12 -0
- package/{src/context/RookSyncGateContext.ts → lib/commonjs/context/RookSyncGateContext.js} +13 -10
- package/lib/commonjs/context/RookSyncGateContext.js.map +1 -0
- package/lib/commonjs/context/RookSyncGateProvider.js +108 -0
- package/lib/commonjs/context/RookSyncGateProvider.js.map +1 -0
- package/{src/context/RookSyncGateReducer.ts → lib/commonjs/context/RookSyncGateReducer.js} +44 -13
- package/lib/commonjs/context/RookSyncGateReducer.js.map +1 -0
- package/lib/commonjs/context/RookSyncGateTypes.js +6 -0
- package/lib/commonjs/context/RookSyncGateTypes.js.map +1 -0
- package/lib/commonjs/context/index.js +14 -0
- package/lib/commonjs/context/index.js.map +1 -0
- package/lib/commonjs/hooks/index.js +83 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/{src/hooks/useRookAPISources.ts → lib/commonjs/hooks/useRookAPISources.js} +36 -40
- package/lib/commonjs/hooks/useRookAPISources.js.map +1 -0
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js +88 -0
- package/lib/commonjs/hooks/useRookAndroidBackgroundSteps.js.map +1 -0
- package/lib/commonjs/hooks/useRookAndroidStepCounter.js +56 -0
- package/lib/commonjs/hooks/useRookAndroidStepCounter.js.map +1 -0
- package/lib/commonjs/hooks/useRookAppleHealth.js +63 -0
- package/lib/commonjs/hooks/useRookAppleHealth.js.map +1 -0
- package/lib/commonjs/hooks/useRookConfiguration.js +113 -0
- package/lib/commonjs/hooks/useRookConfiguration.js.map +1 -0
- package/lib/commonjs/hooks/useRookData.js +116 -0
- package/lib/commonjs/hooks/useRookData.js.map +1 -0
- package/lib/commonjs/hooks/useRookHealthConnect.js +70 -0
- package/lib/commonjs/hooks/useRookHealthConnect.js.map +1 -0
- package/lib/commonjs/hooks/useRookPermissions.js +223 -0
- package/lib/commonjs/hooks/useRookPermissions.js.map +1 -0
- package/lib/commonjs/hooks/useRookSamsungHealth.js +54 -0
- package/lib/commonjs/hooks/useRookSamsungHealth.js.map +1 -0
- package/lib/commonjs/hooks/useRookSync.js +148 -0
- package/lib/commonjs/hooks/useRookSync.js.map +1 -0
- package/lib/commonjs/hooks/useRookVariables.js +93 -0
- package/lib/commonjs/hooks/useRookVariables.js.map +1 -0
- package/lib/commonjs/index.js +121 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/hook/useRookAutoSync.js +261 -0
- package/lib/commonjs/modules/hook/useRookAutoSync.js.map +1 -0
- package/lib/commonjs/modules/types/sendMessageBroadcast.js +2 -0
- package/lib/commonjs/modules/types/sendMessageBroadcast.js.map +1 -0
- package/lib/commonjs/modules/utils/errors.js +12 -0
- package/lib/commonjs/modules/utils/errors.js.map +1 -0
- package/lib/commonjs/types/ActivityEvent.js +6 -0
- package/lib/commonjs/types/ActivityEvent.js.map +1 -0
- package/lib/commonjs/types/AppleHealthNutritionEvent.js +77 -0
- package/lib/commonjs/types/AppleHealthNutritionEvent.js.map +1 -0
- package/lib/commonjs/types/AppleHealthPermissions.js +57 -0
- package/lib/commonjs/types/AppleHealthPermissions.js.map +1 -0
- package/lib/commonjs/types/AuthorizedSources.js +6 -0
- package/lib/commonjs/types/AuthorizedSources.js.map +1 -0
- package/lib/commonjs/types/BodySummary.js +6 -0
- package/lib/{module/types/Rook.js.map → commonjs/types/BodySummary.js.map} +1 -1
- package/lib/commonjs/types/DataSource.js +16 -0
- package/lib/commonjs/types/DataSource.js.map +1 -0
- package/lib/commonjs/types/DiagnosticState.js +2 -0
- package/lib/commonjs/types/DiagnosticState.js.map +1 -0
- package/lib/commonjs/types/HCMealData.js +65 -0
- package/lib/commonjs/types/HCMealData.js.map +1 -0
- package/lib/commonjs/types/HeartRateEvent.js +2 -0
- package/lib/commonjs/types/HeartRateEvent.js.map +1 -0
- package/lib/commonjs/types/PermissionsType.js +2 -0
- package/lib/commonjs/types/PermissionsType.js.map +1 -0
- package/lib/commonjs/types/PhysicalSummary.js +6 -0
- package/lib/commonjs/types/PhysicalSummary.js.map +1 -0
- package/lib/commonjs/types/SDKSources.js +13 -0
- package/lib/commonjs/types/SDKSources.js.map +1 -0
- package/lib/commonjs/types/SamsungHealthPermissions.js +23 -0
- package/lib/commonjs/types/SamsungHealthPermissions.js.map +1 -0
- package/lib/commonjs/types/SleepSummary.js +6 -0
- package/lib/commonjs/types/SleepSummary.js.map +1 -0
- package/lib/commonjs/types/SummaryTypes.js +2 -0
- package/lib/commonjs/types/SummaryTypes.js.map +1 -0
- package/lib/commonjs/types/SyncTypes.js +33 -0
- package/lib/commonjs/types/SyncTypes.js.map +1 -0
- package/lib/commonjs/types/WriteNutrition.js +18 -0
- package/lib/commonjs/types/WriteNutrition.js.map +1 -0
- package/lib/commonjs/utils/getNativeModule.js +29 -0
- package/lib/commonjs/utils/getNativeModule.js.map +1 -0
- package/lib/commonjs/utils/getRookModule.js +28 -0
- package/lib/commonjs/utils/getRookModule.js.map +1 -0
- package/{src/utils/isModuleReady.ts → lib/commonjs/utils/isModuleReady.js} +10 -4
- package/lib/commonjs/utils/isModuleReady.js.map +1 -0
- package/lib/commonjs/utils/isRunningOnAndroid.js +15 -0
- package/lib/commonjs/utils/isRunningOnAndroid.js.map +1 -0
- package/lib/commonjs/utils/isRunningOniOS.js +15 -0
- package/lib/commonjs/utils/isRunningOniOS.js.map +1 -0
- package/lib/commonjs/utils/isValidDate.js +41 -0
- package/lib/commonjs/utils/isValidDate.js.map +1 -0
- package/lib/commonjs/utils/nativeModules.js +29 -0
- package/lib/commonjs/utils/nativeModules.js.map +1 -0
- package/lib/commonjs/utils/packageInfo.js +13 -0
- package/lib/commonjs/utils/packageInfo.js.map +1 -0
- package/lib/module/context/RookSyncGateContext.js +0 -2
- package/lib/module/context/RookSyncGateContext.js.map +1 -1
- package/lib/module/context/RookSyncGateProvider.js +31 -22
- package/lib/module/context/RookSyncGateProvider.js.map +1 -1
- package/lib/module/context/RookSyncGateReducer.js +12 -4
- package/lib/module/context/RookSyncGateReducer.js.map +1 -1
- package/lib/module/context/RookSyncGateTypes.js +0 -2
- package/lib/module/context/index.js +2 -0
- package/lib/module/context/index.js.map +1 -0
- package/lib/module/hooks/index.js +12 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useRookAPISources.js +16 -10
- package/lib/module/hooks/useRookAPISources.js.map +1 -1
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js +12 -11
- package/lib/module/hooks/useRookAndroidBackgroundSteps.js.map +1 -1
- package/lib/module/hooks/useRookAndroidStepCounter.js +48 -0
- package/lib/module/hooks/useRookAndroidStepCounter.js.map +1 -0
- package/lib/module/hooks/useRookAppleHealth.js +10 -9
- package/lib/module/hooks/useRookAppleHealth.js.map +1 -1
- package/lib/module/hooks/useRookConfiguration.js +34 -10
- package/lib/module/hooks/useRookConfiguration.js.map +1 -1
- package/lib/module/hooks/useRookData.js +45 -31
- package/lib/module/hooks/useRookData.js.map +1 -1
- package/lib/module/hooks/useRookHealthConnect.js +10 -9
- package/lib/module/hooks/useRookHealthConnect.js.map +1 -1
- package/lib/module/hooks/useRookPermissions.js +63 -28
- package/lib/module/hooks/useRookPermissions.js.map +1 -1
- package/lib/module/hooks/useRookSamsungHealth.js +20 -8
- package/lib/module/hooks/useRookSamsungHealth.js.map +1 -1
- package/lib/module/hooks/useRookSync.js +32 -23
- package/lib/module/hooks/useRookSync.js.map +1 -1
- package/lib/module/hooks/useRookVariables.js +37 -19
- package/lib/module/hooks/useRookVariables.js.map +1 -1
- package/lib/module/index.js +10 -18
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/hook/useRookAutoSync.js +40 -27
- 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 +0 -2
- package/lib/module/modules/utils/errors.js.map +1 -1
- package/lib/module/types/ActivityEvent.js +0 -2
- package/lib/module/types/AppleHealthNutritionEvent.js +70 -0
- package/lib/module/types/AppleHealthNutritionEvent.js.map +1 -0
- package/lib/module/types/AppleHealthPermissions.js +0 -2
- package/lib/module/types/AppleHealthPermissions.js.map +1 -1
- package/lib/module/types/AuthorizedSources.js +0 -2
- package/lib/module/types/BodySummary.js +0 -2
- package/lib/module/types/DataSource.js +0 -2
- package/lib/module/types/DataSource.js.map +1 -1
- package/lib/module/types/DiagnosticState.js +2 -0
- package/lib/module/types/DiagnosticState.js.map +1 -0
- package/lib/module/types/HCMealData.js +59 -0
- package/lib/module/types/HCMealData.js.map +1 -0
- package/lib/module/types/HeartRateEvent.js +1 -1
- package/lib/module/types/PermissionsType.js +1 -1
- package/lib/module/types/PhysicalSummary.js +0 -2
- package/lib/module/types/SDKSources.js +0 -2
- package/lib/module/types/SDKSources.js.map +1 -1
- package/lib/module/types/SamsungHealthPermissions.js +0 -3
- package/lib/module/types/SamsungHealthPermissions.js.map +1 -1
- package/lib/module/types/SleepSummary.js +0 -2
- package/lib/module/types/SummaryTypes.js +1 -1
- package/lib/module/types/SyncTypes.js +0 -2
- package/lib/module/types/SyncTypes.js.map +1 -1
- package/lib/module/types/WriteNutrition.js +12 -0
- package/lib/module/types/WriteNutrition.js.map +1 -0
- package/lib/module/utils/getNativeModule.js +23 -0
- package/lib/module/utils/getNativeModule.js.map +1 -0
- package/lib/module/utils/getRookModule.js +22 -0
- package/lib/module/utils/getRookModule.js.map +1 -0
- package/lib/module/utils/isModuleReady.js +0 -2
- package/lib/module/utils/isModuleReady.js.map +1 -1
- package/lib/module/utils/isRunningOnAndroid.js +0 -2
- package/lib/module/utils/isRunningOnAndroid.js.map +1 -1
- package/lib/module/utils/isRunningOniOS.js +0 -2
- package/lib/module/utils/isRunningOniOS.js.map +1 -1
- package/lib/module/utils/isValidDate.js +20 -2
- package/lib/module/utils/isValidDate.js.map +1 -1
- package/lib/module/utils/nativeModules.js +23 -0
- package/lib/module/utils/nativeModules.js.map +1 -0
- package/lib/module/utils/packageInfo.js +7 -0
- package/lib/module/utils/packageInfo.js.map +1 -0
- package/lib/typescript/src/context/RookSyncGateContext.d.ts.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/context/RookSyncGateTypes.d.ts +14 -4
- package/lib/typescript/src/context/RookSyncGateTypes.d.ts.map +1 -1
- package/lib/typescript/src/context/index.d.ts +2 -0
- package/lib/typescript/src/context/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +12 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- 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/useRookAndroidStepCounter.d.ts +9 -0
- package/lib/typescript/src/hooks/useRookAndroidStepCounter.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRookAppleHealth.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts +3 -1
- package/lib/typescript/src/hooks/useRookConfiguration.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookData.d.ts +2 -2
- 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 +6 -2
- package/lib/typescript/src/hooks/useRookPermissions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useRookSamsungHealth.d.ts +6 -0
- 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 +2 -0
- package/lib/typescript/src/hooks/useRookVariables.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -17
- 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/AppleHealthNutritionEvent.d.ts +76 -0
- package/lib/typescript/src/types/AppleHealthNutritionEvent.d.ts.map +1 -0
- package/lib/typescript/src/types/AuthorizedSources.d.ts +0 -11
- package/lib/typescript/src/types/AuthorizedSources.d.ts.map +1 -1
- package/lib/typescript/src/types/DiagnosticState.d.ts +13 -0
- package/lib/typescript/src/types/DiagnosticState.d.ts.map +1 -0
- package/lib/typescript/src/types/HCMealData.d.ts +60 -0
- package/lib/typescript/src/types/HCMealData.d.ts.map +1 -0
- 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/SamsungHealthPermissions.d.ts +0 -1
- package/lib/typescript/src/types/SamsungHealthPermissions.d.ts.map +1 -1
- package/lib/typescript/src/types/SyncTypes.d.ts +1 -5
- package/lib/typescript/src/types/SyncTypes.d.ts.map +1 -1
- package/lib/typescript/src/types/WriteNutrition.d.ts +61 -0
- package/lib/typescript/src/types/WriteNutrition.d.ts.map +1 -0
- package/lib/typescript/src/utils/getNativeModule.d.ts +10 -0
- package/lib/typescript/src/utils/getNativeModule.d.ts.map +1 -0
- package/lib/typescript/src/utils/getRookModule.d.ts +9 -0
- package/lib/typescript/src/utils/getRookModule.d.ts.map +1 -0
- package/lib/typescript/src/utils/isModuleReady.d.ts.map +1 -1
- package/lib/typescript/src/utils/isValidDate.d.ts +8 -0
- package/lib/typescript/src/utils/isValidDate.d.ts.map +1 -1
- package/lib/typescript/src/utils/nativeModules.d.ts +24 -0
- package/lib/typescript/src/utils/nativeModules.d.ts.map +1 -0
- package/lib/typescript/src/utils/packageInfo.d.ts +6 -0
- package/lib/typescript/src/utils/packageInfo.d.ts.map +1 -0
- package/package.json +98 -94
- package/react-native-rook-sdk.podspec +45 -0
- package/RNRookSdk.podspec +0 -22
- package/ios/Encodable.swift +0 -25
- package/ios/RookEntry.swift +0 -61
- package/ios/RookSdk-Bridging-Header.h +0 -12
- package/ios/boost-boost_privacy-Bridging-Header.h +0 -4
- package/lib/module/NativeRookSdk.js +0 -13
- package/lib/module/NativeRookSdk.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/module/types/Rook.js +0 -2
- package/lib/typescript/package.json +0 -1
- package/lib/typescript/src/NativeRookSdk.d.ts +0 -116
- package/lib/typescript/src/NativeRookSdk.d.ts.map +0 -1
- package/lib/typescript/src/types/Rook.d.ts +0 -9
- package/lib/typescript/src/types/Rook.d.ts.map +0 -1
- package/src/NativeRookSdk.ts +0 -274
- package/src/context/RookSyncGateProvider.tsx +0 -78
- package/src/context/RookSyncGateTypes.ts +0 -34
- package/src/hooks/useRookAndroidBackgroundSteps.ts +0 -81
- package/src/hooks/useRookAppleHealth.ts +0 -55
- package/src/hooks/useRookConfiguration.ts +0 -82
- package/src/hooks/useRookData.ts +0 -122
- package/src/hooks/useRookHealthConnect.ts +0 -59
- package/src/hooks/useRookPermissions.ts +0 -224
- package/src/hooks/useRookSamsungHealth.ts +0 -37
- package/src/hooks/useRookSync.ts +0 -157
- package/src/hooks/useRookVariables.ts +0 -77
- package/src/index.tsx +0 -28
- package/src/modules/hook/useRookAutoSync.ts +0 -305
- package/src/modules/types/sendMessageBroadcast.ts +0 -5
- package/src/modules/utils/errors.ts +0 -9
- package/src/types/ActivityEvent.ts +0 -159
- package/src/types/AppleHealthPermissions.ts +0 -49
- package/src/types/AuthorizedSources.ts +0 -33
- package/src/types/BodySummary.ts +0 -116
- package/src/types/DataSource.ts +0 -16
- package/src/types/HeartRateEvent.ts +0 -26
- package/src/types/PermissionsType.ts +0 -9
- package/src/types/PhysicalSummary.ts +0 -84
- package/src/types/Rook.ts +0 -8
- package/src/types/SDKSources.ts +0 -5
- package/src/types/SamsungHealthPermissions.ts +0 -16
- package/src/types/SleepSummary.ts +0 -66
- package/src/types/SummaryTypes.ts +0 -70
- package/src/types/SyncTypes.ts +0 -63
- package/src/utils/isRunningOnAndroid.ts +0 -10
- package/src/utils/isRunningOniOS.ts +0 -10
- package/src/utils/isValidDate.ts +0 -15
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
package com.rooksdk.utils
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReadableMap
|
|
6
|
+
import com.facebook.react.bridge.ReadableType
|
|
7
|
+
import com.facebook.react.bridge.WritableMap
|
|
8
|
+
import com.rookmotion.rook.sdk.domain.enums.HCNutritionInsertionEventType
|
|
9
|
+
import com.rookmotion.rook.sdk.domain.model.HCNutritionInsertionEvent
|
|
10
|
+
import java.time.ZonedDateTime
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* ReadableToWritable is a utility object that provides methods to convert between
|
|
14
|
+
* React Native's ReadableMap and WritableMap, and Kotlin's HashMap.
|
|
15
|
+
* This is useful when you need to transform data between JavaScript and native code.
|
|
16
|
+
*/
|
|
17
|
+
object ReadableToWritable {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Converts a ReadableMap (from JavaScript/React Native) to a HashMap (native Kotlin data structure).
|
|
21
|
+
* It iterates through all the keys in the ReadableMap and converts its values based on their type.
|
|
22
|
+
*
|
|
23
|
+
* @param readableMap The ReadableMap to convert.
|
|
24
|
+
* @return A HashMap<String, Any> with equivalent values.
|
|
25
|
+
*/
|
|
26
|
+
fun readableMapToHashMap(readableMap: ReadableMap): HashMap<String, Any> {
|
|
27
|
+
val map = HashMap<String, Any>()
|
|
28
|
+
val iterator = readableMap.keySetIterator()
|
|
29
|
+
|
|
30
|
+
while (iterator.hasNextKey()) {
|
|
31
|
+
val key = iterator.nextKey()
|
|
32
|
+
when (readableMap.getType(key)) {
|
|
33
|
+
ReadableType.Boolean -> map[key] = readableMap.getBoolean(key)
|
|
34
|
+
ReadableType.Number -> map[key] = readableMap.getDouble(key)
|
|
35
|
+
ReadableType.String -> map[key] = readableMap.getString(key) ?: ""
|
|
36
|
+
ReadableType.Map -> map[key] = readableMapToHashMap(readableMap.getMap(key)!!)
|
|
37
|
+
ReadableType.Array -> map[key] = readableMap.getArray(key)!!.toArrayList()
|
|
38
|
+
else -> {} // Manejar otros tipos si es necesario
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return map
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Converts a HashMap (native Kotlin data structure) to a WritableMap (to be sent to JavaScript/React Native).
|
|
47
|
+
* It iterates through all the entries in the HashMap and converts its values based on their type.
|
|
48
|
+
*
|
|
49
|
+
* @param hashMap The HashMap<String, Any> to convert.
|
|
50
|
+
* @return A WritableMap with equivalent values.
|
|
51
|
+
*/
|
|
52
|
+
fun hashMapToWritableMap(hashMap: HashMap<String, Any>): WritableMap {
|
|
53
|
+
val writableMap = Arguments.createMap()
|
|
54
|
+
|
|
55
|
+
for ((key, value) in hashMap) {
|
|
56
|
+
when (value) {
|
|
57
|
+
is Boolean -> writableMap.putBoolean(key, value)
|
|
58
|
+
is Double -> writableMap.putDouble(key, value)
|
|
59
|
+
is String -> writableMap.putString(key, value)
|
|
60
|
+
is HashMap<*, *> -> writableMap.putMap(key, hashMapToWritableMap(value as HashMap<String, Any>))
|
|
61
|
+
is ArrayList<*> -> writableMap.putArray(key, Arguments.fromArray(value))
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return writableMap
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fun mapReadableMapToHCMealData(map: ReadableMap): HCNutritionInsertionEvent {
|
|
69
|
+
// Helper for micro-nutrients: range [0.0, 100.0]
|
|
70
|
+
fun getGramValue(key: String): Double? {
|
|
71
|
+
return if (map.hasKey(key) && !map.isNull(key)) {
|
|
72
|
+
map.getDouble(key).takeIf { it in 0.0..100.0 }
|
|
73
|
+
} else null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Helper for energy and macronutrients: range [0.0, 100,000.0]
|
|
77
|
+
fun getLargeValue(key: String): Double? {
|
|
78
|
+
return if (map.hasKey(key) && !map.isNull(key)) {
|
|
79
|
+
map.getDouble(key).takeIf { it in 0.0..100000.0 }
|
|
80
|
+
} else null
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
val typeString = if (map.hasKey("type")) map.getString("type") else null
|
|
84
|
+
val mealType = when (typeString?.uppercase()) {
|
|
85
|
+
"BREAKFAST" -> HCNutritionInsertionEventType.BREAKFAST
|
|
86
|
+
"LUNCH" -> HCNutritionInsertionEventType.LUNCH
|
|
87
|
+
"DINNER" -> HCNutritionInsertionEventType.DINNER
|
|
88
|
+
"SNACK" -> HCNutritionInsertionEventType.SNACK
|
|
89
|
+
else -> HCNutritionInsertionEventType.SNACK // Default fallback
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return HCNutritionInsertionEvent(
|
|
93
|
+
startDateTime = ZonedDateTime.parse(map.getString("startDateTime")),
|
|
94
|
+
endDateTime = ZonedDateTime.parse(map.getString("endDateTime")),
|
|
95
|
+
name = map.getString("name") ?: "Meal",
|
|
96
|
+
type = mealType,
|
|
97
|
+
|
|
98
|
+
// Energy & Macros (0 to 100,000 range)
|
|
99
|
+
energyKcal = getLargeValue("energyKcal"),
|
|
100
|
+
energyFromFatKcal = getLargeValue("energyFromFatKcal"),
|
|
101
|
+
dietaryFiberGrams = getLargeValue("dietaryFiberGrams"),
|
|
102
|
+
monounsaturatedFatGrams = getLargeValue("monounsaturatedFatGrams"),
|
|
103
|
+
polyunsaturatedFatGrams = getLargeValue("polyunsaturatedFatGrams"),
|
|
104
|
+
proteinGrams = getLargeValue("proteinGrams"),
|
|
105
|
+
saturatedFatGrams = getLargeValue("saturatedFatGrams"),
|
|
106
|
+
sugarGrams = getLargeValue("sugarGrams"),
|
|
107
|
+
totalCarbohydrateGrams = getLargeValue("totalCarbohydrateGrams"),
|
|
108
|
+
totalFatGrams = getLargeValue("totalFatGrams"),
|
|
109
|
+
transFatGrams = getLargeValue("transFatGrams"),
|
|
110
|
+
unsaturatedFatGrams = getLargeValue("unsaturatedFatGrams"),
|
|
111
|
+
|
|
112
|
+
// Micro-nutrients & Minerals (0 to 100 range)
|
|
113
|
+
biotinGrams = getGramValue("biotinGrams"),
|
|
114
|
+
caffeineGrams = getGramValue("caffeineGrams"),
|
|
115
|
+
calciumGrams = getGramValue("calciumGrams"),
|
|
116
|
+
chlorideGrams = getGramValue("chlorideGrams"),
|
|
117
|
+
cholesterolGrams = getGramValue("cholesterolGrams"),
|
|
118
|
+
chromiumGrams = getGramValue("chromiumGrams"),
|
|
119
|
+
copperGrams = getGramValue("copperGrams"),
|
|
120
|
+
folateGrams = getGramValue("folateGrams"),
|
|
121
|
+
folicAcidGrams = getGramValue("folicAcidGrams"),
|
|
122
|
+
iodineGrams = getGramValue("iodineGrams"),
|
|
123
|
+
ironGrams = getGramValue("ironGrams"),
|
|
124
|
+
magnesiumGrams = getGramValue("magnesiumGrams"),
|
|
125
|
+
manganeseGrams = getGramValue("manganeseGrams"),
|
|
126
|
+
molybdenumGrams = getGramValue("molybdenumGrams"),
|
|
127
|
+
niacinGrams = getGramValue("niacinGrams"),
|
|
128
|
+
pantothenicAcidGrams = getGramValue("pantothenicAcidGrams"),
|
|
129
|
+
phosphorusGrams = getGramValue("phosphorusGrams"),
|
|
130
|
+
potassiumGrams = getGramValue("potassiumGrams"),
|
|
131
|
+
riboflavinGrams = getGramValue("riboflavinGrams"),
|
|
132
|
+
seleniumGrams = getGramValue("seleniumGrams"),
|
|
133
|
+
sodiumGrams = getGramValue("sodiumGrams"),
|
|
134
|
+
thiaminGrams = getGramValue("thiaminGrams"),
|
|
135
|
+
vitaminAGrams = getGramValue("vitaminAGrams"),
|
|
136
|
+
vitaminB12Grams = getGramValue("vitaminB12Grams"),
|
|
137
|
+
vitaminB6Grams = getGramValue("vitaminB6Grams"),
|
|
138
|
+
vitaminCGrams = getGramValue("vitaminCGrams"),
|
|
139
|
+
vitaminDGrams = getGramValue("vitaminDGrams"),
|
|
140
|
+
vitaminEGrams = getGramValue("vitaminEGrams"),
|
|
141
|
+
vitaminKGrams = getGramValue("vitaminKGrams"),
|
|
142
|
+
zincGrams = getGramValue("zincGrams")
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package com.rooksdk.utils
|
|
2
|
+
|
|
3
|
+
import java.time.LocalDate
|
|
4
|
+
import java.time.ZonedDateTime
|
|
5
|
+
import java.time.format.DateTimeFormatter
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* RookDateTime is a utility object for handling date-related operations.
|
|
9
|
+
* It provides methods to format and parse dates using the ISO_LOCAL_DATE format.
|
|
10
|
+
*/
|
|
11
|
+
object RookDateTime {
|
|
12
|
+
private val rookDateFormatter: DateTimeFormatter get() = DateTimeFormatter.ISO_LOCAL_DATE
|
|
13
|
+
private val rookZonedDateTimeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A DateTimeFormatter using the ISO_LOCAL_DATE pattern (e.g., "YYYY-MM-DD").
|
|
17
|
+
* It formats or parses dates in the standard ISO 8601 format.
|
|
18
|
+
*/
|
|
19
|
+
fun stringToLocalDate(string: String): LocalDate {
|
|
20
|
+
return LocalDate.parse(string, rookDateFormatter)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fun stringToZonedDateTime(string: String): ZonedDateTime {
|
|
24
|
+
return ZonedDateTime.parse(string, rookZonedDateTimeFormatter)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.rooksdk.utils
|
|
2
|
+
|
|
3
|
+
import com.google.gson.Gson
|
|
4
|
+
import com.google.gson.GsonBuilder
|
|
5
|
+
import com.rooksdk.utils.serializers.InstantSerializer
|
|
6
|
+
import com.rooksdk.utils.serializers.LocalDateSerializer
|
|
7
|
+
import java.time.Instant
|
|
8
|
+
import java.time.LocalDate
|
|
9
|
+
|
|
10
|
+
object RookGsonBuilder {
|
|
11
|
+
fun getGsonBuilder(): Gson {
|
|
12
|
+
return GsonBuilder()
|
|
13
|
+
.registerTypeAdapter(Instant::class.java, InstantSerializer())
|
|
14
|
+
.registerTypeAdapter(LocalDate::class.java, LocalDateSerializer())
|
|
15
|
+
.create()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package com.rooksdk.utils
|
|
2
|
+
|
|
3
|
+
import com.rookmotion.rook.sdk.domain.model.SyncType
|
|
4
|
+
import io.tryrook.sdk.samsung.domain.model.SHSyncType
|
|
5
|
+
|
|
6
|
+
object StringToSyncType {
|
|
7
|
+
|
|
8
|
+
fun stringToSummary(type: String): SyncType.Summary {
|
|
9
|
+
return when(type.lowercase()) {
|
|
10
|
+
"sleep" -> SyncType.Summary.SLEEP
|
|
11
|
+
"body" -> SyncType.Summary.BODY
|
|
12
|
+
"physical" -> SyncType.Summary.PHYSICAL
|
|
13
|
+
else -> SyncType.Summary.BODY
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fun stringToEvent(value: String): SyncType.Event {
|
|
18
|
+
return try {
|
|
19
|
+
SyncType.Event.valueOf(value)
|
|
20
|
+
} catch (e: IllegalArgumentException) {
|
|
21
|
+
SyncType.Event.STEPS
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fun stringToSamsungPillar(value: String): SHSyncType.Summary {
|
|
26
|
+
return when(value.lowercase()) {
|
|
27
|
+
"sleep" -> SHSyncType.Summary.SLEEP
|
|
28
|
+
"body" -> SHSyncType.Summary.BODY
|
|
29
|
+
"physical" -> SHSyncType.Summary.PHYSICAL
|
|
30
|
+
else -> SHSyncType.Summary.BODY
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fun stringToSamsungEvent(value: String): SHSyncType.Event {
|
|
35
|
+
return try {
|
|
36
|
+
SHSyncType.Event.valueOf(value)
|
|
37
|
+
} catch (e: IllegalArgumentException) {
|
|
38
|
+
SHSyncType.Event.STEPS
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.rooksdk.utils.serializers
|
|
2
|
+
|
|
3
|
+
import com.google.gson.JsonElement
|
|
4
|
+
import com.google.gson.JsonPrimitive
|
|
5
|
+
import com.google.gson.JsonSerializationContext
|
|
6
|
+
import com.google.gson.JsonSerializer
|
|
7
|
+
import java.time.Instant
|
|
8
|
+
import java.lang.reflect.Type
|
|
9
|
+
|
|
10
|
+
class InstantSerializer : JsonSerializer<Instant> {
|
|
11
|
+
override fun serialize(
|
|
12
|
+
src: Instant?,
|
|
13
|
+
typeOfSrc: Type?,
|
|
14
|
+
context: JsonSerializationContext?
|
|
15
|
+
): JsonElement {
|
|
16
|
+
return JsonPrimitive(src?.toString())
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package com.rooksdk.utils.serializers
|
|
2
|
+
|
|
3
|
+
import com.google.gson.JsonElement
|
|
4
|
+
import com.google.gson.JsonPrimitive
|
|
5
|
+
import com.google.gson.JsonSerializationContext
|
|
6
|
+
import com.google.gson.JsonSerializer
|
|
7
|
+
import java.lang.reflect.Type
|
|
8
|
+
import java.time.LocalDate
|
|
9
|
+
import java.time.format.DateTimeFormatter
|
|
10
|
+
|
|
11
|
+
class LocalDateSerializer : JsonSerializer<LocalDate> {
|
|
12
|
+
private val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
13
|
+
|
|
14
|
+
override fun serialize(
|
|
15
|
+
src: LocalDate?,
|
|
16
|
+
typeOfSrc: Type?,
|
|
17
|
+
context: JsonSerializationContext?
|
|
18
|
+
): JsonElement {
|
|
19
|
+
return JsonPrimitive(src?.format(formatter))
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:width="200dp"
|
|
4
|
+
android:height="200dp"
|
|
5
|
+
android:viewportWidth="512"
|
|
6
|
+
android:viewportHeight="512">
|
|
7
|
+
<path
|
|
8
|
+
android:fillColor="#4285F4"
|
|
9
|
+
android:pathData="M258.3,431.3c-35.1,0 -68.1,-13.3 -92.9,-37.6l44.2,-45.4c26.9,26.2 70.6,26.2 97.6,0l94.4,-92c12.7,-12.4 19.8,-28.9 19.8,-46.3s-7,-33.9 -19.8,-46.3c-26.9,-26.2 -70.6,-26.2 -97.6,0l-17.1,16.7L242.6,135l17.1,-16.7c25,-24.3 58,-37.6 93,-37.6c35.1,0 68.1,13.3 92.9,37.6c25.1,24.4 38.9,57 38.9,91.7s-13.8,67.2 -38.9,91.7l-94.4,92.1C326.4,417.9 293.4,431.3 258.3,431.3z" />
|
|
10
|
+
<path
|
|
11
|
+
android:fillColor="#3DDB85"
|
|
12
|
+
android:pathData="M165.6,393.7L66.5,302l-0.3,-0.3c-25.1,-24.4 -38.9,-57 -38.9,-91.7s13.8,-67.2 38.9,-91.7c24.9,-24.2 57.9,-37.6 92.9,-37.6c35.1,0 68.1,13.3 93,37.5l25.2,24.6l-44.2,45.4L208,163.7c-26.9,-26.2 -70.7,-26.2 -97.6,0c-12.7,12.4 -19.8,28.9 -19.8,46.3c0,17.3 6.9,33.7 19.5,46.1l98.5,91.2L165.6,393.7z" />
|
|
13
|
+
<path
|
|
14
|
+
android:fillColor="#4285F4"
|
|
15
|
+
android:pathData="M165.3,393.7c-24.9,-24.2 -38.6,-56.5 -38.8,-90.9c-0.1,-35.1 13.9,-68.4 39.5,-93.7l0.2,-0.2l91.4,-88.5l44.1,45.5l-91.2,88.4c-13.4,13.3 -20.7,30.4 -20.6,48.3c0.1,17.3 7,33.5 19.6,45.8L165.3,393.7z" />
|
|
16
|
+
<path
|
|
17
|
+
android:fillColor="#3DDB85"
|
|
18
|
+
android:pathData="M302.5,211.3a50.7,50.7 0,1 0,101.4 0a50.7,50.7 0,1 0,-101.4 0z" />
|
|
19
|
+
</vector>
|
package/ios/DateHelper.swift
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// DateHelper.swift
|
|
3
|
+
// react-native-rook-sdk
|
|
4
4
|
//
|
|
5
|
-
// Created by Javier Villanueva on
|
|
5
|
+
// Created by Javier Villanueva on 08/12/25.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
import Foundation
|
|
@@ -16,7 +16,7 @@ struct DateHelper: DateHelperProtocol {
|
|
|
16
16
|
|
|
17
17
|
private static let dateISOFormatterDateLocal: DateFormatter = {
|
|
18
18
|
let dateFormatter = DateFormatter()
|
|
19
|
-
dateFormatter.locale = Locale(identifier:
|
|
19
|
+
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
|
|
20
20
|
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
|
|
21
21
|
return dateFormatter
|
|
22
22
|
}()
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
//
|
|
2
2
|
// EncodableDataSource.swift
|
|
3
|
-
//
|
|
3
|
+
// react-native-rook-sdk
|
|
4
4
|
//
|
|
5
|
-
// Created by Javier Villanueva on
|
|
5
|
+
// Created by Javier Villanueva on 09/10/25.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
+
import Foundation
|
|
8
9
|
import RookSDK
|
|
9
10
|
|
|
10
11
|
struct EncodableDataSource: Encodable {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// EncodableRookDataSource.swift
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Javier Villanueva on 08/10/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import RookSDK
|
|
10
|
+
|
|
11
|
+
struct EncodableRookDataSource: Encodable {
|
|
12
|
+
|
|
13
|
+
private let dataSource: RookSDK.RookDataSource
|
|
14
|
+
|
|
15
|
+
init(_ dataSource: RookSDK.RookDataSource) {
|
|
16
|
+
self.dataSource = dataSource
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private enum CodingKeys: String, CodingKey {
|
|
20
|
+
case name
|
|
21
|
+
case description
|
|
22
|
+
case imageUrl
|
|
23
|
+
case connected
|
|
24
|
+
case authorizationURL
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func encode(to encoder: Encoder) throws {
|
|
28
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
29
|
+
|
|
30
|
+
try container.encode(dataSource.name, forKey: .name)
|
|
31
|
+
try container.encode(dataSource.description, forKey: .description)
|
|
32
|
+
try container.encode(dataSource.imageUrl, forKey: .imageUrl)
|
|
33
|
+
try container.encode(dataSource.connected, forKey: .connected)
|
|
34
|
+
try container.encode(dataSource.authorizationURL, forKey: .authorizationURL)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// EncodableSDKState.swift
|
|
3
|
+
// react-native-rook-sdk
|
|
4
|
+
//
|
|
5
|
+
// Created by Javier Villanueva on 10/03/26.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import RookSDK
|
|
9
|
+
|
|
10
|
+
private struct DateTransformer {
|
|
11
|
+
static let localFormatter: DateFormatter = {
|
|
12
|
+
let formatter = DateFormatter()
|
|
13
|
+
// Use a standard ISO-like format or customize as needed
|
|
14
|
+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
|
|
15
|
+
formatter.timeZone = .current // Explicitly set to the device's local timezone
|
|
16
|
+
return formatter
|
|
17
|
+
}()
|
|
18
|
+
|
|
19
|
+
static func string(from date: Date?) -> String? {
|
|
20
|
+
guard let date = date else { return nil }
|
|
21
|
+
return localFormatter.string(from: date)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public struct EncodableSDKState: Encodable {
|
|
26
|
+
|
|
27
|
+
private let state: RookSDK.SDKState
|
|
28
|
+
|
|
29
|
+
public init(_ state: RookSDK.SDKState) {
|
|
30
|
+
self.state = state
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private enum CodingKeys: String, CodingKey {
|
|
34
|
+
case isConfigured
|
|
35
|
+
case userIdentified
|
|
36
|
+
case permissions
|
|
37
|
+
case backgroundSync
|
|
38
|
+
case manualSync
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public func encode(to encoder: Encoder) throws {
|
|
42
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
43
|
+
|
|
44
|
+
try container.encode(state.isConfigured, forKey: .isConfigured)
|
|
45
|
+
try container.encode(state.userIdentified, forKey: .userIdentified)
|
|
46
|
+
try container.encode(state.permissions, forKey: .permissions)
|
|
47
|
+
|
|
48
|
+
// Wrap nested structs to ensure they use their own encoding logic
|
|
49
|
+
try container.encode(EncodableSDKBackgroundState(state.backgroundSync), forKey: .backgroundSync)
|
|
50
|
+
try container.encode(EncodableSDKManualSyncState(state.manualSync), forKey: .manualSync)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// MARK: - Nested Wrappers
|
|
55
|
+
|
|
56
|
+
struct EncodableSDKBackgroundState: Encodable {
|
|
57
|
+
private let backgroundState: RookSDK.SDKBackgroundState
|
|
58
|
+
private let formatter = ISO8601DateFormatter()
|
|
59
|
+
|
|
60
|
+
init(_ backgroundState: RookSDK.SDKBackgroundState) {
|
|
61
|
+
self.backgroundState = backgroundState
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private enum CodingKeys: String, CodingKey {
|
|
65
|
+
case enabled, lastSync
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func encode(to encoder: Encoder) throws {
|
|
69
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
70
|
+
try container.encode(backgroundState.enabled, forKey: .enabled)
|
|
71
|
+
|
|
72
|
+
try container.encode(DateTransformer.string(from: backgroundState.lastSync), forKey: .lastSync)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
struct EncodableSDKManualSyncState: Encodable {
|
|
77
|
+
private let manualState: RookSDK.SDKManualSyncState
|
|
78
|
+
private let formatter = ISO8601DateFormatter()
|
|
79
|
+
|
|
80
|
+
init(_ manualState: RookSDK.SDKManualSyncState) {
|
|
81
|
+
self.manualState = manualState
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private enum CodingKeys: String, CodingKey {
|
|
85
|
+
case enabled, lastSync
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
func encode(to encoder: Encoder) throws {
|
|
89
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
90
|
+
try container.encode(manualState.enabled, forKey: .enabled)
|
|
91
|
+
|
|
92
|
+
try container.encode(DateTransformer.string(from: manualState.lastSync), forKey: .lastSync)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// EncodableStatusDataSources.swift
|
|
3
|
+
// react-native-rook-sdk
|
|
4
|
+
//
|
|
5
|
+
// Created by Javier Villanueva on 08/10/25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import RookSDK
|
|
10
|
+
|
|
11
|
+
struct EncodableStatusDataSources: Encodable {
|
|
12
|
+
private let status: RookSDK.StatusDataSources
|
|
13
|
+
|
|
14
|
+
init(_ status: RookSDK.StatusDataSources) {
|
|
15
|
+
self.status = status
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private enum CodingKeys: String, CodingKey {
|
|
19
|
+
case oura
|
|
20
|
+
case polar
|
|
21
|
+
case whoop
|
|
22
|
+
case fitbit
|
|
23
|
+
case garmin
|
|
24
|
+
case withings
|
|
25
|
+
case googleFit
|
|
26
|
+
case appleHealth
|
|
27
|
+
case healthConnect
|
|
28
|
+
case android
|
|
29
|
+
case dexcom
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func encode(to encoder: Encoder) throws {
|
|
33
|
+
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
34
|
+
|
|
35
|
+
try container.encode(status.oura, forKey: .oura)
|
|
36
|
+
try container.encode(status.polar, forKey: .polar)
|
|
37
|
+
try container.encode(status.whoop, forKey: .whoop)
|
|
38
|
+
try container.encode(status.fitbit, forKey: .fitbit)
|
|
39
|
+
try container.encode(status.garmin, forKey: .garmin)
|
|
40
|
+
try container.encode(status.withings, forKey: .withings)
|
|
41
|
+
try container.encode(status.googleFit, forKey: .googleFit)
|
|
42
|
+
try container.encode(status.appleHealth, forKey: .appleHealth)
|
|
43
|
+
try container.encode(status.healthConnect, forKey: .healthConnect)
|
|
44
|
+
try container.encode(status.android, forKey: .android)
|
|
45
|
+
try container.encode(status.dexcom, forKey: .dexcom)
|
|
46
|
+
}
|
|
47
|
+
}
|