diff --git a/README.md b/README.md index 636a451..1e583ef 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ The library supports: Note that for Android, the target phone **needs** to have ~~[Google Fit](https://www.google.com/fit/) or~~ [Health Connect](https://health.google/health-connect-android/) (which is currently in beta) installed and have access to the internet, otherwise this library will not work. ## Data Types -- STEPS -- WEIGHT +- Steps +- Weight ## Requesting permission diff --git a/core/src/androidMain/kotlin/com/vitoksmile/kmp/health/HealthConnectDataType.kt b/core/src/androidMain/kotlin/com/vitoksmile/kmp/health/HealthConnectDataType.kt index 086ac64..e319046 100644 --- a/core/src/androidMain/kotlin/com/vitoksmile/kmp/health/HealthConnectDataType.kt +++ b/core/src/androidMain/kotlin/com/vitoksmile/kmp/health/HealthConnectDataType.kt @@ -4,11 +4,14 @@ import androidx.health.connect.client.permission.HealthPermission import androidx.health.connect.client.records.Record import androidx.health.connect.client.records.StepsRecord import androidx.health.connect.client.records.WeightRecord +import com.vitoksmile.kmp.health.HealthDataType.Steps +import com.vitoksmile.kmp.health.HealthDataType.Weight import kotlin.reflect.KClass internal fun HealthDataType.toRecordType(): KClass = when (this) { - HealthDataType.STEPS -> StepsRecord::class - HealthDataType.WEIGHT -> WeightRecord::class + Steps -> StepsRecord::class + + Weight -> WeightRecord::class } /** diff --git a/core/src/commonMain/kotlin/com/vitoksmile/kmp/health/HealthDataType.kt b/core/src/commonMain/kotlin/com/vitoksmile/kmp/health/HealthDataType.kt index c3f5ce1..2a08fde 100644 --- a/core/src/commonMain/kotlin/com/vitoksmile/kmp/health/HealthDataType.kt +++ b/core/src/commonMain/kotlin/com/vitoksmile/kmp/health/HealthDataType.kt @@ -1,6 +1,7 @@ package com.vitoksmile.kmp.health -enum class HealthDataType { - STEPS, - WEIGHT, +sealed interface HealthDataType { + data object Steps : HealthDataType + + data object Weight : HealthDataType } \ No newline at end of file diff --git a/core/src/iosMain/kotlin/com/vitoksmile/kmp/health/HealthKitDataType.kt b/core/src/iosMain/kotlin/com/vitoksmile/kmp/health/HealthKitDataType.kt index 609b8c2..b0b2548 100644 --- a/core/src/iosMain/kotlin/com/vitoksmile/kmp/health/HealthKitDataType.kt +++ b/core/src/iosMain/kotlin/com/vitoksmile/kmp/health/HealthKitDataType.kt @@ -1,14 +1,16 @@ package com.vitoksmile.kmp.health +import com.vitoksmile.kmp.health.HealthDataType.Steps +import com.vitoksmile.kmp.health.HealthDataType.Weight import platform.HealthKit.HKQuantityType import platform.HealthKit.HKQuantityTypeIdentifierBodyMass import platform.HealthKit.HKQuantityTypeIdentifierStepCount import platform.HealthKit.HKSampleType internal fun HealthDataType.toHKSampleType(): HKSampleType? = when (this) { - HealthDataType.STEPS -> + Steps -> HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount) - HealthDataType.WEIGHT -> + Weight -> HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass) } \ No newline at end of file diff --git a/sample/src/commonMain/kotlin/com/vitoksmile/kmp/health/sample/SampleApp.kt b/sample/src/commonMain/kotlin/com/vitoksmile/kmp/health/sample/SampleApp.kt index 2f77a4a..b8e2574 100644 --- a/sample/src/commonMain/kotlin/com/vitoksmile/kmp/health/sample/SampleApp.kt +++ b/sample/src/commonMain/kotlin/com/vitoksmile/kmp/health/sample/SampleApp.kt @@ -28,6 +28,8 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import com.vitoksmile.kmp.health.HealthDataType +import com.vitoksmile.kmp.health.HealthDataType.Steps +import com.vitoksmile.kmp.health.HealthDataType.Weight import com.vitoksmile.kmp.health.HealthManagerFactory import com.vitoksmile.kmp.health.HealthRecord import com.vitoksmile.kmp.health.records.StepsRecord @@ -45,14 +47,14 @@ fun SampleApp() { val readTypes = remember { listOf( - HealthDataType.STEPS, - HealthDataType.WEIGHT, + Steps, + Weight, ) } val writeTypes = remember { listOf( - HealthDataType.STEPS, - HealthDataType.WEIGHT, + Steps, + Weight, ) }