react-native-spike-sdk 4.3.43 → 4.3.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +454 -456
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/v3/DataModels/MetricType.js +3 -3
- package/lib/commonjs/v3/DataModels/Provider.js +1 -0
- package/lib/commonjs/v3/DataModels/Provider.js.map +1 -1
- package/lib/commonjs/v3/DataModels/ProviderSource.js +1 -0
- package/lib/commonjs/v3/DataModels/ProviderSource.js.map +1 -1
- package/lib/commonjs/v3/DataModels/SamsungHealthDataAvailability.js +6 -0
- package/lib/commonjs/v3/DataModels/SamsungHealthDataAvailability.js.map +1 -0
- package/lib/commonjs/v3/DataModels/SamsungHealthDataAvailabilityStatus.js +37 -0
- package/lib/commonjs/v3/DataModels/SamsungHealthDataAvailabilityStatus.js.map +1 -0
- package/lib/commonjs/v3/SpikeRNConnectionAPIv3.js +111 -1
- package/lib/commonjs/v3/SpikeRNConnectionAPIv3.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/v3/DataModels/MetricType.js +3 -3
- package/lib/module/v3/DataModels/Provider.js +1 -0
- package/lib/module/v3/DataModels/Provider.js.map +1 -1
- package/lib/module/v3/DataModels/ProviderSource.js +1 -0
- package/lib/module/v3/DataModels/ProviderSource.js.map +1 -1
- package/lib/module/v3/DataModels/SamsungHealthDataAvailability.js +4 -0
- package/lib/module/v3/DataModels/SamsungHealthDataAvailability.js.map +1 -0
- package/lib/module/v3/DataModels/SamsungHealthDataAvailabilityStatus.js +33 -0
- package/lib/module/v3/DataModels/SamsungHealthDataAvailabilityStatus.js.map +1 -0
- package/lib/module/v3/SpikeRNConnectionAPIv3.js +111 -1
- package/lib/module/v3/SpikeRNConnectionAPIv3.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/v3/DataModels/BackgroundDeliveryConfig.d.ts +2 -0
- package/lib/typescript/v3/DataModels/BackgroundDeliveryConfig.d.ts.map +1 -1
- package/lib/typescript/v3/DataModels/MetricType.d.ts +3 -3
- package/lib/typescript/v3/DataModels/MetricType.d.ts.map +1 -1
- package/lib/typescript/v3/DataModels/Provider.d.ts +1 -0
- package/lib/typescript/v3/DataModels/Provider.d.ts.map +1 -1
- package/lib/typescript/v3/DataModels/ProviderSource.d.ts +1 -0
- package/lib/typescript/v3/DataModels/ProviderSource.d.ts.map +1 -1
- package/lib/typescript/v3/DataModels/SamsungHealthDataAvailability.d.ts +7 -0
- package/lib/typescript/v3/DataModels/SamsungHealthDataAvailability.d.ts.map +1 -0
- package/lib/typescript/v3/DataModels/SamsungHealthDataAvailabilityStatus.d.ts +28 -0
- package/lib/typescript/v3/DataModels/SamsungHealthDataAvailabilityStatus.d.ts.map +1 -0
- package/lib/typescript/v3/SpikeRNConnectionAPIv3.d.ts +57 -1
- package/lib/typescript/v3/SpikeRNConnectionAPIv3.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/v3/DataModels/BackgroundDeliveryConfig.ts +2 -0
- package/src/v3/DataModels/MetricType.ts +3 -3
- package/src/v3/DataModels/Provider.ts +1 -0
- package/src/v3/DataModels/ProviderSource.ts +1 -0
- package/src/v3/DataModels/SamsungHealthDataAvailability.ts +9 -0
- package/src/v3/DataModels/SamsungHealthDataAvailabilityStatus.ts +34 -0
- package/src/v3/SpikeRNConnectionAPIv3.ts +127 -1
- package/src/version.ts +1 -1
|
@@ -597,21 +597,16 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
597
597
|
customerEndUserId: String,
|
|
598
598
|
promise: Promise
|
|
599
599
|
) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
)
|
|
608
|
-
|
|
609
|
-
addConnectionV3(connection, uuid)
|
|
610
|
-
promise.resolve(uuid)
|
|
600
|
+
executeV3Method(promise) {
|
|
601
|
+
val connection = SpikeConnectionAPIv3.createConnectionLegacy(
|
|
602
|
+
appId = appId,
|
|
603
|
+
authToken = authToken,
|
|
604
|
+
customerEndUserId = customerEndUserId,
|
|
605
|
+
context = reactApplicationContext
|
|
606
|
+
)
|
|
611
607
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
608
|
+
addConnectionV3(connection, uuid)
|
|
609
|
+
promise.resolve(uuid)
|
|
615
610
|
}
|
|
616
611
|
}
|
|
617
612
|
|
|
@@ -623,21 +618,16 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
623
618
|
endUserId: String,
|
|
624
619
|
promise: Promise
|
|
625
620
|
) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
)
|
|
634
|
-
|
|
635
|
-
addConnectionV3(connection, uuid)
|
|
636
|
-
promise.resolve(uuid)
|
|
621
|
+
executeV3Method(promise) {
|
|
622
|
+
val connection = SpikeConnectionAPIv3.createConnection(
|
|
623
|
+
applicationId = applicationId,
|
|
624
|
+
signature = signature,
|
|
625
|
+
endUserId = endUserId,
|
|
626
|
+
context = reactApplicationContext
|
|
627
|
+
)
|
|
637
628
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
629
|
+
addConnectionV3(connection, uuid)
|
|
630
|
+
promise.resolve(uuid)
|
|
641
631
|
}
|
|
642
632
|
}
|
|
643
633
|
|
|
@@ -648,20 +638,9 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
648
638
|
connectionUUID: String,
|
|
649
639
|
promise: Promise
|
|
650
640
|
) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
655
|
-
"Connection not found (getUserInfo)"
|
|
656
|
-
)
|
|
657
|
-
|
|
658
|
-
val result = connection.getUserInfo()
|
|
659
|
-
|
|
660
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
661
|
-
|
|
662
|
-
} catch (e: SpikeExceptions) {
|
|
663
|
-
promise.reject(e.mapException(), e.message)
|
|
664
|
-
}
|
|
641
|
+
executeV3MethodWithConnection("getUserInfo", connectionUUID, promise) { connection ->
|
|
642
|
+
val result = connection.getUserInfo()
|
|
643
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
665
644
|
}
|
|
666
645
|
}
|
|
667
646
|
|
|
@@ -674,26 +653,15 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
674
653
|
config: String?,
|
|
675
654
|
promise: Promise
|
|
676
655
|
) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
val providerObject = Provider.values().find { it.value == provider } ?: Provider.UNKNOWN
|
|
685
|
-
val configObject = if (config != null) {
|
|
686
|
-
IntegrationInitConfigUtils.fromValue(config)
|
|
687
|
-
} else {
|
|
688
|
-
null
|
|
689
|
-
}
|
|
690
|
-
val result = connection.getIntegrationInitUrl(providerObject, configObject)
|
|
691
|
-
|
|
692
|
-
promise.resolve(result)
|
|
693
|
-
|
|
694
|
-
} catch (e: SpikeExceptions) {
|
|
695
|
-
promise.reject(e.mapException(), e.message)
|
|
656
|
+
executeV3MethodWithConnection("getIntegrationInitUrl", connectionUUID, promise) { connection ->
|
|
657
|
+
val providerObject = Provider.values().find { it.value == provider } ?: Provider.UNKNOWN
|
|
658
|
+
val configObject = if (config != null) {
|
|
659
|
+
IntegrationInitConfigUtils.fromValue(config)
|
|
660
|
+
} else {
|
|
661
|
+
null
|
|
696
662
|
}
|
|
663
|
+
val result = connection.getIntegrationInitUrl(providerObject, configObject)
|
|
664
|
+
promise.resolve(result)
|
|
697
665
|
}
|
|
698
666
|
}
|
|
699
667
|
|
|
@@ -709,33 +677,24 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
709
677
|
filter: String?, // StatisticsFilter?
|
|
710
678
|
promise: Promise
|
|
711
679
|
) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
from = dateFrom,
|
|
729
|
-
to = dateTo,
|
|
730
|
-
interval = statsInterval,
|
|
731
|
-
filter = statsFilter
|
|
732
|
-
)
|
|
733
|
-
|
|
734
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
680
|
+
executeV3MethodWithConnection("getStatistics", connectionUUID, promise) { connection ->
|
|
681
|
+
val statTypes = types.toArrayList().mapNotNull {
|
|
682
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
683
|
+
}.toSet()
|
|
684
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
685
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
686
|
+
val statsInterval = StatisticsIntervalUtils.fromValue(interval)
|
|
687
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
688
|
+
|
|
689
|
+
val result = connection.getStatistics(
|
|
690
|
+
types = statTypes,
|
|
691
|
+
from = dateFrom,
|
|
692
|
+
to = dateTo,
|
|
693
|
+
interval = statsInterval,
|
|
694
|
+
filter = statsFilter
|
|
695
|
+
)
|
|
735
696
|
|
|
736
|
-
|
|
737
|
-
promise.reject(e.mapException(), e.message)
|
|
738
|
-
}
|
|
697
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
739
698
|
}
|
|
740
699
|
}
|
|
741
700
|
|
|
@@ -748,31 +707,22 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
748
707
|
filter: String?, // StatisticsFilter?
|
|
749
708
|
promise: Promise
|
|
750
709
|
) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
types = statTypes,
|
|
766
|
-
from = dateFrom,
|
|
767
|
-
to = dateTo,
|
|
768
|
-
filter = statsFilter
|
|
769
|
-
)
|
|
710
|
+
executeV3MethodWithConnection("getRecords", connectionUUID, promise) { connection ->
|
|
711
|
+
val statTypes = types.toArrayList().mapNotNull {
|
|
712
|
+
MetricTypeUtils.fromValue(it as String)
|
|
713
|
+
}.toSet()
|
|
714
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
715
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
716
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
717
|
+
|
|
718
|
+
val result = connection.getRecords(
|
|
719
|
+
types = statTypes,
|
|
720
|
+
from = dateFrom,
|
|
721
|
+
to = dateTo,
|
|
722
|
+
filter = statsFilter
|
|
723
|
+
)
|
|
770
724
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
} catch (e: SpikeExceptions) {
|
|
774
|
-
promise.reject(e.mapException(), e.message)
|
|
775
|
-
}
|
|
725
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
776
726
|
}
|
|
777
727
|
}
|
|
778
728
|
|
|
@@ -785,29 +735,20 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
785
735
|
filter: String?, // StatisticsFilter?
|
|
786
736
|
promise: Promise
|
|
787
737
|
) {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
config = configObject,
|
|
801
|
-
from = dateFrom,
|
|
802
|
-
to = dateTo,
|
|
803
|
-
filter = statsFilter
|
|
804
|
-
)
|
|
738
|
+
executeV3MethodWithConnection("getActivities", connectionUUID, promise) { connection ->
|
|
739
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
740
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
741
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
742
|
+
val configObject = ActivityConfigUtils.fromValue(configJson) ?: ActivityConfig()
|
|
743
|
+
|
|
744
|
+
val result = connection.getActivities(
|
|
745
|
+
config = configObject,
|
|
746
|
+
from = dateFrom,
|
|
747
|
+
to = dateTo,
|
|
748
|
+
filter = statsFilter
|
|
749
|
+
)
|
|
805
750
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
} catch (e: SpikeExceptions) {
|
|
809
|
-
promise.reject(e.mapException(), e.message)
|
|
810
|
-
}
|
|
751
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
811
752
|
}
|
|
812
753
|
}
|
|
813
754
|
|
|
@@ -820,29 +761,20 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
820
761
|
filter: String?, // StatisticsFilter?
|
|
821
762
|
promise: Promise
|
|
822
763
|
) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
config = configObject,
|
|
836
|
-
from = dateFrom,
|
|
837
|
-
to = dateTo,
|
|
838
|
-
filter = statsFilter
|
|
839
|
-
)
|
|
764
|
+
executeV3MethodWithConnection("getSleep", connectionUUID, promise) { connection ->
|
|
765
|
+
val dateFrom = convertIsoStringToInstant(from)
|
|
766
|
+
val dateTo = convertIsoStringToInstant(to)
|
|
767
|
+
val statsFilter = StatisticsFilter.fromValue(filter)
|
|
768
|
+
val configObject = SleepConfigUtils.fromValue(configJson) ?: SleepConfig()
|
|
769
|
+
|
|
770
|
+
val result = connection.getSleep(
|
|
771
|
+
config = configObject,
|
|
772
|
+
from = dateFrom,
|
|
773
|
+
to = dateTo,
|
|
774
|
+
filter = statsFilter
|
|
775
|
+
)
|
|
840
776
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
} catch (e: SpikeExceptions) {
|
|
844
|
-
promise.reject(e.mapException(), e.message)
|
|
845
|
-
}
|
|
777
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
846
778
|
}
|
|
847
779
|
}
|
|
848
780
|
|
|
@@ -852,24 +784,13 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
852
784
|
metrics: ReadableArray,
|
|
853
785
|
promise: Promise
|
|
854
786
|
) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
"Connection not found (getUserProperties)"
|
|
860
|
-
)
|
|
861
|
-
|
|
862
|
-
val mTypes = metrics.toArrayList().mapNotNull {
|
|
863
|
-
MetricTypeUtils.fromValue(it as String)
|
|
864
|
-
}.toSet()
|
|
865
|
-
|
|
866
|
-
val result = connection.getUserProperties(types = mTypes)
|
|
867
|
-
|
|
868
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
787
|
+
executeV3MethodWithConnection("getUserProperties", connectionUUID, promise) { connection ->
|
|
788
|
+
val mTypes = metrics.toArrayList().mapNotNull {
|
|
789
|
+
MetricTypeUtils.fromValue(it as String)
|
|
790
|
+
}.toSet()
|
|
869
791
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
}
|
|
792
|
+
val result = connection.getUserProperties(types = mTypes)
|
|
793
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
873
794
|
}
|
|
874
795
|
}
|
|
875
796
|
|
|
@@ -878,126 +799,65 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
878
799
|
|
|
879
800
|
@ReactMethod
|
|
880
801
|
fun checkHealthConnectAvailability(connectionUUID: String, promise: Promise) {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
885
|
-
"Connection not found (checkHealthConnectAvailability)"
|
|
886
|
-
)
|
|
887
|
-
|
|
888
|
-
val result = connection.checkHealthConnectAvailability()
|
|
889
|
-
promise.resolve(result.value)
|
|
890
|
-
|
|
891
|
-
} catch (e: SpikeExceptions) {
|
|
892
|
-
promise.reject(e.mapException(), e.message)
|
|
893
|
-
}
|
|
802
|
+
executeV3MethodWithConnection("checkHealthConnectAvailability", connectionUUID, promise) { connection ->
|
|
803
|
+
val result = connection.checkHealthConnectAvailability()
|
|
804
|
+
promise.resolve(result.value)
|
|
894
805
|
}
|
|
895
806
|
}
|
|
896
807
|
|
|
897
808
|
@ReactMethod
|
|
898
809
|
fun openHealthConnectInstallation(connectionUUID: String, promise: Promise) {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
903
|
-
"Connection not found (openHealthConnectInstallation)"
|
|
904
|
-
)
|
|
905
|
-
|
|
906
|
-
connection.openHealthConnectInstallation()
|
|
907
|
-
promise.resolve(true)
|
|
908
|
-
|
|
909
|
-
} catch (e: SpikeExceptions) {
|
|
910
|
-
promise.reject(e.mapException(), e.message)
|
|
911
|
-
}
|
|
810
|
+
executeV3MethodWithConnection("openHealthConnectInstallation", connectionUUID, promise) { connection ->
|
|
811
|
+
connection.openHealthConnectInstallation()
|
|
812
|
+
promise.resolve(true)
|
|
912
813
|
}
|
|
913
814
|
}
|
|
914
815
|
|
|
915
816
|
@ReactMethod
|
|
916
817
|
fun enableHealthConnectIntegration(connectionUUID: String, promise: Promise) {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
"Connection not found (enableHealthConnectIntegration)"
|
|
922
|
-
)
|
|
923
|
-
|
|
924
|
-
connection.enableHealthConnectIntegration()
|
|
925
|
-
Log.d("SpikeSdkModule", "Health Connect integration enabled")
|
|
926
|
-
promise.resolve(true)
|
|
927
|
-
} catch (e: SpikeExceptions) {
|
|
928
|
-
promise.reject(e.mapException(), e.message)
|
|
929
|
-
}
|
|
818
|
+
executeV3MethodWithConnection("enableHealthConnectIntegration", connectionUUID, promise) { connection ->
|
|
819
|
+
connection.enableHealthConnectIntegration()
|
|
820
|
+
Log.d("SpikeSdkModule", "Health Connect integration enabled")
|
|
821
|
+
promise.resolve(true)
|
|
930
822
|
}
|
|
931
823
|
}
|
|
932
824
|
|
|
933
825
|
@ReactMethod
|
|
934
826
|
fun disableHealthConnectIntegration(connectionUUID: String, promise: Promise) {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
"Connection not found (enableHealthConnectIntegration)"
|
|
940
|
-
)
|
|
941
|
-
|
|
942
|
-
connection.disableHealthConnectIntegration()
|
|
943
|
-
Log.d("SpikeSdkModule", "Health Connect integration disabled")
|
|
944
|
-
promise.resolve(true)
|
|
945
|
-
|
|
946
|
-
} catch (e: SpikeExceptions) {
|
|
947
|
-
promise.reject(e.mapException(), e.message)
|
|
948
|
-
}
|
|
827
|
+
executeV3MethodWithConnection("disableHealthConnectIntegration", connectionUUID, promise) { connection ->
|
|
828
|
+
connection.disableHealthConnectIntegration()
|
|
829
|
+
Log.d("SpikeSdkModule", "Health Connect integration disabled")
|
|
830
|
+
promise.resolve(true)
|
|
949
831
|
}
|
|
950
832
|
}
|
|
951
833
|
|
|
952
834
|
@ReactMethod
|
|
953
835
|
fun isHealthConnectIntegrationEnabled(connectionUUID: String, promise: Promise) {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
"Connection not found (enableHealthConnectIntegration)"
|
|
959
|
-
)
|
|
960
|
-
|
|
961
|
-
val result = connection.isHealthConnectIntegrationEnabled()
|
|
962
|
-
Log.d("SpikeSdkModule", "Health Connect integration is " + if (result) { "enabled" } else ( "disabled" ))
|
|
963
|
-
promise.resolve(result)
|
|
964
|
-
|
|
965
|
-
} catch (e: SpikeExceptions) {
|
|
966
|
-
promise.reject(e.mapException(), e.message)
|
|
967
|
-
}
|
|
836
|
+
executeV3MethodWithConnection("isHealthConnectIntegrationEnabled", connectionUUID, promise) { connection ->
|
|
837
|
+
val result = connection.isHealthConnectIntegrationEnabled()
|
|
838
|
+
Log.d("SpikeSdkModule", "Health Connect integration is " + if (result) { "enabled" } else ( "disabled" ))
|
|
839
|
+
promise.resolve(result)
|
|
968
840
|
}
|
|
969
841
|
}
|
|
970
842
|
|
|
971
843
|
@ReactMethod
|
|
972
844
|
fun getGrantedHealthConnectPermissions(connectionUUID: String, promise: Promise) {
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
"Connection not found (getGrantedHealthConnectPermissions)"
|
|
978
|
-
)
|
|
979
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
980
|
-
return@launch promise.reject(
|
|
981
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
982
|
-
"Health Connect should be enabled before calling getGrantedHealthConnectPermissions"
|
|
983
|
-
)
|
|
984
|
-
}
|
|
845
|
+
executeV3MethodWithConnection("getGrantedHealthConnectPermissions", connectionUUID, promise) { connection ->
|
|
846
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
847
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling getGrantedHealthConnectPermissions")
|
|
848
|
+
}
|
|
985
849
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
850
|
+
val permissions = connection
|
|
851
|
+
.getHealthConnectPermissionManager()
|
|
852
|
+
.getGrantedPermissions()
|
|
989
853
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
Log.w("SpikeSdkModule", "$permissions")
|
|
996
|
-
promise.resolve(result)
|
|
997
|
-
|
|
998
|
-
} catch (e: SpikeExceptions) {
|
|
999
|
-
promise.reject(e.mapException(), e.message)
|
|
854
|
+
val result = Arguments.createArray()
|
|
855
|
+
permissions.forEach {
|
|
856
|
+
result.pushString(it)
|
|
1000
857
|
}
|
|
858
|
+
|
|
859
|
+
Log.w("SpikeSdkModule", "$permissions")
|
|
860
|
+
promise.resolve(result)
|
|
1001
861
|
}
|
|
1002
862
|
}
|
|
1003
863
|
|
|
@@ -1012,122 +872,85 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1012
872
|
includeBackgroundDelivery: Boolean,
|
|
1013
873
|
promise: Promise
|
|
1014
874
|
) {
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
875
|
+
executeV3MethodWithConnection("getHealthConnectPermissions", connectionUUID, promise) { connection ->
|
|
876
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
877
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling getHealthConnectPermissionsForStatisticTypes")
|
|
878
|
+
}
|
|
879
|
+
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
880
|
+
|
|
881
|
+
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
882
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
883
|
+
}.toSet()
|
|
884
|
+
|
|
885
|
+
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
886
|
+
MetricTypeUtils.fromValue(it as String)
|
|
887
|
+
}.toSet()
|
|
888
|
+
|
|
889
|
+
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
890
|
+
ActivityConfigUtils.fromValue(it as String)
|
|
891
|
+
}.toSet()
|
|
892
|
+
|
|
893
|
+
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
894
|
+
SleepConfigUtils.fromValue(it as String)
|
|
895
|
+
}.toSet()
|
|
896
|
+
|
|
897
|
+
val permissions = permissionManager
|
|
898
|
+
.getPermissions(
|
|
899
|
+
statisticsTypes = statTypes,
|
|
900
|
+
metricTypes = mTypes,
|
|
901
|
+
activityConfigs = aConfigs,
|
|
902
|
+
sleepConfigs = sConfigs,
|
|
903
|
+
includeEnhancedPermissions = includeEnhancedPermissions,
|
|
904
|
+
includeBackgroundDelivery = includeBackgroundDelivery
|
|
1020
905
|
)
|
|
1021
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1022
|
-
return@launch promise.reject(
|
|
1023
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1024
|
-
"Health Connect should be enabled before calling getHealthConnectPermissionsForStatisticTypes"
|
|
1025
|
-
)
|
|
1026
|
-
}
|
|
1027
|
-
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1028
|
-
|
|
1029
|
-
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1030
|
-
StatisticsTypeUtils.fromValue(it as String)
|
|
1031
|
-
}.toSet()
|
|
1032
|
-
|
|
1033
|
-
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
1034
|
-
MetricTypeUtils.fromValue(it as String)
|
|
1035
|
-
}.toSet()
|
|
1036
|
-
|
|
1037
|
-
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
1038
|
-
ActivityConfigUtils.fromValue(it as String)
|
|
1039
|
-
}.toSet()
|
|
1040
|
-
|
|
1041
|
-
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
1042
|
-
SleepConfigUtils.fromValue(it as String)
|
|
1043
|
-
}.toSet()
|
|
1044
|
-
|
|
1045
|
-
val permissions = permissionManager
|
|
1046
|
-
.getPermissions(
|
|
1047
|
-
statisticsTypes = statTypes,
|
|
1048
|
-
metricTypes = mTypes,
|
|
1049
|
-
activityConfigs = aConfigs,
|
|
1050
|
-
sleepConfigs = sConfigs,
|
|
1051
|
-
includeEnhancedPermissions = includeEnhancedPermissions,
|
|
1052
|
-
includeBackgroundDelivery = includeBackgroundDelivery
|
|
1053
|
-
)
|
|
1054
906
|
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
// Log.w("SpikeSdkModule", "$permissions")
|
|
1061
|
-
promise.resolve(result)
|
|
1062
|
-
|
|
1063
|
-
} catch (e: SpikeExceptions) {
|
|
1064
|
-
promise.reject(e.mapException(), e.message)
|
|
907
|
+
val result = Arguments.createArray()
|
|
908
|
+
permissions.forEach {
|
|
909
|
+
result.pushString(it)
|
|
1065
910
|
}
|
|
911
|
+
|
|
912
|
+
// Log.w("SpikeSdkModule", "$permissions")
|
|
913
|
+
promise.resolve(result)
|
|
1066
914
|
}
|
|
1067
915
|
}
|
|
1068
916
|
|
|
1069
917
|
@ReactMethod
|
|
1070
918
|
fun revokeAllHealthConnectPermissions(connectionUUID: String, promise: Promise) {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
SpikeExceptions.SpikeException("Connection not found").mapException(),
|
|
1075
|
-
"Connection not found (revokeAllHealthConnectPermissions)"
|
|
1076
|
-
)
|
|
1077
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1078
|
-
return@launch promise.reject(
|
|
1079
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1080
|
-
"Health Connect should be enabled before calling revokeAllHealthConnectPermissions"
|
|
1081
|
-
)
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
connection
|
|
1085
|
-
.getHealthConnectPermissionManager()
|
|
1086
|
-
.revokeAllPermissions()
|
|
1087
|
-
|
|
1088
|
-
promise.resolve(true)
|
|
1089
|
-
|
|
1090
|
-
} catch (e: SpikeExceptions) {
|
|
1091
|
-
promise.reject(e.mapException(), e.message)
|
|
919
|
+
executeV3MethodWithConnection("revokeAllHealthConnectPermissions", connectionUUID, promise) { connection ->
|
|
920
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
921
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling revokeAllHealthConnectPermissions")
|
|
1092
922
|
}
|
|
923
|
+
|
|
924
|
+
connection
|
|
925
|
+
.getHealthConnectPermissionManager()
|
|
926
|
+
.revokeAllPermissions()
|
|
927
|
+
|
|
928
|
+
promise.resolve(true)
|
|
1093
929
|
}
|
|
1094
930
|
}
|
|
1095
931
|
|
|
1096
932
|
@ReactMethod
|
|
1097
933
|
fun requestPermissionsFromHealthConnect(connectionUUID: String, permissions: ReadableArray, promise: Promise) {
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
"Connection not found"
|
|
1103
|
-
).mapException(), "Connection not found"
|
|
1104
|
-
)
|
|
1105
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1106
|
-
return@launch promise.reject(
|
|
1107
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1108
|
-
"Health Connect should be enabled before calling requestPermissionsFromHealthConnect"
|
|
1109
|
-
)
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1113
|
-
val permissionsStrings = permissions.toArrayList().map{ it as String }.toSet()
|
|
934
|
+
executeV3MethodWithConnection("requestPermissionsFromHealthConnect", connectionUUID, promise) { connection ->
|
|
935
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
936
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling requestPermissionsFromHealthConnect")
|
|
937
|
+
}
|
|
1114
938
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
promise.resolve(true)
|
|
1118
|
-
return@launch
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
Log.d("SpikeSdkModule", "Will ask for following Health Connect permissions: $permissions")
|
|
939
|
+
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
940
|
+
val permissionsStrings = permissions.toArrayList().map{ it as String }.toSet()
|
|
1122
941
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
942
|
+
if (checkIfAllPermissionsAreGranted(permissionManager, permissionsStrings)) {
|
|
943
|
+
// All permissions granted, nothing to do here
|
|
944
|
+
promise.resolve(true)
|
|
945
|
+
return@executeV3MethodWithConnection
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
Log.d("SpikeSdkModule", "Will ask for following Health Connect permissions: $permissions")
|
|
1128
949
|
|
|
1129
|
-
|
|
1130
|
-
|
|
950
|
+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.TIRAMISU) {
|
|
951
|
+
startHealthConnectRequest_oldAndroid(connectionUUID, permissionManager, permissionsStrings, promise)
|
|
952
|
+
} else {
|
|
953
|
+
startHealthConnectRequest(connectionUUID, permissionManager, permissionsStrings, promise)
|
|
1131
954
|
}
|
|
1132
955
|
}
|
|
1133
956
|
}
|
|
@@ -1176,27 +999,14 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1176
999
|
}
|
|
1177
1000
|
|
|
1178
1001
|
fun areAllPermissionsGranted(connectionUUID: String, permissions: Set<String>, promise: Promise) {
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
SpikeExceptions.SpikeException(
|
|
1183
|
-
"Connection not found"
|
|
1184
|
-
).mapException(), "Connection not found"
|
|
1185
|
-
)
|
|
1186
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1187
|
-
return@launch promise.reject(
|
|
1188
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1189
|
-
"Health Connect should be enabled before calling areAllPermissionsGranted"
|
|
1190
|
-
)
|
|
1191
|
-
}
|
|
1192
|
-
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1193
|
-
|
|
1194
|
-
val permissionsGranted: Boolean = checkIfAllPermissionsAreGranted(permissionManager, permissions)
|
|
1195
|
-
promise.resolve(permissionsGranted)
|
|
1196
|
-
|
|
1197
|
-
} catch (e: SpikeExceptions) {
|
|
1198
|
-
promise.reject(e.mapException(), e.message)
|
|
1002
|
+
executeV3MethodWithConnection("areAllPermissionsGranted", connectionUUID, promise) { connection ->
|
|
1003
|
+
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1004
|
+
throw SpikeExceptions.SpikeException("Health Connect should be enabled before calling areAllPermissionsGranted")
|
|
1199
1005
|
}
|
|
1006
|
+
val permissionManager = connection.getHealthConnectPermissionManager()
|
|
1007
|
+
|
|
1008
|
+
val permissionsGranted: Boolean = checkIfAllPermissionsAreGranted(permissionManager, permissions)
|
|
1009
|
+
promise.resolve(permissionsGranted)
|
|
1200
1010
|
}
|
|
1201
1011
|
}
|
|
1202
1012
|
|
|
@@ -1215,47 +1025,38 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1215
1025
|
sleepConfigs: ReadableArray,
|
|
1216
1026
|
promise: Promise
|
|
1217
1027
|
) {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
)
|
|
1224
|
-
|
|
1225
|
-
return@launch promise.reject(
|
|
1226
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1227
|
-
"Health Connect should be enabled before calling enableBackgroundDelivery"
|
|
1228
|
-
)
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1232
|
-
StatisticsTypeUtils.fromValue(it as String)
|
|
1233
|
-
}.toSet()
|
|
1028
|
+
executeV3MethodWithConnection("enableBackgroundDelivery", connectionUUID, promise) { connection ->
|
|
1029
|
+
val healthConnectEnabled = connection.isHealthConnectIntegrationEnabled()
|
|
1030
|
+
val samsungHealthDataEnabled = connection.isSamsungHealthDataIntegrationEnabled()
|
|
1031
|
+
|
|
1032
|
+
if (!healthConnectEnabled && !samsungHealthDataEnabled) {
|
|
1033
|
+
throw SpikeExceptions.SpikeException("Either Health Connect or Samsung Health Data should be enabled before calling enableBackgroundDelivery")
|
|
1034
|
+
}
|
|
1234
1035
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1036
|
+
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1037
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
1038
|
+
}.toSet()
|
|
1238
1039
|
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1040
|
+
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
1041
|
+
MetricTypeUtils.fromValue(it as String)
|
|
1042
|
+
}.toSet()
|
|
1242
1043
|
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1044
|
+
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
1045
|
+
ActivityConfigUtils.fromValue(it as String)
|
|
1046
|
+
}.toSet()
|
|
1246
1047
|
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
activityConfigs = aConfigs,
|
|
1251
|
-
sleepConfigs = sConfigs
|
|
1252
|
-
)
|
|
1048
|
+
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
1049
|
+
SleepConfigUtils.fromValue(it as String)
|
|
1050
|
+
}.toSet()
|
|
1253
1051
|
|
|
1254
|
-
|
|
1052
|
+
connection.enableBackgroundDelivery(
|
|
1053
|
+
statisticsTypes = statTypes,
|
|
1054
|
+
metricTypes = mTypes,
|
|
1055
|
+
activityConfigs = aConfigs,
|
|
1056
|
+
sleepConfigs = sConfigs
|
|
1057
|
+
)
|
|
1255
1058
|
|
|
1256
|
-
|
|
1257
|
-
promise.reject(e.mapException(), e.message)
|
|
1258
|
-
}
|
|
1059
|
+
promise.resolve(true)
|
|
1259
1060
|
}
|
|
1260
1061
|
}
|
|
1261
1062
|
|
|
@@ -1264,24 +1065,15 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1264
1065
|
connectionUUID: String,
|
|
1265
1066
|
promise: Promise
|
|
1266
1067
|
) {
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
)
|
|
1273
|
-
if (!connection.isHealthConnectIntegrationEnabled()) {
|
|
1274
|
-
return@launch promise.reject(
|
|
1275
|
-
SpikeExceptions.SpikeException("Health Connect is disabled").mapException(),
|
|
1276
|
-
"Health Connect should be enabled before calling disableBackgroundDelivery"
|
|
1277
|
-
)
|
|
1278
|
-
}
|
|
1279
|
-
connection.disableBackgroundDelivery()
|
|
1280
|
-
promise.resolve(true)
|
|
1281
|
-
|
|
1282
|
-
} catch (e: SpikeExceptions) {
|
|
1283
|
-
promise.reject(e.mapException(), e.message)
|
|
1068
|
+
executeV3MethodWithConnection("disableBackgroundDelivery", connectionUUID, promise) { connection ->
|
|
1069
|
+
val healthConnectEnabled = connection.isHealthConnectIntegrationEnabled()
|
|
1070
|
+
val samsungHealthDataEnabled = connection.isSamsungHealthDataIntegrationEnabled()
|
|
1071
|
+
|
|
1072
|
+
if (!healthConnectEnabled && !samsungHealthDataEnabled) {
|
|
1073
|
+
throw SpikeExceptions.SpikeException("Either Health Connect or Samsung Health Data should be enabled before calling disableBackgroundDelivery")
|
|
1284
1074
|
}
|
|
1075
|
+
connection.disableBackgroundDelivery()
|
|
1076
|
+
promise.resolve(true)
|
|
1285
1077
|
}
|
|
1286
1078
|
}
|
|
1287
1079
|
|
|
@@ -1290,27 +1082,18 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1290
1082
|
connectionUUID: String,
|
|
1291
1083
|
promise: Promise
|
|
1292
1084
|
) {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
)
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
val result = connection.getBackgroundDeliveryConfig()
|
|
1306
|
-
if (result == null) {
|
|
1307
|
-
promise.resolve(null)
|
|
1308
|
-
} else {
|
|
1309
|
-
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
} catch (e: SpikeExceptions) {
|
|
1313
|
-
promise.reject(e.mapException(), e.message)
|
|
1085
|
+
executeV3MethodWithConnection("getBackgroundDeliveryConfig", connectionUUID, promise) { connection ->
|
|
1086
|
+
val healthConnectEnabled = connection.isHealthConnectIntegrationEnabled()
|
|
1087
|
+
val samsungHealthDataEnabled = connection.isSamsungHealthDataIntegrationEnabled()
|
|
1088
|
+
|
|
1089
|
+
if (!healthConnectEnabled && !samsungHealthDataEnabled) {
|
|
1090
|
+
throw SpikeExceptions.SpikeException("Either Health Connect or Samsung Health Data should be enabled before calling getBackgroundDeliveryConfig")
|
|
1091
|
+
}
|
|
1092
|
+
val result = connection.getBackgroundDeliveryConfig()
|
|
1093
|
+
if (result == null) {
|
|
1094
|
+
promise.resolve(null)
|
|
1095
|
+
} else {
|
|
1096
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
1314
1097
|
}
|
|
1315
1098
|
}
|
|
1316
1099
|
}
|
|
@@ -1336,6 +1119,221 @@ class SpikeSdkModule(reactContext: ReactApplicationContext) :
|
|
|
1336
1119
|
}
|
|
1337
1120
|
}
|
|
1338
1121
|
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Centralized error handling for V3 methods
|
|
1125
|
+
* Executes the provided block in a coroutine scope with comprehensive error handling
|
|
1126
|
+
*/
|
|
1127
|
+
private fun executeV3Method(
|
|
1128
|
+
promise: Promise,
|
|
1129
|
+
block: suspend () -> Unit
|
|
1130
|
+
) {
|
|
1131
|
+
scope.launch {
|
|
1132
|
+
try {
|
|
1133
|
+
block()
|
|
1134
|
+
} catch (e: SpikeExceptions) {
|
|
1135
|
+
promise.reject(e.mapException(), e.message)
|
|
1136
|
+
} catch (e: Exception) {
|
|
1137
|
+
promise.reject(e.toString(), e.message)
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Centralized error handling for V3 methods that need connection validation
|
|
1144
|
+
* Executes the provided block in a coroutine scope with connection validation and comprehensive error handling
|
|
1145
|
+
*/
|
|
1146
|
+
private fun executeV3MethodWithConnection(
|
|
1147
|
+
methodName: String,
|
|
1148
|
+
connectionUUID: String,
|
|
1149
|
+
promise: Promise,
|
|
1150
|
+
block: suspend (SpikeConnectionAPIv3) -> Unit
|
|
1151
|
+
) {
|
|
1152
|
+
executeV3Method(promise) {
|
|
1153
|
+
val connection = getConnectionV3(connectionUUID) ?: throw SpikeExceptions.SpikeException(
|
|
1154
|
+
"Connection not found ($methodName)"
|
|
1155
|
+
)
|
|
1156
|
+
block(connection)
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/// --- Samsung Health Data permissions ---
|
|
1161
|
+
|
|
1162
|
+
@ReactMethod
|
|
1163
|
+
fun checkSamsungHealthDataAvailability(connectionUUID: String, promise: Promise) {
|
|
1164
|
+
executeV3MethodWithConnection("checkSamsungHealthDataAvailability", connectionUUID, promise) { connection ->
|
|
1165
|
+
val activity = reactApplicationContext.currentActivity
|
|
1166
|
+
if (activity == null) {
|
|
1167
|
+
throw SpikeExceptions.SpikeException("Activity is required to check Samsung Health Data availability")
|
|
1168
|
+
}
|
|
1169
|
+
val result = connection.checkSamsungHealthDataAvailability(activity)
|
|
1170
|
+
promise.resolve(SpikeConnectionAPIv3.convertToJson(result))
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
@ReactMethod
|
|
1175
|
+
fun enableSamsungHealthDataIntegration(connectionUUID: String, promise: Promise) {
|
|
1176
|
+
executeV3MethodWithConnection("enableSamsungHealthDataIntegration", connectionUUID, promise) { connection ->
|
|
1177
|
+
val activity = reactApplicationContext.currentActivity
|
|
1178
|
+
if (activity == null) {
|
|
1179
|
+
throw SpikeExceptions.SpikeException("Activity is required to enable Samsung Health Data integration")
|
|
1180
|
+
}
|
|
1181
|
+
connection.enableSamsungHealthDataIntegration(activity)
|
|
1182
|
+
Log.d("SpikeSdkModule", "Samsung Health Data integration enabled")
|
|
1183
|
+
promise.resolve(true)
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
@ReactMethod
|
|
1188
|
+
fun disableSamsungHealthDataIntegration(connectionUUID: String, promise: Promise) {
|
|
1189
|
+
executeV3MethodWithConnection("disableSamsungHealthDataIntegration", connectionUUID, promise) { connection ->
|
|
1190
|
+
connection.disableSamsungHealthDataIntegration()
|
|
1191
|
+
Log.d("SpikeSdkModule", "Samsung Health Data integration disabled")
|
|
1192
|
+
promise.resolve(true)
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
@ReactMethod
|
|
1197
|
+
fun isSamsungHealthDataIntegrationEnabled(connectionUUID: String, promise: Promise) {
|
|
1198
|
+
executeV3MethodWithConnection("isSamsungHealthDataIntegrationEnabled", connectionUUID, promise) { connection ->
|
|
1199
|
+
val result = connection.isSamsungHealthDataIntegrationEnabled()
|
|
1200
|
+
Log.d("SpikeSdkModule", "Samsung Health Data integration is " + if (result) { "enabled" } else ( "disabled" ))
|
|
1201
|
+
promise.resolve(result)
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
@ReactMethod
|
|
1206
|
+
fun getGrantedSamsungHealthDataPermissions(connectionUUID: String, promise: Promise) {
|
|
1207
|
+
executeV3MethodWithConnection("getGrantedSamsungHealthDataPermissions", connectionUUID, promise) { connection ->
|
|
1208
|
+
if (!connection.isSamsungHealthDataIntegrationEnabled()) {
|
|
1209
|
+
throw SpikeExceptions.SpikeException("Samsung Health Data should be enabled before calling getGrantedSamsungHealthDataPermissions")
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
val permissions = connection
|
|
1213
|
+
.getSamsungHealthDataPermissionManager()
|
|
1214
|
+
.getGrantedPermissions()
|
|
1215
|
+
|
|
1216
|
+
val result = Arguments.createArray()
|
|
1217
|
+
permissions.forEach {
|
|
1218
|
+
result.pushString(it)
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
Log.w("SpikeSdkModule", "$permissions")
|
|
1222
|
+
promise.resolve(result)
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
@ReactMethod
|
|
1227
|
+
fun getSamsungHealthDataPermissions(
|
|
1228
|
+
connectionUUID: String,
|
|
1229
|
+
statisticTypes: ReadableArray,
|
|
1230
|
+
metricTypes: ReadableArray,
|
|
1231
|
+
activityConfigs: ReadableArray,
|
|
1232
|
+
sleepConfigs: ReadableArray,
|
|
1233
|
+
promise: Promise
|
|
1234
|
+
) {
|
|
1235
|
+
executeV3MethodWithConnection("getSamsungHealthDataPermissions", connectionUUID, promise) { connection ->
|
|
1236
|
+
if (!connection.isSamsungHealthDataIntegrationEnabled()) {
|
|
1237
|
+
throw SpikeExceptions.SpikeException("Samsung Health Data should be enabled before calling getSamsungHealthDataPermissions")
|
|
1238
|
+
}
|
|
1239
|
+
val permissionManager = connection.getSamsungHealthDataPermissionManager()
|
|
1240
|
+
|
|
1241
|
+
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1242
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
1243
|
+
}.toSet()
|
|
1244
|
+
|
|
1245
|
+
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
1246
|
+
MetricTypeUtils.fromValue(it as String)
|
|
1247
|
+
}.toSet()
|
|
1248
|
+
|
|
1249
|
+
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
1250
|
+
ActivityConfigUtils.fromValue(it as String)
|
|
1251
|
+
}.toSet()
|
|
1252
|
+
|
|
1253
|
+
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
1254
|
+
SleepConfigUtils.fromValue(it as String)
|
|
1255
|
+
}.toSet()
|
|
1256
|
+
|
|
1257
|
+
val permissions = permissionManager
|
|
1258
|
+
.getPermissions(
|
|
1259
|
+
statisticsTypes = statTypes,
|
|
1260
|
+
metricTypes = mTypes,
|
|
1261
|
+
activityConfigs = aConfigs,
|
|
1262
|
+
sleepConfigs = sConfigs
|
|
1263
|
+
)
|
|
1264
|
+
|
|
1265
|
+
val result = Arguments.createArray()
|
|
1266
|
+
permissions.forEach {
|
|
1267
|
+
result.pushString(it)
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
promise.resolve(result)
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
@ReactMethod
|
|
1275
|
+
fun requestPermissionsFromSamsungHealthData(
|
|
1276
|
+
connectionUUID: String,
|
|
1277
|
+
statisticTypes: ReadableArray,
|
|
1278
|
+
metricTypes: ReadableArray,
|
|
1279
|
+
activityConfigs: ReadableArray,
|
|
1280
|
+
sleepConfigs: ReadableArray,
|
|
1281
|
+
promise: Promise
|
|
1282
|
+
) {
|
|
1283
|
+
executeV3MethodWithConnection("requestPermissionsFromSamsungHealthData", connectionUUID, promise) { connection ->
|
|
1284
|
+
if (!connection.isSamsungHealthDataIntegrationEnabled()) {
|
|
1285
|
+
throw SpikeExceptions.SpikeException("Samsung Health Data should be enabled before calling requestPermissionsFromSamsungHealthData")
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
val permissionManager = connection.getSamsungHealthDataPermissionManager()
|
|
1289
|
+
|
|
1290
|
+
val statTypes = statisticTypes.toArrayList().mapNotNull {
|
|
1291
|
+
StatisticsTypeUtils.fromValue(it as String)
|
|
1292
|
+
}.toSet()
|
|
1293
|
+
|
|
1294
|
+
val mTypes = metricTypes.toArrayList().mapNotNull {
|
|
1295
|
+
MetricTypeUtils.fromValue(it as String)
|
|
1296
|
+
}.toSet()
|
|
1297
|
+
|
|
1298
|
+
val aConfigs = activityConfigs.toArrayList().mapNotNull {
|
|
1299
|
+
ActivityConfigUtils.fromValue(it as String)
|
|
1300
|
+
}.toSet()
|
|
1301
|
+
|
|
1302
|
+
val sConfigs = sleepConfigs.toArrayList().mapNotNull {
|
|
1303
|
+
SleepConfigUtils.fromValue(it as String)
|
|
1304
|
+
}.toSet()
|
|
1305
|
+
|
|
1306
|
+
Log.d("SpikeSdkModule", "Will ask for Samsung Health Data permissions with: statTypes=$statTypes, metricTypes=$mTypes, activityConfigs=$aConfigs, sleepConfigs=$sConfigs")
|
|
1307
|
+
|
|
1308
|
+
val activity = reactApplicationContext.currentActivity
|
|
1309
|
+
if (activity == null) {
|
|
1310
|
+
throw SpikeExceptions.SpikeException("Activity is required to request Samsung Health Data permissions")
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
try {
|
|
1314
|
+
val grantedPermissions = permissionManager.requestPermissions(
|
|
1315
|
+
statisticsTypes = statTypes,
|
|
1316
|
+
metricTypes = mTypes,
|
|
1317
|
+
activityConfigs = aConfigs,
|
|
1318
|
+
sleepConfigs = sConfigs
|
|
1319
|
+
)
|
|
1320
|
+
|
|
1321
|
+
val result = Arguments.createArray()
|
|
1322
|
+
grantedPermissions.forEach {
|
|
1323
|
+
result.pushString(it)
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
promise.resolve(result)
|
|
1327
|
+
} catch (e: Exception) {
|
|
1328
|
+
promise.reject(e.toString(), e.message)
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
|
|
1334
|
+
|
|
1335
|
+
/// ---
|
|
1336
|
+
|
|
1339
1337
|
}
|
|
1340
1338
|
|
|
1341
1339
|
private fun convertIsoStringToInstant(isoString: String): Instant {
|