Add health connect snippets#915
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds several helper functions to the HealthConnectManager class for managing permissions and inserting various Health Connect records. The review identified several issues: an empty conditional block for permission checks, incorrect property usage in the PlannedExerciseSessionRecord constructor, unused function parameters, and typos in function names. Addressing these will improve code correctness, cleanliness, and maintainability.
| if (!granted.containsAll(permissions)) { | ||
| // Check if required permissions are not granted, and return | ||
| } |
There was a problem hiding this comment.
The if block is empty, meaning the function does not actually return or handle the case where permissions are missing, despite the comment. This could lead to unexpected behavior if the caller assumes the permissions were verified.
| if (!granted.containsAll(permissions)) { | |
| // Check if required permissions are not granted, and return | |
| } | |
| if (!granted.containsAll(permissions)) { | |
| return emptySet() | |
| } |
| startDate = plannedStartDate, | ||
| duration = plannedDuration, |
| suspend fun createSetOfPermissionSleep( | ||
| healthConnectClient: HealthConnectClient, | ||
| record: StepsRecord | ||
| ): Set<String> { |
There was a problem hiding this comment.
The parameters healthConnectClient and record are unused in this function. Additionally, healthConnectClient is already available as a property of the HealthConnectManager class, making it redundant to pass as a parameter. The record parameter (of type StepsRecord) also seems misplaced in a function related to sleep permissions.
suspend fun createSetOfPermissionSleep(): Set<String> {| return permissions | ||
| } | ||
|
|
||
| suspend fun createPermissionExcerciseSession(): Set<String> { |
| return permissions | ||
| } | ||
|
|
||
| suspend fun checkPermissionPlannedExceriseSession() { |
| suspend fun insertRecords( | ||
| healthConnectClient: HealthConnectClient, | ||
| record: ExerciseSessionRecord, | ||
| startTime: Instant | ||
| ){ |
| } | ||
|
|
||
| @SuppressLint("RestrictedApi") | ||
| suspend fun insertSegmentExerciseSession(startTime: Instant, endTime: Instant, insertedPlannedExerciseSessionId: String) { |
There was a problem hiding this comment.
The parameters startTime and endTime are unused. The function calculates sessionStartTime and sessionEndTime internally using Instant.now() and a fixed duration.
| suspend fun insertSegmentExerciseSession(startTime: Instant, endTime: Instant, insertedPlannedExerciseSessionId: String) { | |
| suspend fun insertSegmentExerciseSession(insertedPlannedExerciseSessionId: String) { |
yrezgui
left a comment
There was a problem hiding this comment.
You need to apply spotless
| } | ||
| } | ||
|
|
||
| suspend fun createSetOfPermissionSleep( |
There was a problem hiding this comment.
| suspend fun createSetOfPermissionSleep( | |
| fun createSetOfPermissionSleep( |
| return permissions | ||
| } | ||
|
|
||
| suspend fun createSetOfPermissionVitals( |
There was a problem hiding this comment.
| suspend fun createSetOfPermissionVitals( | |
| fun createSetOfPermissionVitals( |
| return permissions | ||
| } | ||
|
|
||
| suspend fun createSetOfPermissionWorkout( |
There was a problem hiding this comment.
| suspend fun createSetOfPermissionWorkout( | |
| fun createSetOfPermissionWorkout( |
| return permissions | ||
| } | ||
|
|
||
| suspend fun createSetOfPermissionGetStarted( |
There was a problem hiding this comment.
| suspend fun createSetOfPermissionGetStarted( | |
| fun createSetOfPermissionGetStarted( |
| return permissions | ||
| } | ||
|
|
||
| suspend fun createPermissionStep( |
There was a problem hiding this comment.
| suspend fun createPermissionStep( | |
| fun createPermissionStep( |
|
|
||
| suspend fun createSetOfPermissionWorkout( | ||
| healthConnectClient: HealthConnectClient, | ||
| record: StepsRecord |
| healthConnectClient: HealthConnectClient, | ||
| record: StepsRecord |
| healthConnectClient: HealthConnectClient, | ||
| record: StepsRecord |
| // [END android_healthconnect_check_permission_planned_excerise_session] | ||
| } | ||
|
|
||
| @SuppressLint("RestrictedApi") |
| // [END android_healthconnect_write_exercise_route] | ||
| } | ||
|
|
||
| @SuppressLint("RestrictedApi") |
Add snippets for Health Connect site