react-native-health-connect 4.1.4 → 4.1.5
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
CHANGED
|
@@ -93,6 +93,8 @@ dependencies {
|
|
|
93
93
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
94
94
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
|
|
95
95
|
implementation "androidx.health.connect:connect-client:1.1.0"
|
|
96
|
+
|
|
97
|
+
testImplementation "junit:junit:4.13.2"
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
if (isNewArchitectureEnabled()) {
|
package/android/src/main/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecord.kt
CHANGED
|
@@ -29,9 +29,9 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl<ExerciseSessionRecord>
|
|
|
29
29
|
time = Instant.parse(sample.getString("time")),
|
|
30
30
|
latitude = sample.getDouble("latitude"),
|
|
31
31
|
longitude = sample.getDouble("longitude"),
|
|
32
|
-
horizontalAccuracy =
|
|
33
|
-
verticalAccuracy =
|
|
34
|
-
altitude =
|
|
32
|
+
horizontalAccuracy = sample.getMap("horizontalAccuracy")?.let { getLengthFromJsMap(it) },
|
|
33
|
+
verticalAccuracy = sample.getMap("verticalAccuracy")?.let { getLengthFromJsMap(it) },
|
|
34
|
+
altitude = sample.getMap("altitude")?.let { getLengthFromJsMap(it) },
|
|
35
35
|
)
|
|
36
36
|
} ?: emptyList()
|
|
37
37
|
|
|
@@ -203,9 +203,9 @@ class ReactExerciseSessionRecord : ReactHealthRecordImpl<ExerciseSessionRecord>
|
|
|
203
203
|
map.putString("time", it.time.toString())
|
|
204
204
|
map.putDouble("latitude", it.latitude)
|
|
205
205
|
map.putDouble("longitude", it.longitude)
|
|
206
|
-
map.putMap("horizontalAccuracy", lengthToJsMap(
|
|
207
|
-
map.putMap("verticalAccuracy", lengthToJsMap(
|
|
208
|
-
map.putMap("altitude", lengthToJsMap(
|
|
206
|
+
it.horizontalAccuracy?.let { length -> map.putMap("horizontalAccuracy", lengthToJsMap(length)) }
|
|
207
|
+
it.verticalAccuracy?.let { length -> map.putMap("verticalAccuracy", lengthToJsMap(length)) }
|
|
208
|
+
it.altitude?.let { length -> map.putMap("altitude", lengthToJsMap(length)) }
|
|
209
209
|
this.pushMap(map)
|
|
210
210
|
}
|
|
211
211
|
}
|
package/android/src/test/java/dev/matinzd/healthconnect/records/ReactExerciseSessionRecordTest.kt
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package dev.matinzd.healthconnect.records
|
|
2
|
+
|
|
3
|
+
import androidx.health.connect.client.records.ExerciseRouteResult
|
|
4
|
+
import com.facebook.react.bridge.JavaOnlyArray
|
|
5
|
+
import com.facebook.react.bridge.JavaOnlyMap
|
|
6
|
+
import org.junit.Assert.assertEquals
|
|
7
|
+
import org.junit.Assert.assertNull
|
|
8
|
+
import org.junit.Test
|
|
9
|
+
|
|
10
|
+
class ReactExerciseSessionRecordTest {
|
|
11
|
+
@Test
|
|
12
|
+
fun parseWriteRecordAcceptsRoutePointWithoutAccuracy() {
|
|
13
|
+
val point = JavaOnlyMap.of(
|
|
14
|
+
"time", "2026-01-01T00:00:00Z",
|
|
15
|
+
"latitude", 37.78,
|
|
16
|
+
"longitude", -122.4,
|
|
17
|
+
"altitude", JavaOnlyMap.of("value", 12.5, "unit", "meters"),
|
|
18
|
+
)
|
|
19
|
+
val pointWithoutAltitude = JavaOnlyMap.of(
|
|
20
|
+
"time", "2026-01-01T00:01:00Z",
|
|
21
|
+
"latitude", 37.79,
|
|
22
|
+
"longitude", -122.41,
|
|
23
|
+
)
|
|
24
|
+
val record = JavaOnlyMap.of(
|
|
25
|
+
"startTime", "2026-01-01T00:00:00Z",
|
|
26
|
+
"endTime", "2026-01-01T00:10:00Z",
|
|
27
|
+
"exerciseRoute", JavaOnlyMap.of("route", JavaOnlyArray.of(point, pointWithoutAltitude)),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
val parsed = ReactExerciseSessionRecord().parseWriteRecord(JavaOnlyArray.of(record)).single()
|
|
31
|
+
val route = (parsed.exerciseRouteResult as ExerciseRouteResult.Data).exerciseRoute.route
|
|
32
|
+
|
|
33
|
+
assertEquals(2, route.size)
|
|
34
|
+
assertEquals(12.5, route[0].altitude!!.inMeters, 0.0)
|
|
35
|
+
assertNull(route[0].horizontalAccuracy)
|
|
36
|
+
assertNull(route[0].verticalAccuracy)
|
|
37
|
+
assertNull(route[1].altitude)
|
|
38
|
+
assertNull(route[1].horizontalAccuracy)
|
|
39
|
+
assertNull(route[1].verticalAccuracy)
|
|
40
|
+
}
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-health-connect",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.5",
|
|
4
4
|
"description": "React native library for health connect (Android only)",
|
|
5
5
|
"funding": "https://github.com/matinzd/react-native-health-connect?sponsor=1",
|
|
6
6
|
"main": "lib/commonjs/index",
|