Import lean body mass from the health platforms

This commit is contained in:
Roland Geider
2026-08-07 16:48:42 +02:00
parent 3855dbc423
commit 9cd9aaac17
9 changed files with 31 additions and 3 deletions

View File

@@ -15,6 +15,7 @@
metric its import. Guarded by health_manifest_test.dart -->
<uses-permission android:name="android.permission.health.READ_WEIGHT"/>
<uses-permission android:name="android.permission.health.READ_BODY_FAT"/>
<uses-permission android:name="android.permission.health.READ_LEAN_BODY_MASS"/>
<uses-permission android:name="android.permission.health.READ_HEIGHT"/>
<uses-permission android:name="android.permission.health.READ_BLOOD_PRESSURE"/>
<uses-permission android:name="android.permission.health.READ_HEART_RATE"/>

View File

@@ -180,6 +180,15 @@ const List<HealthMetric> healthMetrics = [
toCategoryValue: _bodyFatToPercent,
enabled: true,
),
HealthMetric(
// Both platforms report kilograms, like body weight. Unlike it, the
// category holds only kg: the per-entry unit of locked decision #9 is
// body weight's alone.
metricType: MetricType.leanBodyMass,
dataType: HealthDataType.LEAN_BODY_MASS,
toCategoryValue: _identity,
enabled: true,
),
HealthMetric(
metricType: MetricType.height,
dataType: HealthDataType.HEIGHT,

View File

@@ -179,6 +179,7 @@ enum MetricType {
custom('custom'),
bodyWeight('body_weight'),
bodyFat('body_fat'),
leanBodyMass('lean_body_mass'),
height('height'),
bloodPressure('blood_pressure'),
bloodPressureSystolic('blood_pressure_systolic'),
@@ -306,6 +307,7 @@ enum MetricType {
MetricType.custom => '',
MetricType.bodyWeight => 'Weight',
MetricType.bodyFat => 'Body fat',
MetricType.leanBodyMass => 'Lean body mass',
MetricType.height => 'Height',
MetricType.bloodPressure => 'Blood pressure',
MetricType.bloodPressureSystolic => 'Systolic',
@@ -332,7 +334,7 @@ enum MetricType {
/// follows the profile.
String get defaultUnit => switch (this) {
MetricType.custom => '',
MetricType.bodyWeight => 'kg',
MetricType.bodyWeight || MetricType.leanBodyMass => 'kg',
MetricType.bodyFat || MetricType.bloodOxygen => '%',
MetricType.height => 'cm',
MetricType.bloodPressure ||
@@ -364,7 +366,10 @@ enum MetricType {
/// context. Custom categories are typically hand-kept body measurements
/// (waist, biceps), so they qualify; the typed health metrics do not.
bool get correlatesWithNutrition => switch (this) {
MetricType.bodyWeight || MetricType.bodyFat || MetricType.custom => true,
MetricType.bodyWeight ||
MetricType.bodyFat ||
MetricType.leanBodyMass ||
MetricType.custom => true,
_ => false,
};
@@ -380,6 +385,8 @@ enum MetricType {
MetricType.bodyWeight =>
unit == 'lb' ? const MetricLimits(44, 770, 66, 661) : const MetricLimits(20, 350, 30, 300),
MetricType.bodyFat => const MetricLimits(2, 60, 5, 50),
// Always below the body weight it is part of, so the floor can sit lower
MetricType.leanBodyMass => const MetricLimits(10, 250, 30, 90),
MetricType.height => const MetricLimits(50, 250, 140, 210),
MetricType.bloodPressureSystolic => const MetricLimits(50, 250, 90, 180),
MetricType.bloodPressureDiastolic => const MetricLimits(30, 150, 50, 110),
@@ -420,6 +427,7 @@ enum MetricType {
num? binWidth([String? unit]) => switch (this) {
MetricType.bodyWeight => unit == 'lb' ? 1 : 0.5,
MetricType.bodyFat => 0.5,
MetricType.leanBodyMass => 0.5,
MetricType.height => 1,
MetricType.bloodPressureSystolic || MetricType.bloodPressureDiastolic => 5,
MetricType.heartRate => 2,
@@ -445,6 +453,7 @@ extension MeasurementMetricTypeL10n on MetricType {
MetricType.custom => l10n.metricCustom,
MetricType.bodyWeight => l10n.metricBodyWeight,
MetricType.bodyFat => l10n.metricBodyFat,
MetricType.leanBodyMass => l10n.metricLeanBodyMass,
MetricType.height => l10n.metricHeight,
MetricType.bloodPressure => l10n.metricBloodPressure,
MetricType.bloodPressureSystolic => l10n.metricBloodPressureSystolic,

View File

@@ -1136,6 +1136,7 @@
"reorderCategories": "Kategorien neu anordnen",
"metricCustom": "Benutzerdefiniert",
"metricBodyWeight": "Körpergewicht",
"metricLeanBodyMass": "Magermasse",
"metricBodyFat": "Körperfett",
"metricHeight": "Körpergröße",
"metricBloodPressure": "Blutdruck",

View File

@@ -730,6 +730,10 @@
"@metricBodyWeight": {
"description": "Label for body weight measurement"
},
"metricLeanBodyMass": "Lean body mass",
"@metricLeanBodyMass": {
"description": "Label for lean body mass measurement"
},
"metricBodyFat": "Body fat",
"@metricBodyFat": {
"description": "Label for body fat percentage measurement"

View File

@@ -1175,6 +1175,7 @@
"reorderCategories": "Reordenar categorías",
"metricCustom": "Personalizado",
"metricBodyWeight": "Peso corporal",
"metricLeanBodyMass": "Masa magra",
"metricBodyFat": "Grasa corporal",
"metricHeight": "Altura",
"metricBloodPressure": "Presión arterial",

View File

@@ -1146,6 +1146,7 @@
"reorderCategories": "Réorganiser les catégories",
"metricCustom": "Personnalisé",
"metricBodyWeight": "Poids corporel",
"metricLeanBodyMass": "Masse maigre",
"metricBodyFat": "Graisse corporelle",
"metricHeight": "Taille",
"metricBloodPressure": "Pression artérielle",

View File

@@ -29,6 +29,7 @@ import 'package:wger/features/health/models/health_metric.dart';
const _readPermissions = {
HealthDataType.WEIGHT: 'android.permission.health.READ_WEIGHT',
HealthDataType.BODY_FAT_PERCENTAGE: 'android.permission.health.READ_BODY_FAT',
HealthDataType.LEAN_BODY_MASS: 'android.permission.health.READ_LEAN_BODY_MASS',
HealthDataType.HEIGHT: 'android.permission.health.READ_HEIGHT',
HealthDataType.BLOOD_PRESSURE_SYSTOLIC: 'android.permission.health.READ_BLOOD_PRESSURE',
HealthDataType.BLOOD_PRESSURE_DIASTOLIC: 'android.permission.health.READ_BLOOD_PRESSURE',

View File

@@ -30,6 +30,7 @@ void main() {
enabledHealthMetrics.map((m) => m.metricType),
containsAll([
MetricType.bodyFat,
MetricType.leanBodyMass,
MetricType.height,
MetricType.bodyWeight,
MetricType.bloodPressure,
@@ -42,7 +43,7 @@ void main() {
MetricType.energy,
]),
);
expect(enabledHealthMetrics.length, 11);
expect(enabledHealthMetrics.length, 12);
});
test('daily aggregation is set per metric', () {