Skip to content

Commit

Permalink
Merge pull request #944 from cph-cachet/bardram/health-update
Browse files Browse the repository at this point in the history
Health 10.2.0
  • Loading branch information
bardram authored Apr 3, 2024
2 parents 58687eb + 122b3ae commit 942d1e4
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 226 deletions.
16 changes: 13 additions & 3 deletions packages/health/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
## 10.2.0

* Using named parameters in most methods for consistency.
* Added a `HealthPlatformType` to save which health platform the data originates from (Apple Health, Google Fit, or Google Health Connect).
* Android: Improved support for Google Health Connect
* getHealthConnectSdkStatus, PR [#941](https://github.com/cph-cachet/flutter-plugins/pull/941)
* installHealthConnect, PR [#943](https://github.com/cph-cachet/flutter-plugins/pull/943)
* workout title, PR [#938](https://github.com/cph-cachet/flutter-plugins/pull/938)
* iOS: Add support for saving blood pressure as a correlation, PR [#919](https://github.com/cph-cachet/flutter-plugins/pull/919)

## 10.1.1

* fix of error in `WorkoutSummary` JSON serialization.
* fix of [#934](https://github.com/cph-cachet/flutter-plugins/issues/934)
* empty value check for calories nutrition, PR [#926](https://github.com/cph-cachet/flutter-plugins/pull/926)
* Fix of error in `WorkoutSummary` JSON serialization.
* Fix of [#934](https://github.com/cph-cachet/flutter-plugins/issues/934)
* Empty value check for calories nutrition, PR [#926](https://github.com/cph-cachet/flutter-plugins/pull/926)

## 10.0.0

Expand Down
28 changes: 23 additions & 5 deletions packages/health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,35 @@ HealthDataType type;
HealthDataUnit unit;
DateTime dateFrom;
DateTime dateTo;
PlatformType platform;
String uuid, deviceId;
HealthPlatformType sourcePlatform;
String sourceDeviceId;
String sourceId;
String sourceName;
bool isManualEntry;
WorkoutSummary? workoutSummary;
```

where a [HealthValue](https://pub.dev/documentation/health/latest/health/HealthValue-class.html) can be any type of `AudiogramHealthValue`, `ElectrocardiogramHealthValue`, `ElectrocardiogramVoltageValue`, `NumericHealthValue`, `NutritionHealthValue`, or `WorkoutHealthValue`.

A `HealthDataPoint` object can be serialized to and from JSON using the `toJson()` and `fromJson()` methods. JSON serialization is using camel_case notation.
where a [`HealthValue`](https://pub.dev/documentation/health/latest/health/HealthValue-class.html) can be any type of `AudiogramHealthValue`, `ElectrocardiogramHealthValue`, `ElectrocardiogramVoltageValue`, `NumericHealthValue`, `NutritionHealthValue`, or `WorkoutHealthValue`.

A `HealthDataPoint` object can be serialized to and from JSON using the `toJson()` and `fromJson()` methods. JSON serialization is using camel_case notation. Null values are not serialized. For example;

```json
{
"value": {
"__type": "NumericHealthValue",
"numeric_value": 141.0
},
"type": "STEPS",
"unit": "COUNT",
"date_from": "2024-04-03T10:06:57.736",
"date_to": "2024-04-03T10:12:51.724",
"source_platform": "appleHealth",
"source_device_id": "F74938B9-C011-4DE4-AA5E-CF41B60B96E7",
"source_id": "com.apple.health.81AE7156-EC05-47E3-AC93-2D6F65C717DF",
"source_name": "iPhone12.bardram.net",
"is_manual_entry": false
}
```

### Fetch health data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Handler
import android.util.Log
Expand Down Expand Up @@ -2382,7 +2383,9 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
/** Handle calls from the MethodChannel */
override fun onMethodCall(call: MethodCall, result: Result) {
when (call.method) {
"installHealthConnect" -> installHealthConnect(call, result)
"useHealthConnectIfAvailable" -> useHealthConnectIfAvailable(call, result)
"getHealthConnectSdkStatus" -> getHealthConnectSdkStatus(call, result)
"hasPermissions" -> hasPermissions(call, result)
"requestAuthorization" -> requestAuthorization(call, result)
"revokePermissions" -> revokePermissions(call, result)
Expand All @@ -2408,15 +2411,13 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
binding.addActivityResultListener(this)
activity = binding.activity

if (healthConnectAvailable) {
val requestPermissionActivityContract =
PermissionController.createRequestPermissionResultContract()
val requestPermissionActivityContract =
PermissionController.createRequestPermissionResultContract()

healthConnectRequestPermissionsLauncher =
(activity as ComponentActivity).registerForActivityResult(
requestPermissionActivityContract
) { granted -> onHealthConnectPermissionCallback(granted) }
}
healthConnectRequestPermissionsLauncher =
(activity as ComponentActivity).registerForActivityResult(
requestPermissionActivityContract
) { granted -> onHealthConnectPermissionCallback(granted) }
}

override fun onDetachedFromActivityForConfigChanges() {
Expand Down Expand Up @@ -2444,11 +2445,37 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
healthConnectAvailable = healthConnectStatus == HealthConnectClient.SDK_AVAILABLE
}

private fun installHealthConnect(call: MethodCall, result: Result) {
val uriString =
"market://details?id=com.google.android.apps.healthdata&url=healthconnect%3A%2F%2Fonboarding"
context!!.startActivity(
Intent(Intent.ACTION_VIEW).apply {
setPackage("com.android.vending")
data = Uri.parse(uriString)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra("overlay", true)
putExtra("callerId", context!!.packageName)
}
)
result.success(null)
}

fun useHealthConnectIfAvailable(call: MethodCall, result: Result) {
useHealthConnectIfAvailable = true
result.success(null)
}

private fun getHealthConnectSdkStatus(call: MethodCall, result: Result) {
checkAvailability()
if (healthConnectAvailable) {
healthConnectClient =
HealthConnectClient.getOrCreate(
context!!
)
}
result.success(healthConnectStatus)
}

private fun hasPermissionsHC(call: MethodCall, result: Result) {
val args = call.arguments as HashMap<*, *>
val types = (args["types"] as? ArrayList<*>)?.filterIsInstance<String>()!!
Expand Down Expand Up @@ -3765,6 +3792,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
return
}
val workoutType = workoutTypeMapHealthConnect[type]!!
val title = call.argument<String>("title") ?: type

scope.launch {
try {
Expand All @@ -3776,7 +3804,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
endTime = endTime,
endZoneOffset = null,
exerciseType = workoutType,
title = type,
title = title,
),
)
if (totalDistance != null) {
Expand Down
Loading

0 comments on commit 942d1e4

Please sign in to comment.