From ffb5c7e7cef028e7631994a99bf3ee871b831c42 Mon Sep 17 00:00:00 2001 From: Vishnu Ravi Date: Sun, 26 Mar 2023 20:03:35 -0400 Subject: [PATCH] Migrate to Health Connect 1.0.0-alpha11 (#101) --- app/src/main/AndroidManifest.xml | 18 ++++++++++-------- .../cardinalkit/presentation/MainActivity.kt | 2 +- .../presentation/health/HealthViewModel.kt | 4 ++-- .../services/HealthConnectManager.kt | 17 ++++++++++------- app/src/main/res/values/health_permissions.xml | 9 --------- build.gradle | 9 ++++----- 6 files changed, 27 insertions(+), 32 deletions(-) delete mode 100644 app/src/main/res/values/health_permissions.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f14d1cb..ce7a782 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,11 @@ - + + + + + - - - - - + + + + + \ No newline at end of file diff --git a/app/src/main/java/edu/stanford/cardinalkit/presentation/MainActivity.kt b/app/src/main/java/edu/stanford/cardinalkit/presentation/MainActivity.kt index f9f4e52..a85b0d8 100644 --- a/app/src/main/java/edu/stanford/cardinalkit/presentation/MainActivity.kt +++ b/app/src/main/java/edu/stanford/cardinalkit/presentation/MainActivity.kt @@ -57,7 +57,7 @@ class MainActivity : AppCompatActivity() { .healthConnectManager .healthConnectClient .permissionController - .getGrantedPermissions(permissions) + .getGrantedPermissions() if (!granted.containsAll(permissions)) { requestPermissions.launch(permissions) } else { diff --git a/app/src/main/java/edu/stanford/cardinalkit/presentation/health/HealthViewModel.kt b/app/src/main/java/edu/stanford/cardinalkit/presentation/health/HealthViewModel.kt index 34b0c0b..81a6092 100644 --- a/app/src/main/java/edu/stanford/cardinalkit/presentation/health/HealthViewModel.kt +++ b/app/src/main/java/edu/stanford/cardinalkit/presentation/health/HealthViewModel.kt @@ -29,8 +29,8 @@ class HealthViewModel @Inject constructor( private var permissionsGranted = mutableStateOf(false) val permissions = setOf( - HealthPermission.createReadPermission(StepsRecord::class), - HealthPermission.createReadPermission(WeightRecord::class) + HealthPermission.getReadPermission(StepsRecord::class), + HealthPermission.getReadPermission(WeightRecord::class) ) init { diff --git a/app/src/main/java/edu/stanford/cardinalkit/services/HealthConnectManager.kt b/app/src/main/java/edu/stanford/cardinalkit/services/HealthConnectManager.kt index 9ad7cbe..230bdff 100644 --- a/app/src/main/java/edu/stanford/cardinalkit/services/HealthConnectManager.kt +++ b/app/src/main/java/edu/stanford/cardinalkit/services/HealthConnectManager.kt @@ -4,7 +4,6 @@ import android.content.Context import androidx.compose.runtime.mutableStateOf import androidx.health.connect.client.HealthConnectClient import androidx.health.connect.client.aggregate.AggregationResult -import androidx.health.connect.client.permission.HealthPermission import androidx.health.connect.client.records.HeartRateRecord import androidx.health.connect.client.records.StepsRecord import androidx.health.connect.client.records.WeightRecord @@ -20,19 +19,23 @@ class HealthConnectManager @Inject constructor( ) { val healthConnectClient by lazy { HealthConnectClient.getOrCreate(context) } - var isAvailable = mutableStateOf(false); private set + var isAvailable = mutableStateOf(false) + private set init { - isAvailable.value = HealthConnectClient.isAvailable(context) + isAvailable.value = checkAvailabilityStatus() + } + + fun checkAvailabilityStatus(): Boolean { + val availabilityStatus = HealthConnectClient.sdkStatus(context, "com.google.android.apps.healthdata") + return availabilityStatus == HealthConnectClient.SDK_AVAILABLE } /** * Determines if all requested permissions are granted. */ - suspend fun hasAllPermissions(permissions: Set): Boolean { - return permissions == healthConnectClient.permissionController.getGrantedPermissions( - permissions - ) + suspend fun hasAllPermissions(permissions: Set): Boolean { + return healthConnectClient.permissionController.getGrantedPermissions().containsAll(permissions) } /** diff --git a/app/src/main/res/values/health_permissions.xml b/app/src/main/res/values/health_permissions.xml deleted file mode 100644 index 8a3b752..0000000 --- a/app/src/main/res/values/health_permissions.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - androidx.health.permission.Steps.READ - androidx.health.permission.HeartRate.READ - androidx.health.permission.TotalCaloriesBurned.READ - androidx.health.permission.Weight.READ - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index d42d6e5..2d9b4f2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,21 @@ buildscript { ext { gradle_version = '7.2.2' - kotlin_version = "1.7.20" + kotlin_version = "1.8.0" google_services_version = "4.3.10" hilt_version = "2.43.2" core_version = "1.8.0" appcompat_version = "1.5.0" live_data_version = "2.5.1" - material_version = "1.6.1" - compose_version = "1.3.2" - compose_bom_version = "2022.10.00" + compose_version = "1.4.1" + compose_bom_version = "2023.03.00" hilt_navigation_compose_version = "1.0.0" firebase_bom_version = "30.1.0" play_services_version = "1.6.2" play_services_auth_version = "20.3.0" accompanist_version = "0.24.10-beta" coil_compose_version = "2.1.0" - health_connect_version = '1.0.0-alpha07' + health_connect_version = '1.0.0-alpha11' android_fhir_version = '1.0.0' spotless_version = '6.10.0' }