When logging a drink (coffee, tea, etc.), the app already syncs the caffeine content to Health Connect as a NutritionRecord. This PR adds an HydrationRecord, so Health Connect also track the user's hydration.
Changes
AndroidManifest.xml — Declares the WRITE_HYDRATION permission required by Health Connect
HealthConnectManager.kt — Adds HydrationRecord write capability alongside the existing NutritionRecord writes. A volumeMl parameter is passed through the call chain. When present and the hydration permission is granted, a HydrationRecord is inserted in the same batch as the NutritionRecord. Deletion also cascades to the associated hydration record. The hydration permission is bundled into the existing allPermissions set so it's requested together with the nutrition permission.
CaffeineViewModel.kt — Computes the volume (quantity × unit.milliliters) at the three logging call sites that have access to the DrinkUnit data: logDrink(), logDrinkFromAddScreen(), and updateLoggedEntry(). Call sites without unit data (coach dose, recent drink, widget quick-log) pass null — no hydration record is created, which is the expected behavior.
What it means for users
The next time they enable Health Connect, a new "Hydration" permission will appear in the grant dialog
From that point on, every logged drink with a known volume (e.g., 250ml coffee, 330ml can) creates both a caffeine record and a hydration record in Health Connect
Past entries are not backfilled
Disclaimer
I used AI assistance to help implement these changes. I am not an experienced Android/Kotlin developer, so please review carefully — especially the Health Connect API usage and permission flow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add hydration data sync to Health Connect
When logging a drink (coffee, tea, etc.), the app already syncs the caffeine content to Health Connect as a NutritionRecord. This PR adds an HydrationRecord, so Health Connect also track the user's hydration.
Changes
What it means for users
Disclaimer
I used AI assistance to help implement these changes. I am not an experienced Android/Kotlin developer, so please review carefully — especially the Health Connect API usage and permission flow.
Screenshot