react-native-visit-rn-sdk 2.0.13 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +4 -0
- package/android/gradle.properties +4 -4
- package/android/src/main/java/com/visitrnsdk/VisitFitnessModule.kt +605 -0
- package/android/src/main/java/com/visitrnsdk/VisitRnSdkPackage.kt +1 -1
- package/android/src/main/java/com/visitrnsdk/VisitSessionStorage.kt +50 -0
- package/package.json +3 -2
- package/android/bin/build/generated/source/buildConfig/debug/com/visitrnsdk/BuildConfig.class +0 -0
- package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +0 -7
- package/android/bin/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +0 -18
- package/android/bin/build/intermediates/aar_main_jar/debug/classes.jar +0 -0
- package/android/bin/build/intermediates/aar_metadata/debug/aar-metadata.properties +0 -5
- package/android/bin/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +0 -1
- package/android/bin/build/intermediates/annotations_typedef_file/debug/typedefs.txt +0 -0
- package/android/bin/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
- package/android/bin/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
- package/android/bin/build/intermediates/compile_symbol_list/debug/R.txt +0 -1954
- package/android/bin/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +0 -1
- package/android/bin/build/intermediates/incremental/debug/packageDebugResources/merger.xml +0 -2
- package/android/bin/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
- package/android/bin/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
- package/android/bin/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
- package/android/bin/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
- package/android/bin/build/intermediates/library_java_res/debug/res.jar +0 -0
- package/android/bin/build/intermediates/local_only_symbol_list/debug/R-def.txt +0 -2
- package/android/bin/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +0 -8
- package/android/bin/build/intermediates/merged_java_res/debug/feature-react-native-visit-rn-sdk.jar +0 -0
- package/android/bin/build/intermediates/merged_manifest/debug/AndroidManifest.xml +0 -7
- package/android/bin/build/intermediates/navigation_json/debug/navigation.json +0 -1
- package/android/bin/build/intermediates/packaged_manifests/debug/output-metadata.json +0 -18
- package/android/bin/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
- package/android/bin/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +0 -1447
- package/android/bin/build/intermediates/variant_model/debug/variant_model.json +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +0 -2
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i.len +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
- package/android/bin/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
- package/android/bin/build/outputs/aar/react-native-visit-rn-sdk-debug.aar +0 -0
- package/android/bin/build/outputs/logs/manifest-merger-debug-report.txt +0 -25
- package/android/bin/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/bin/build/tmp/kotlin-classes/debug/META-INF/react-native-visit-rn-sdk_debug.kotlin_module +0 -0
- package/android/bin/local.properties +0 -8
package/android/build.gradle
CHANGED
|
@@ -101,6 +101,10 @@ dependencies {
|
|
|
101
101
|
//noinspection GradleDynamicVersion
|
|
102
102
|
implementation "com.facebook.react:react-native:+"
|
|
103
103
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
104
|
+
implementation "com.github.VisitApp:AndroidSDK:v3.08"
|
|
105
|
+
implementation "androidx.health.connect:connect-client:1.1.0"
|
|
106
|
+
implementation "com.jakewharton.timber:timber:5.0.1"
|
|
107
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1"
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
if (isNewArchitectureEnabled()) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
VisitRnSdk_kotlinVersion=1.
|
|
2
|
-
VisitRnSdk_minSdkVersion=
|
|
3
|
-
VisitRnSdk_targetSdkVersion=
|
|
4
|
-
VisitRnSdk_compileSdkVersion=
|
|
1
|
+
VisitRnSdk_kotlinVersion=1.9.25
|
|
2
|
+
VisitRnSdk_minSdkVersion=23
|
|
3
|
+
VisitRnSdk_targetSdkVersion=35
|
|
4
|
+
VisitRnSdk_compileSdkVersion=36
|
|
5
5
|
VisitRnSdk_ndkversion=21.4.7075529
|
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
package com.visitrnsdk
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.content.Intent
|
|
5
|
+
import android.net.Uri
|
|
6
|
+
import android.os.Handler
|
|
7
|
+
import android.os.Looper
|
|
8
|
+
import android.util.Log
|
|
9
|
+
import androidx.annotation.Keep
|
|
10
|
+
import androidx.activity.result.ActivityResultLauncher
|
|
11
|
+
import androidx.activity.result.ActivityResultRegistryOwner
|
|
12
|
+
import androidx.health.connect.client.PermissionController
|
|
13
|
+
import com.facebook.react.bridge.Promise
|
|
14
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
15
|
+
import com.facebook.react.bridge.ReactContext
|
|
16
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
17
|
+
import com.facebook.react.bridge.ReactMethod
|
|
18
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
19
|
+
import com.getvisitapp.visit.HealthConnectListener
|
|
20
|
+
import com.getvisitapp.visit.data.VisitStepSyncHelper
|
|
21
|
+
import com.getvisitapp.visit.healthConnect.activity.HealthConnectUtil
|
|
22
|
+
import com.getvisitapp.visit.healthConnect.contants.Contants.previouslyRevoked
|
|
23
|
+
import com.getvisitapp.visit.healthConnect.enums.HealthConnectConnectionState
|
|
24
|
+
import com.getvisitapp.visit.healthConnect.enums.HealthConnectConnectionState.CONNECTED
|
|
25
|
+
import com.getvisitapp.visit.healthConnect.enums.HealthConnectConnectionState.INSTALLED
|
|
26
|
+
import com.getvisitapp.visit.healthConnect.enums.HealthConnectConnectionState.NONE
|
|
27
|
+
import com.getvisitapp.visit.healthConnect.enums.HealthConnectConnectionState.NOT_INSTALLED
|
|
28
|
+
import com.getvisitapp.visit.healthConnect.enums.HealthConnectConnectionState.NOT_SUPPORTED
|
|
29
|
+
import kotlinx.coroutines.Dispatchers
|
|
30
|
+
import kotlinx.coroutines.launch
|
|
31
|
+
import kotlinx.coroutines.withContext
|
|
32
|
+
import timber.log.Timber
|
|
33
|
+
|
|
34
|
+
@Keep
|
|
35
|
+
class VisitFitnessModule(reactContext: ReactApplicationContext) :
|
|
36
|
+
ReactContextBaseJavaModule(reactContext), HealthConnectListener {
|
|
37
|
+
|
|
38
|
+
private companion object {
|
|
39
|
+
private const val HEALTH_CONNECT_PERMISSION_REQUEST_CODE = 7021
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private val TAG = "mytag"
|
|
43
|
+
private val reactContext: ReactContext = reactContext
|
|
44
|
+
private val reactApplicationContext: ReactApplicationContext = reactContext
|
|
45
|
+
|
|
46
|
+
private var promise: Promise? = null
|
|
47
|
+
|
|
48
|
+
private var healthConnectStatusPromise: Promise? = null
|
|
49
|
+
private var dataRetrivalPromise: Promise? = null
|
|
50
|
+
private var isLoggingEnabled = false
|
|
51
|
+
|
|
52
|
+
private var visitStepSyncHelper: VisitStepSyncHelper? = null
|
|
53
|
+
private var healthConnectUtil: HealthConnectUtil? = null
|
|
54
|
+
private var syncDataWithServer = false
|
|
55
|
+
|
|
56
|
+
@Volatile
|
|
57
|
+
private var isSyncInProgress = false
|
|
58
|
+
private var mainActivity: Activity? = null
|
|
59
|
+
|
|
60
|
+
private lateinit var visitSessionStorage: VisitSessionStorage
|
|
61
|
+
private val requestPermissionActivityContract =
|
|
62
|
+
PermissionController.createRequestPermissionResultContract()
|
|
63
|
+
private var requestPermissionsLauncher: ActivityResultLauncher<Set<String>>? = null
|
|
64
|
+
private var requestPermissionsLauncherActivity: Activity? = null
|
|
65
|
+
|
|
66
|
+
init {
|
|
67
|
+
Log.d(TAG, "GoogleFitPermissionModule: inside constructor")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@ReactMethod
|
|
71
|
+
fun initiateSDK(isLoggingEnabled: Boolean) {
|
|
72
|
+
this.isLoggingEnabled = isLoggingEnabled
|
|
73
|
+
configureTimber(isLoggingEnabled)
|
|
74
|
+
Timber.d("mytag: initiateSDK %b", isLoggingEnabled)
|
|
75
|
+
mainActivity = reactApplicationContext.currentActivity
|
|
76
|
+
|
|
77
|
+
//don't initialise the native module if the mainActivity instance is null.
|
|
78
|
+
if (mainActivity == null) {
|
|
79
|
+
Timber.d("mytag: initiateSDK() skipped because currentActivity is null")
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
visitStepSyncHelper = VisitStepSyncHelper(mainActivity!!)
|
|
83
|
+
healthConnectUtil = HealthConnectUtil(mainActivity!!, this)
|
|
84
|
+
healthConnectUtil!!.initialize()
|
|
85
|
+
visitSessionStorage = VisitSessionStorage(mainActivity!!)
|
|
86
|
+
|
|
87
|
+
Timber.d("mytag: initiateSDK() called")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@ReactMethod
|
|
91
|
+
fun getHealthConnectStatus(healthConnectStatusPromise: Promise) {
|
|
92
|
+
this.healthConnectStatusPromise = healthConnectStatusPromise
|
|
93
|
+
|
|
94
|
+
Timber.d("mytag: getHealthConnectStatus called")
|
|
95
|
+
|
|
96
|
+
healthConnectUtil?.scope?.launch {
|
|
97
|
+
val status: HealthConnectConnectionState = healthConnectUtil!!.checkAvailability()
|
|
98
|
+
|
|
99
|
+
withContext(Dispatchers.Main) {
|
|
100
|
+
when (status) {
|
|
101
|
+
NOT_SUPPORTED -> {
|
|
102
|
+
healthConnectStatusPromise.resolve("NOT_SUPPORTED")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
NOT_INSTALLED -> {
|
|
106
|
+
healthConnectStatusPromise.resolve("NOT_INSTALLED")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
INSTALLED -> {
|
|
110
|
+
healthConnectStatusPromise.resolve("INSTALLED")
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
CONNECTED -> {
|
|
114
|
+
healthConnectStatusPromise.resolve("CONNECTED")
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
NONE -> {
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@ReactMethod
|
|
126
|
+
fun askForFitnessPermission(promise: Promise) {
|
|
127
|
+
this.promise = promise
|
|
128
|
+
healthConnectUtil?.let {
|
|
129
|
+
if (healthConnectUtil!!.healthConnectConnectionState == CONNECTED) {
|
|
130
|
+
Timber.d("askForFitnessPermission: already granted")
|
|
131
|
+
promise.resolve("GRANTED")
|
|
132
|
+
} else {
|
|
133
|
+
Timber.d("askForFitnessPermission: request permission")
|
|
134
|
+
healthConnectUtil!!.requestPermission()
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
override fun userAcceptedHealthConnectPermission() {
|
|
141
|
+
Timber.d("userAcceptedHealthConnectPermission")
|
|
142
|
+
promise?.resolve("GRANTED")
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
override fun userDeniedHealthConnectPermission() {
|
|
146
|
+
Timber.d("userDeniedHealthConnectPermission")
|
|
147
|
+
promise?.resolve("CANCELLED")
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@ReactMethod
|
|
151
|
+
fun requestDailyFitnessData(promise: Promise?) {
|
|
152
|
+
this.dataRetrivalPromise = promise
|
|
153
|
+
|
|
154
|
+
if (healthConnectUtil!!.healthConnectConnectionState == CONNECTED) {
|
|
155
|
+
healthConnectUtil!!.getVisitDashboardGraph()
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@ReactMethod
|
|
160
|
+
fun requestActivityDataFromHealthConnect(
|
|
161
|
+
type: String?, frequency: String?, timestamp: Double, promise: Promise?
|
|
162
|
+
) {
|
|
163
|
+
this.dataRetrivalPromise = promise
|
|
164
|
+
Timber.d("mytag: requestActivityData() called.")
|
|
165
|
+
healthConnectUtil?.let {
|
|
166
|
+
if (healthConnectUtil!!.healthConnectConnectionState == HealthConnectConnectionState.CONNECTED) {
|
|
167
|
+
//Health Connect Implementation
|
|
168
|
+
healthConnectUtil!!.getActivityData(type, frequency, Math.round(timestamp))
|
|
169
|
+
} else {
|
|
170
|
+
Timber.d("mytag: permission not available healthConnectConnectionState: ${healthConnectUtil!!.healthConnectConnectionState}")
|
|
171
|
+
healthConnectUtil!!.requestPermission()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@ReactMethod
|
|
178
|
+
fun updateApiBaseUrl(
|
|
179
|
+
apiBaseUrl: String,
|
|
180
|
+
authToken: String,
|
|
181
|
+
googleFitLastSync: Double,
|
|
182
|
+
gfHourlyLastSync: Double,
|
|
183
|
+
promise: Promise?
|
|
184
|
+
) {
|
|
185
|
+
if (isLoggingEnabled) {
|
|
186
|
+
Log.d(
|
|
187
|
+
"mytag",
|
|
188
|
+
"GoogleFitPermissionModule syncDataWithServer(): baseUrl: " + apiBaseUrl + " googleFitLastSync: " + googleFitLastSync + " gfHourlyLastSync:" + gfHourlyLastSync
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!::visitSessionStorage.isInitialized) {
|
|
193
|
+
promise?.resolve("Health SDK Not Initialized")
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
val normalizedBaseUrl = normalizeBaseUrl(apiBaseUrl)
|
|
198
|
+
|
|
199
|
+
visitSessionStorage.saveBaseUrl(normalizedBaseUrl)
|
|
200
|
+
visitSessionStorage.saveVisitAuthToken(authToken)
|
|
201
|
+
visitSessionStorage.saveDailyLastSyncTimeStamp(Math.round(googleFitLastSync))
|
|
202
|
+
visitSessionStorage.saveHourlyLastSyncTimeStamp(Math.round(gfHourlyLastSync))
|
|
203
|
+
|
|
204
|
+
val healthConnectUtil = healthConnectUtil
|
|
205
|
+
val visitStepSyncHelper = visitStepSyncHelper
|
|
206
|
+
|
|
207
|
+
if (healthConnectUtil == null || visitStepSyncHelper == null) {
|
|
208
|
+
promise?.resolve("Health SDK Not Initialized")
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (isSyncInProgress) {
|
|
213
|
+
promise?.resolve("Health Data Sync Already In Progress")
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!syncDataWithServer) {
|
|
218
|
+
Timber.d("mytag: syncDataWithServer() called")
|
|
219
|
+
isSyncInProgress = true
|
|
220
|
+
visitStepSyncHelper.sendDataToVisitServer(
|
|
221
|
+
healthConnectUtil,
|
|
222
|
+
Math.round(googleFitLastSync),
|
|
223
|
+
Math.round(gfHourlyLastSync),
|
|
224
|
+
normalizedBaseUrl,
|
|
225
|
+
authToken,
|
|
226
|
+
onSuccess = { message ->
|
|
227
|
+
isSyncInProgress = false
|
|
228
|
+
Timber.d("mytag: syncDataWithServer() completed. $message")
|
|
229
|
+
},
|
|
230
|
+
onFailure = { reason ->
|
|
231
|
+
isSyncInProgress = false
|
|
232
|
+
syncDataWithServer = false
|
|
233
|
+
Timber.d("mytag: syncDataWithServer() failed. $reason")
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
syncDataWithServer = true
|
|
237
|
+
promise?.resolve("Health Data Sync Started")
|
|
238
|
+
} else {
|
|
239
|
+
promise?.resolve("Health Data Already Synced")
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@ReactMethod
|
|
246
|
+
fun openHraLink(link: String?) {
|
|
247
|
+
try {
|
|
248
|
+
val i = Intent(Intent.ACTION_VIEW)
|
|
249
|
+
i.setData(Uri.parse(link))
|
|
250
|
+
currentActivityOrCached()?.startActivity(i)
|
|
251
|
+
} catch (e: Exception) {
|
|
252
|
+
e.printStackTrace()
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@ReactMethod
|
|
257
|
+
fun fetchDailyFitnessData(timestamp: Double, promise: Promise?) {
|
|
258
|
+
this.promise = promise
|
|
259
|
+
// TODO: to be implemented in the future.
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@ReactMethod
|
|
263
|
+
fun fetchHourlyFitnessData(timestamp: Double, promise: Promise?) {
|
|
264
|
+
this.promise = promise
|
|
265
|
+
// TODO: to be implemented in the future.
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
@ReactMethod
|
|
269
|
+
fun openHealthConnectApp(promise: Promise?) {
|
|
270
|
+
this.promise = promise
|
|
271
|
+
healthConnectUtil?.openHealthConnectApp();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
override fun getName(): String {
|
|
275
|
+
return "VisitFitnessModule"
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
override fun loadVisitWebViewGraphData(webUrl: String) {
|
|
279
|
+
Handler(Looper.getMainLooper()).post {
|
|
280
|
+
if (isLoggingEnabled) {
|
|
281
|
+
Log.d("mytag", "loadVisitWebViewGraphData: $webUrl")
|
|
282
|
+
}
|
|
283
|
+
dataRetrivalPromise!!.resolve(webUrl)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
override fun requestPermission() {
|
|
289
|
+
Timber.d("requestPermission called 218")
|
|
290
|
+
Handler(Looper.getMainLooper()).post {
|
|
291
|
+
val activity = currentActivityOrCached()
|
|
292
|
+
val healthConnectUtil = healthConnectUtil
|
|
293
|
+
|
|
294
|
+
if (activity == null || healthConnectUtil == null) {
|
|
295
|
+
Timber.d(
|
|
296
|
+
"requestPermission skipped. activityReady=%s, healthConnectUtilReady=%s",
|
|
297
|
+
activity != null,
|
|
298
|
+
healthConnectUtil != null
|
|
299
|
+
)
|
|
300
|
+
userDeniedHealthConnectPermission()
|
|
301
|
+
return@post
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
val launcher = getOrCreatePermissionLauncher(activity)
|
|
305
|
+
if (launcher == null) {
|
|
306
|
+
val exception = IllegalStateException(
|
|
307
|
+
"Current activity must implement ActivityResultRegistryOwner to request Health Connect permissions"
|
|
308
|
+
)
|
|
309
|
+
Timber.e(exception, "requestPermission failed")
|
|
310
|
+
logHealthConnectError(exception)
|
|
311
|
+
userDeniedHealthConnectPermission()
|
|
312
|
+
return@post
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
try {
|
|
316
|
+
launcher.launch(healthConnectUtil.PERMISSIONS)
|
|
317
|
+
} catch (exception: Exception) {
|
|
318
|
+
Timber.e(exception, "requestPermission failed")
|
|
319
|
+
logHealthConnectError(exception)
|
|
320
|
+
userDeniedHealthConnectPermission()
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
override fun updateHealthConnectConnectionStatus(
|
|
326
|
+
status: HealthConnectConnectionState, text: String
|
|
327
|
+
) {
|
|
328
|
+
Timber.d("updateHealthConnectConnectionStatus: %s %s", status, text)
|
|
329
|
+
|
|
330
|
+
when (status) {
|
|
331
|
+
CONNECTED -> {}
|
|
332
|
+
NOT_SUPPORTED -> {}
|
|
333
|
+
NOT_INSTALLED -> {}
|
|
334
|
+
INSTALLED -> {}
|
|
335
|
+
NONE -> {}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
override fun logHealthConnectError(throwable: Throwable) {
|
|
340
|
+
//pass it via a callback.
|
|
341
|
+
throwable.message?.let {
|
|
342
|
+
val formattedMessage = "${throwable.javaClass}: ${throwable.message}"
|
|
343
|
+
Timber.d("mytag: logHealthConnectError= $formattedMessage")
|
|
344
|
+
|
|
345
|
+
sendMessageToReactNative(formattedMessage)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
private fun sendMessageToReactNative(message: String) {
|
|
350
|
+
Timber.d("mytag: sendMessageToReactNative called()")
|
|
351
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
352
|
+
.emit("onMessage", message) // "onMessage" is the event name
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
@ReactMethod
|
|
357
|
+
fun getTodayStepCount(promise: Promise?) {
|
|
358
|
+
healthConnectUtil?.let { healthConnectUtil ->
|
|
359
|
+
healthConnectUtil.scope.launch {
|
|
360
|
+
try {
|
|
361
|
+
val stepsCount = healthConnectUtil.getTodayStepData()
|
|
362
|
+
promise?.resolve(stepsCount.toInt())
|
|
363
|
+
} catch (e: Exception) {
|
|
364
|
+
promise?.reject(e)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
@ReactMethod
|
|
371
|
+
fun getTodaySleepMinutes(promise: Promise?) {
|
|
372
|
+
healthConnectUtil?.let { healthConnectUtil ->
|
|
373
|
+
healthConnectUtil.scope.launch {
|
|
374
|
+
try {
|
|
375
|
+
val sleepMinutes = healthConnectUtil.getTodaySleepData()
|
|
376
|
+
promise?.resolve(sleepMinutes.toInt())
|
|
377
|
+
} catch (e: Exception) {
|
|
378
|
+
promise?.reject(e)
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
@ReactMethod
|
|
385
|
+
fun getTodayCalorieCount(promise: Promise?) {
|
|
386
|
+
healthConnectUtil?.let { healthConnectUtil ->
|
|
387
|
+
healthConnectUtil.scope.launch {
|
|
388
|
+
try {
|
|
389
|
+
val calorieCount = healthConnectUtil.getTodayCalorieData()
|
|
390
|
+
promise?.resolve(calorieCount.toInt())
|
|
391
|
+
} catch (e: Exception) {
|
|
392
|
+
promise?.reject(e)
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
@ReactMethod
|
|
400
|
+
fun triggerManualSync(promise: Promise?) {
|
|
401
|
+
|
|
402
|
+
val manualSyncStartedAt = System.currentTimeMillis()
|
|
403
|
+
|
|
404
|
+
Timber.d(
|
|
405
|
+
"mytag: triggerManualSync() called. storageInitialized=%s, healthConnectUtilReady=%s, visitStepSyncHelperReady=%s, isSyncInProgress=%s",
|
|
406
|
+
::visitSessionStorage.isInitialized,
|
|
407
|
+
healthConnectUtil != null,
|
|
408
|
+
visitStepSyncHelper != null,
|
|
409
|
+
isSyncInProgress
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
if (!::visitSessionStorage.isInitialized) {
|
|
413
|
+
Timber.d(
|
|
414
|
+
"mytag: triggerManualSync() rejected. code=SDK_NOT_INITIALIZED, reason=visitSessionStorage not initialized, elapsedMs=%s",
|
|
415
|
+
System.currentTimeMillis() - manualSyncStartedAt
|
|
416
|
+
)
|
|
417
|
+
rejectPromiseOnMainThread(promise, "SDK_NOT_INITIALIZED", "Health SDK is not initialized")
|
|
418
|
+
return
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
val healthConnectUtil = healthConnectUtil
|
|
422
|
+
val visitStepSyncHelper = visitStepSyncHelper
|
|
423
|
+
|
|
424
|
+
if (healthConnectUtil == null || visitStepSyncHelper == null) {
|
|
425
|
+
Timber.d(
|
|
426
|
+
"mytag: triggerManualSync() rejected. code=SDK_NOT_INITIALIZED, healthConnectUtilReady=%s, visitStepSyncHelperReady=%s, elapsedMs=%s",
|
|
427
|
+
healthConnectUtil != null,
|
|
428
|
+
visitStepSyncHelper != null,
|
|
429
|
+
System.currentTimeMillis() - manualSyncStartedAt
|
|
430
|
+
)
|
|
431
|
+
rejectPromiseOnMainThread(promise, "SDK_NOT_INITIALIZED", "Health SDK is not initialized")
|
|
432
|
+
return
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (isSyncInProgress) {
|
|
436
|
+
Timber.d(
|
|
437
|
+
"mytag: triggerManualSync() rejected. code=SYNC_IN_PROGRESS, elapsedMs=%s",
|
|
438
|
+
System.currentTimeMillis() - manualSyncStartedAt
|
|
439
|
+
)
|
|
440
|
+
rejectPromiseOnMainThread(
|
|
441
|
+
promise,
|
|
442
|
+
"SYNC_IN_PROGRESS",
|
|
443
|
+
"Health data sync is already in progress"
|
|
444
|
+
)
|
|
445
|
+
return
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
val baseUrl = visitSessionStorage.getBaseURL()
|
|
449
|
+
val authToken = visitSessionStorage.getVisitAuthToken()
|
|
450
|
+
val dailyLastSyncTimeStamp = visitSessionStorage.getDailyLastSyncTimestamp()
|
|
451
|
+
val hourlyLastSyncTimestamp = visitSessionStorage.getHourlyLastSyncTimeStamp()
|
|
452
|
+
|
|
453
|
+
Timber.d(
|
|
454
|
+
"mytag: triggerManualSync() sync inputs loaded. baseUrl=%s, authTokenPresent=%s, dailyLastSyncTimeStamp=%s, hourlyLastSyncTimestamp=%s",
|
|
455
|
+
baseUrl,
|
|
456
|
+
!authToken.isNullOrBlank(),
|
|
457
|
+
dailyLastSyncTimeStamp,
|
|
458
|
+
hourlyLastSyncTimestamp
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
if (baseUrl.isNullOrBlank() || authToken.isNullOrBlank()) {
|
|
462
|
+
Timber.d(
|
|
463
|
+
"mytag: triggerManualSync() rejected. code=MISSING_SYNC_CREDENTIALS, baseUrlPresent=%s, authTokenPresent=%s, elapsedMs=%s",
|
|
464
|
+
!baseUrl.isNullOrBlank(),
|
|
465
|
+
!authToken.isNullOrBlank(),
|
|
466
|
+
System.currentTimeMillis() - manualSyncStartedAt
|
|
467
|
+
)
|
|
468
|
+
rejectPromiseOnMainThread(
|
|
469
|
+
promise,
|
|
470
|
+
"MISSING_SYNC_CREDENTIALS",
|
|
471
|
+
"Visit sync base URL or auth token is missing"
|
|
472
|
+
)
|
|
473
|
+
return
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (dailyLastSyncTimeStamp < 0 || hourlyLastSyncTimestamp < 0) {
|
|
477
|
+
Timber.d(
|
|
478
|
+
"mytag: triggerManualSync() rejected. code=MISSING_SYNC_TIMESTAMPS, dailyLastSyncTimeStamp=%s, hourlyLastSyncTimestamp=%s, elapsedMs=%s",
|
|
479
|
+
dailyLastSyncTimeStamp,
|
|
480
|
+
hourlyLastSyncTimestamp,
|
|
481
|
+
System.currentTimeMillis() - manualSyncStartedAt
|
|
482
|
+
)
|
|
483
|
+
rejectPromiseOnMainThread(
|
|
484
|
+
promise,
|
|
485
|
+
"MISSING_SYNC_TIMESTAMPS",
|
|
486
|
+
"Visit sync timestamps are missing"
|
|
487
|
+
)
|
|
488
|
+
return
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
Timber.d(
|
|
492
|
+
"mytag: triggerManualSync() dispatching sendDataToVisitServer. baseUrl=%s, dailyLastSyncTimeStamp=%s, hourlyLastSyncTimestamp=%s",
|
|
493
|
+
baseUrl,
|
|
494
|
+
dailyLastSyncTimeStamp,
|
|
495
|
+
hourlyLastSyncTimestamp
|
|
496
|
+
)
|
|
497
|
+
isSyncInProgress = true
|
|
498
|
+
visitStepSyncHelper.sendDataToVisitServer(
|
|
499
|
+
healthConnectUtil = healthConnectUtil,
|
|
500
|
+
googleFitLastSync = dailyLastSyncTimeStamp,
|
|
501
|
+
gfHourlyLastSync = hourlyLastSyncTimestamp,
|
|
502
|
+
visitBaseUrl = baseUrl,
|
|
503
|
+
visitAuthToken = authToken,
|
|
504
|
+
onSuccess = { message ->
|
|
505
|
+
isSyncInProgress = false
|
|
506
|
+
Timber.d(
|
|
507
|
+
"mytag: triggerManualSync() succeeded. elapsedMs=%s, message=%s",
|
|
508
|
+
System.currentTimeMillis() - manualSyncStartedAt,
|
|
509
|
+
message
|
|
510
|
+
)
|
|
511
|
+
resolvePromiseOnMainThread(promise, message)
|
|
512
|
+
},
|
|
513
|
+
onFailure = { reason ->
|
|
514
|
+
isSyncInProgress = false
|
|
515
|
+
Timber.d(
|
|
516
|
+
"mytag: triggerManualSync() failed. elapsedMs=%s, reason=%s",
|
|
517
|
+
System.currentTimeMillis() - manualSyncStartedAt,
|
|
518
|
+
reason
|
|
519
|
+
)
|
|
520
|
+
rejectPromiseOnMainThread(promise, "SYNC_FAILED", reason)
|
|
521
|
+
}
|
|
522
|
+
)
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
private fun normalizeBaseUrl(baseUrl: String): String {
|
|
526
|
+
val trimmedBaseUrl = baseUrl.trim()
|
|
527
|
+
return if (trimmedBaseUrl.endsWith("/")) trimmedBaseUrl else "$trimmedBaseUrl/"
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
private fun resolvePromiseOnMainThread(promise: Promise?, value: String) {
|
|
531
|
+
Handler(Looper.getMainLooper()).post {
|
|
532
|
+
promise?.resolve(value)
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
private fun rejectPromiseOnMainThread(promise: Promise?, code: String, message: String) {
|
|
537
|
+
Handler(Looper.getMainLooper()).post {
|
|
538
|
+
promise?.reject(code, message)
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
private fun handlePermissionResult(granted: Set<String>?) {
|
|
543
|
+
Timber.d("handlePermissionResult: result: %s", granted)
|
|
544
|
+
|
|
545
|
+
val healthConnectUtil = healthConnectUtil
|
|
546
|
+
if (granted == null || healthConnectUtil == null) {
|
|
547
|
+
Timber.d("Lack of required permissions")
|
|
548
|
+
healthConnectUtil?.checkPermissionsAndRunForStar(true)
|
|
549
|
+
return
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (granted.containsAll(healthConnectUtil.PERMISSIONS)) {
|
|
553
|
+
previouslyRevoked = false
|
|
554
|
+
Timber.d("Permissions successfully granted")
|
|
555
|
+
} else {
|
|
556
|
+
Timber.d("Lack of required permissions")
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
healthConnectUtil.checkPermissionsAndRunForStar(true)
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
private fun getOrCreatePermissionLauncher(
|
|
563
|
+
activity: Activity
|
|
564
|
+
): ActivityResultLauncher<Set<String>>? {
|
|
565
|
+
val existingLauncher = requestPermissionsLauncher
|
|
566
|
+
if (existingLauncher != null && requestPermissionsLauncherActivity === activity) {
|
|
567
|
+
return existingLauncher
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
val registryOwner = activity as? ActivityResultRegistryOwner ?: return null
|
|
571
|
+
requestPermissionsLauncher?.unregister()
|
|
572
|
+
|
|
573
|
+
requestPermissionsLauncher =
|
|
574
|
+
registryOwner.activityResultRegistry.register(
|
|
575
|
+
"visit-rn-sdk-health-connect-permissions-${System.identityHashCode(this)}",
|
|
576
|
+
requestPermissionActivityContract
|
|
577
|
+
) { granted ->
|
|
578
|
+
handlePermissionResult(granted)
|
|
579
|
+
}
|
|
580
|
+
requestPermissionsLauncherActivity = activity
|
|
581
|
+
|
|
582
|
+
return requestPermissionsLauncher
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
private fun currentActivityOrCached(): Activity? {
|
|
586
|
+
val activity = reactApplicationContext.currentActivity
|
|
587
|
+
if (activity != null) {
|
|
588
|
+
mainActivity = activity
|
|
589
|
+
}
|
|
590
|
+
return activity ?: mainActivity
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
private fun configureTimber(loggingEnabled: Boolean) {
|
|
594
|
+
if (loggingEnabled && Timber.forest().isEmpty()) {
|
|
595
|
+
Timber.plant(Timber.DebugTree())
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
override fun invalidate() {
|
|
600
|
+
requestPermissionsLauncher?.unregister()
|
|
601
|
+
requestPermissionsLauncher = null
|
|
602
|
+
requestPermissionsLauncherActivity = null
|
|
603
|
+
super.invalidate()
|
|
604
|
+
}
|
|
605
|
+
}
|
|
@@ -8,7 +8,7 @@ import com.facebook.react.uimanager.ViewManager
|
|
|
8
8
|
|
|
9
9
|
class VisitRnSdkPackage : ReactPackage {
|
|
10
10
|
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
-
return
|
|
11
|
+
return listOf(VisitFitnessModule(reactContext))
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package com.visitrnsdk
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.SharedPreferences
|
|
5
|
+
|
|
6
|
+
class VisitSessionStorage(context: Context) {
|
|
7
|
+
|
|
8
|
+
private val BASE_URL = "baseURL"
|
|
9
|
+
private val DAILY_LAST_SYNC = "dailyLastSync"
|
|
10
|
+
private val HOURLY_LAST_SYNC = "hourlyLastSync"
|
|
11
|
+
private val VISIT_AUTH_TOKEN = "visitAuthToken"
|
|
12
|
+
|
|
13
|
+
private val sharedPreferences: SharedPreferences =
|
|
14
|
+
context.getSharedPreferences("VisitSharedPref", Context.MODE_PRIVATE)
|
|
15
|
+
|
|
16
|
+
fun saveBaseUrl(value: String) {
|
|
17
|
+
sharedPreferences.edit().putString(BASE_URL, value).apply()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fun getBaseURL(): String? {
|
|
21
|
+
return sharedPreferences.getString(BASE_URL, null)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
fun saveDailyLastSyncTimeStamp(value: Long) {
|
|
26
|
+
sharedPreferences.edit().putLong(DAILY_LAST_SYNC, value).apply()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
fun getDailyLastSyncTimestamp(): Long {
|
|
31
|
+
return sharedPreferences.getLong(DAILY_LAST_SYNC, -1L)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fun saveHourlyLastSyncTimeStamp(value: Long) {
|
|
35
|
+
sharedPreferences.edit().putLong(HOURLY_LAST_SYNC, value).apply()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
fun getHourlyLastSyncTimeStamp(): Long {
|
|
40
|
+
return sharedPreferences.getLong(HOURLY_LAST_SYNC, -1L)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fun saveVisitAuthToken(value: String) {
|
|
44
|
+
sharedPreferences.edit().putString(VISIT_AUTH_TOKEN, value).apply()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun getVisitAuthToken(): String? {
|
|
48
|
+
return sharedPreferences.getString(VISIT_AUTH_TOKEN, null)
|
|
49
|
+
}
|
|
50
|
+
}
|