react-native-health-connect 0.1.0-alpha.1 → 0.1.0-alpha.2

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.
@@ -85,7 +85,16 @@ dependencies {
85
85
  implementation "com.facebook.react:react-native"
86
86
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
87
87
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
88
- implementation "androidx.health.connect:connect-client:1.0.0-alpha09"
88
+ implementation "androidx.health.connect:connect-client:1.0.0-alpha10"
89
+
90
+ constraints {
91
+ implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
92
+ because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
93
+ }
94
+ implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
95
+ because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
96
+ }
97
+ }
89
98
  }
90
99
 
91
100
  if (isNewArchitectureEnabled()) {
@@ -4,7 +4,6 @@ import android.app.Activity
4
4
  import android.content.Intent
5
5
  import android.os.Bundle
6
6
  import androidx.health.connect.client.HealthConnectClient
7
- import androidx.health.connect.client.permission.HealthPermission
8
7
  import com.facebook.react.bridge.*
9
8
  import dev.matinzd.healthconnect.permissions.HCPermissionManager
10
9
  import dev.matinzd.healthconnect.records.ReactHealthRecord
@@ -17,7 +16,7 @@ class HealthConnectManager(private val context: ReactApplicationContext) : Activ
17
16
  private lateinit var healthConnectClient: HealthConnectClient
18
17
  private val coroutineScope = CoroutineScope(Dispatchers.IO)
19
18
  private var pendingPromise: Promise? = null
20
- private var latestPermissions: Set<HealthPermission>? = null
19
+ private var latestPermissions: Set<String>? = null
21
20
 
22
21
  private val isInitialized get() = this::healthConnectClient.isInitialized
23
22
 
@@ -17,7 +17,7 @@ class HCPermissionManager(providerPackageName: String) {
17
17
  companion object {
18
18
  private const val DEFAULT_PROVIDER_PACKAGE_NAME = "com.google.android.apps.healthdata"
19
19
 
20
- fun parsePermissions(reactPermissions: ReadableArray): Set<HealthPermission> {
20
+ fun parsePermissions(reactPermissions: ReadableArray): Set<String> {
21
21
  return reactPermissions.toArrayList().mapNotNull {
22
22
  it as HashMap<*, *>
23
23
  val recordType = it["recordType"]
@@ -25,8 +25,8 @@ class HCPermissionManager(providerPackageName: String) {
25
25
  ?: throw InvalidRecordType()
26
26
 
27
27
  when (it["accessType"]) {
28
- "write" -> HealthPermission.createWritePermission(recordClass)
29
- "read" -> HealthPermission.createReadPermission(recordClass)
28
+ "write" -> HealthPermission.getWritePermission(recordClass)
29
+ "read" -> HealthPermission.getReadPermission(recordClass)
30
30
  else -> null
31
31
  }
32
32
  }.toSet()
@@ -48,16 +48,27 @@ class HCPermissionManager(providerPackageName: String) {
48
48
  val grantedPermissions = WritableNativeArray().apply {
49
49
  result.forEach {
50
50
  val map = WritableNativeMap()
51
- // TODO: Find a way to properly parse permission result without suppression
52
- @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
53
- map.putString("recordType", it.recordType.simpleName)
54
- @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
55
- map.putInt("accessType", it.accessType)
51
+
52
+ val (accessType, recordType) = extractPermissionResult(it)
53
+
54
+ map.putString("recordType", snakeToCamel(recordType))
55
+ map.putString("accessType", accessType)
56
56
  pushMap(map)
57
57
  }
58
58
  }
59
59
 
60
60
  pendingPromise?.resolve(grantedPermissions)
61
61
  }
62
+
63
+ private fun extractPermissionResult(it: String): Pair<String, String> {
64
+ val accessType = it.substring(it.lastIndexOf(".") + 1, it.indexOf("_")).lowercase()
65
+ val recordType = it.substring(it.indexOf("_") + 1).lowercase()
66
+ return Pair(accessType, recordType)
67
+ }
68
+
69
+ private fun snakeToCamel(word: String): String {
70
+ val components = word.split("_")
71
+ return components.joinToString("") { it[0].uppercase() + it.substring(1) }
72
+ }
62
73
  }
63
74
  }
@@ -129,15 +129,11 @@ val reactRecordTypeToClassMap: Map<String, KClass<out Record>> = mapOf(
129
129
  "CyclingPedalingCadence" to CyclingPedalingCadenceRecord::class,
130
130
  "Distance" to DistanceRecord::class,
131
131
  "ElevationGained" to ElevationGainedRecord::class,
132
- "ExerciseEvent" to ExerciseEventRecord::class, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
133
- "ExerciseLap" to ExerciseLapRecord::class, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
134
- "ExerciseRepetitions" to ExerciseRepetitionsRecord::class, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
135
132
  "ExerciseSession" to ExerciseSessionRecord::class,
136
133
  "FloorsClimbed" to FloorsClimbedRecord::class,
137
134
  "HeartRate" to HeartRateRecord::class,
138
135
  "HeartRateVariabilityRmssd" to HeartRateVariabilityRmssdRecord::class,
139
136
  "Height" to HeightRecord::class,
140
- "HipCircumference" to HipCircumferenceRecord::class, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
141
137
  "Hydration" to HydrationRecord::class,
142
138
  "LeanBodyMass" to LeanBodyMassRecord::class,
143
139
  "MenstruationFlow" to MenstruationFlowRecord::class,
@@ -153,10 +149,8 @@ val reactRecordTypeToClassMap: Map<String, KClass<out Record>> = mapOf(
153
149
  "Speed" to SpeedRecord::class,
154
150
  "StepsCadence" to StepsCadenceRecord::class,
155
151
  "Steps" to StepsRecord::class,
156
- "SwimmingStrokes" to SwimmingStrokesRecord::class, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
157
152
  "TotalCaloriesBurned" to TotalCaloriesBurnedRecord::class,
158
153
  "Vo2Max" to Vo2MaxRecord::class,
159
- "WaistCircumference" to WaistCircumferenceRecord::class, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
160
154
  "Weight" to WeightRecord::class,
161
155
  "WheelchairPushes" to WheelchairPushesRecord::class,
162
156
  "IntermenstrualBleeding" to IntermenstrualBleedingRecord::class,
@@ -178,15 +172,11 @@ val reactRecordTypeToReactClassMap: Map<String, Class<out ReactHealthRecordImpl<
178
172
  "CyclingPedalingCadence" to ReactCyclingPedalingCadenceRecord::class.java,
179
173
  "Distance" to ReactDistanceRecord::class.java,
180
174
  "ElevationGained" to ReactElevationGainedRecord::class.java,
181
- // "ExerciseEvent" to ExerciseEventRecord::class.java, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
182
- // "ExerciseLap" to ExerciseLapRecord::class.java, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
183
- // "ExerciseRepetitions" to ExerciseRepetitionsRecord::class.java, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
184
175
  "ExerciseSession" to ReactExerciseSessionRecord::class.java,
185
176
  "FloorsClimbed" to ReactFloorsClimbedRecord::class.java,
186
177
  "HeartRate" to ReactHeartRateRecord::class.java,
187
178
  "HeartRateVariabilityRmssd" to ReactHeartRateVariabilityRmssdRecord::class.java,
188
179
  "Height" to ReactHeightRecord::class.java,
189
- // "HipCircumference" to ReactHipCircumferenceRecord::class.java, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
190
180
  "Hydration" to ReactHydrationRecord::class.java,
191
181
  "LeanBodyMass" to ReactLeanBodyMassRecord::class.java,
192
182
  "MenstruationFlow" to ReactMenstruationFlowRecord::class.java,
@@ -202,10 +192,8 @@ val reactRecordTypeToReactClassMap: Map<String, Class<out ReactHealthRecordImpl<
202
192
  "Speed" to ReactSpeedRecord::class.java,
203
193
  "StepsCadence" to ReactStepsCadenceRecord::class.java,
204
194
  "Steps" to ReactStepsRecord::class.java,
205
- // "SwimmingStrokes" to ReactSwimmingStrokesRecord::class.java, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
206
195
  "TotalCaloriesBurned" to ReactTotalCaloriesBurnedRecord::class.java,
207
196
  "Vo2Max" to ReactVo2MaxRecord::class.java,
208
- // "WaistCircumference" to ReactWaistCircumferenceRecord::class.java, //TODO: not registered in https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/Record
209
197
  "Weight" to ReactWeightRecord::class.java,
210
198
  "WheelchairPushes" to ReactWheelchairPushesRecord::class.java,
211
199
  "IntermenstrualBleeding" to ReactIntermenstrualBleedingRecord::class.java,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-health-connect",
3
- "version": "0.1.0-alpha.1",
4
- "description": "test",
3
+ "version": "0.1.0-alpha.2",
4
+ "description": "React native library for health connect (Android only)",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
7
7
  "types": "lib/typescript/index.d.ts",