From 00d0beeadc97678c12fdd8b41df5999afadf4bcb Mon Sep 17 00:00:00 2001 From: "rafal.platek" <8421184+rafaellop@users.noreply.github.com> Date: Mon, 20 Nov 2023 12:12:18 +0100 Subject: [PATCH 1/2] Add missing Android workout types Fixes https://github.com/cph-cachet/flutter-plugins/issues/835 and related iOS list is complete so no changes introduced. --- packages/health/lib/src/health_factory.dart | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/health/lib/src/health_factory.dart b/packages/health/lib/src/health_factory.dart index 58ccc85ed..1e6091f93 100644 --- a/packages/health/lib/src/health_factory.dart +++ b/packages/health/lib/src/health_factory.dart @@ -700,6 +700,7 @@ class HealthFactory { bool _isOnAndroid(HealthWorkoutActivityType type) { // Returns true if the type is part of the Android set return { + // Both HealthWorkoutActivityType.ARCHERY, HealthWorkoutActivityType.BADMINTON, HealthWorkoutActivityType.BASEBALL, @@ -742,8 +743,16 @@ class HealthFactory { HealthWorkoutActivityType.WALKING, HealthWorkoutActivityType.WATER_POLO, HealthWorkoutActivityType.YOGA, + + // Android only HealthWorkoutActivityType.AEROBICS, HealthWorkoutActivityType.BIATHLON, + HealthWorkoutActivityType.BIKING_HAND, + HealthWorkoutActivityType.BIKING_MOUNTAIN, + HealthWorkoutActivityType.BIKING_ROAD, + HealthWorkoutActivityType.BIKING_SPINNING, + HealthWorkoutActivityType.BIKING_STATIONARY, + HealthWorkoutActivityType.BIKING_UTILITY, HealthWorkoutActivityType.CALISTHENICS, HealthWorkoutActivityType.CIRCUIT_TRAINING, HealthWorkoutActivityType.CROSS_FIT, @@ -759,6 +768,7 @@ class HealthFactory { HealthWorkoutActivityType.HOUSEWORK, HealthWorkoutActivityType.INTERVAL_TRAINING, HealthWorkoutActivityType.IN_VEHICLE, + HealthWorkoutActivityType.ICE_SKATING, HealthWorkoutActivityType.KAYAKING, HealthWorkoutActivityType.KETTLEBELL_TRAINING, HealthWorkoutActivityType.KICK_SCOOTER, @@ -768,18 +778,22 @@ class HealthFactory { HealthWorkoutActivityType.P90X, HealthWorkoutActivityType.PARAGLIDING, HealthWorkoutActivityType.POLO, - HealthWorkoutActivityType.ROCK_CLIMBING, + HealthWorkoutActivityType.ROCK_CLIMBING, + HealthWorkoutActivityType.ROWING_MACHINE, HealthWorkoutActivityType.RUNNING_JOGGING, - HealthWorkoutActivityType.RUNNING_SAND, + HealthWorkoutActivityType.RUNNING_SAND, HealthWorkoutActivityType.RUNNING_TREADMILL, HealthWorkoutActivityType.SCUBA_DIVING, - HealthWorkoutActivityType.SKATING_CROSS, + HealthWorkoutActivityType.SKATING_CROSS, HealthWorkoutActivityType.SKATING_INDOOR, HealthWorkoutActivityType.SKATING_INLINE, + HealthWorkoutActivityType.SKIING, HealthWorkoutActivityType.SKIING_BACK_COUNTRY, HealthWorkoutActivityType.SKIING_KITE, HealthWorkoutActivityType.SKIING_ROLLER, HealthWorkoutActivityType.SLEDDING, + HealthWorkoutActivityType.SNOWMOBILE, + HealthWorkoutActivityType.SNOWSHOEING, HealthWorkoutActivityType.STAIR_CLIMBING_MACHINE, HealthWorkoutActivityType.STANDUP_PADDLEBOARDING, HealthWorkoutActivityType.STILL, From c20121b370e5714b8943a78c77ceb3fa62aa8872 Mon Sep 17 00:00:00 2001 From: Matteo Hoffmann Date: Mon, 29 Jan 2024 14:32:07 +0100 Subject: [PATCH 2/2] Added null check --- .../main/kotlin/cachet/plugins/health/HealthPlugin.kt | 7 ++++++- packages/health/lib/src/health_factory.dart | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt b/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt index ce3c5425e..541d64278 100644 --- a/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt +++ b/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt @@ -243,7 +243,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) : // "BIATHLON" to ExerciseSessionRecord.EXERCISE_TYPE_BIATHLON, "BIKING" to ExerciseSessionRecord.EXERCISE_TYPE_BIKING, // "BIKING_HAND" to ExerciseSessionRecord.EXERCISE_TYPE_BIKING_HAND, - // "BIKING_MOUNTAIN" to ExerciseSessionRecord.EXERCISE_TYPE_BIKING_MOUNTAIN, + //"BIKING_MOUNTAIN" to ExerciseSessionRecord.EXERCISE_TYPE_BIKING_MOUNTAIN, // "BIKING_ROAD" to ExerciseSessionRecord.EXERCISE_TYPE_BIKING_ROAD, // "BIKING_SPINNING" to ExerciseSessionRecord.EXERCISE_TYPE_BIKING_SPINNING, // "BIKING_STATIONARY" to ExerciseSessionRecord.EXERCISE_TYPE_BIKING_STATIONARY, @@ -2168,6 +2168,11 @@ class HealthPlugin(private var channel: MethodChannel? = null) : val endTime = Instant.ofEpochMilli(call.argument("endTime")!!) val totalEnergyBurned = call.argument("totalEnergyBurned") val totalDistance = call.argument("totalDistance") + if(workoutTypeMapHealthConnect.containsKey(type) == false) { + result.success(false) + Log.w("FLUTTER_HEALTH::ERROR", "[Health Connect] Workout type not supported") + return + } val workoutType = workoutTypeMapHealthConnect[type]!! scope.launch { diff --git a/packages/health/lib/src/health_factory.dart b/packages/health/lib/src/health_factory.dart index 3e8bd2897..b25b0c095 100644 --- a/packages/health/lib/src/health_factory.dart +++ b/packages/health/lib/src/health_factory.dart @@ -787,8 +787,9 @@ class HealthFactory { HealthWorkoutActivityType.WALKING, HealthWorkoutActivityType.WATER_POLO, HealthWorkoutActivityType.YOGA, - + // Android only + // Once Google Fit is removed, this list needs to be changed HealthWorkoutActivityType.AEROBICS, HealthWorkoutActivityType.BIATHLON, HealthWorkoutActivityType.BIKING_HAND, @@ -822,13 +823,13 @@ class HealthFactory { HealthWorkoutActivityType.P90X, HealthWorkoutActivityType.PARAGLIDING, HealthWorkoutActivityType.POLO, - HealthWorkoutActivityType.ROCK_CLIMBING, + HealthWorkoutActivityType.ROCK_CLIMBING, HealthWorkoutActivityType.ROWING_MACHINE, HealthWorkoutActivityType.RUNNING_JOGGING, - HealthWorkoutActivityType.RUNNING_SAND, + HealthWorkoutActivityType.RUNNING_SAND, HealthWorkoutActivityType.RUNNING_TREADMILL, HealthWorkoutActivityType.SCUBA_DIVING, - HealthWorkoutActivityType.SKATING_CROSS, + HealthWorkoutActivityType.SKATING_CROSS, HealthWorkoutActivityType.SKATING_INDOOR, HealthWorkoutActivityType.SKATING_INLINE, HealthWorkoutActivityType.SKIING,