diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
index ea7b3d088..21dfee1e5 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSettingsPreferenceConst.java
@@ -372,6 +372,8 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_USER_FITNESS_GOAL = "fitness_goal";
public static final String PREF_USER_FITNESS_GOAL_NOTIFICATION = "fitness_goal_notification";
public static final String PREF_USER_FITNESS_GOAL_SECONDARY = "fitness_goal_secondary";
+ public static final String PREF_VITALITY_SCORE_7_DAY = "pref_vitality_score_7_day";
+ public static final String PREF_VITALITY_SCORE_DAILY = "pref_vitality_score_daily";
public static final String PREF_HOURLY_CHIME_ENABLE = "hourly_chime_enable";
public static final String PREF_HOURLY_CHIME_START = "hourly_chime_start";
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
index a7db56e3d..1fd43e0e9 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/devicesettings/DeviceSpecificSettingsFragment.java
@@ -517,6 +517,9 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
addPreferenceHandlerFor(PREF_USER_FITNESS_GOAL_NOTIFICATION);
addPreferenceHandlerFor(PREF_USER_FITNESS_GOAL_SECONDARY);
+ addPreferenceHandlerFor(PREF_VITALITY_SCORE_7_DAY);
+ addPreferenceHandlerFor(PREF_VITALITY_SCORE_DAILY);
+
addPreferenceHandlerFor(PREF_UM25_SHOW_THRESHOLD_NOTIFICATION);
addPreferenceHandlerFor(PREF_UM25_SHOW_THRESHOLD);
addPreferenceHandlerFor(PREF_HOURLY_CHIME_ENABLE);
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java
index b79833e4d..d40cb2ce2 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/xiaomi/XiaomiCoordinator.java
@@ -373,6 +373,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
settings.add(R.xml.devicesettings_sleep_mode_schedule);
settings.add(R.xml.devicesettings_goal_notification);
settings.add(R.xml.devicesettings_goal_secondary);
+ settings.add(R.xml.devicesettings_vitality_score);
//
// Workout
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java
index 5337fbedb..579c58a9c 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiHealthService.java
@@ -81,6 +81,8 @@ public class XiaomiHealthService extends AbstractXiaomiService {
private static final int CMD_CONFIG_GOAL_SET = 22;
private static final int CMD_WORKOUT_WATCH_STATUS = 26;
private static final int CMD_WORKOUT_WATCH_OPEN = 30;
+ private static final int CMD_CONFIG_VITALITY_SCORE_GET = 35;
+ private static final int CMD_CONFIG_VITALITY_SCORE_SET = 36;
private static final int CMD_WORKOUT_LOCATION = 48;
private static final int CMD_REALTIME_STATS_START = 45;
private static final int CMD_REALTIME_STATS_STOP = 46;
@@ -149,6 +151,12 @@ public class XiaomiHealthService extends AbstractXiaomiService {
case CMD_CONFIG_GOAL_SET:
LOG.debug("Got goal set ack, status={}", cmd.getStatus());
return;
+ case CMD_CONFIG_VITALITY_SCORE_GET:
+ handleVitalityScore(cmd.getHealth().getVitalityScore());
+ return;
+ case CMD_CONFIG_VITALITY_SCORE_SET:
+ LOG.debug("Got vitality score set ack, status={}", cmd.getStatus());
+ return;
case CMD_WORKOUT_WATCH_STATUS:
handleWorkoutStatus(cmd.getHealth().getWorkoutStatusWatch());
return;
@@ -171,6 +179,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
getSupport().sendCommand("get standing reminders config", COMMAND_TYPE, CMD_CONFIG_STANDING_REMINDER_GET);
getSupport().sendCommand("get stress config", COMMAND_TYPE, CMD_CONFIG_STRESS_GET);
getSupport().sendCommand("get goal config", COMMAND_TYPE, CMD_CONFIG_GOAL_GET);
+ getSupport().sendCommand("get vitality score config", COMMAND_TYPE, CMD_CONFIG_VITALITY_SCORE_GET);
}
@Override
@@ -190,6 +199,10 @@ public class XiaomiHealthService extends AbstractXiaomiService {
case DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_SECONDARY:
sendGoalConfig();
return true;
+ case DeviceSettingsPreferenceConst.PREF_VITALITY_SCORE_7_DAY:
+ case DeviceSettingsPreferenceConst.PREF_VITALITY_SCORE_DAILY:
+ sendVitalityScoreConfig();
+ return true;
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_SLEEP_BREATHING_QUALITY_MONITORING:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_MEASUREMENT_INTERVAL:
@@ -315,6 +328,41 @@ public class XiaomiHealthService extends AbstractXiaomiService {
);
}
+ private void handleVitalityScore(final XiaomiProto.VitalityScore vitalityScore) {
+ LOG.debug("Got vitality score config");
+
+ final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences()
+ .withPreference(DeviceSettingsPreferenceConst.PREF_VITALITY_SCORE_7_DAY, vitalityScore.getSevenDay())
+ .withPreference(DeviceSettingsPreferenceConst.PREF_VITALITY_SCORE_DAILY, vitalityScore.getDailyProgress());
+
+ getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
+ }
+
+ public void sendVitalityScoreConfig() {
+ final boolean prefSevenDay = getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_VITALITY_SCORE_7_DAY, false);
+ final boolean prefDaily = getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_VITALITY_SCORE_DAILY, false);
+
+ LOG.debug("Setting vitality score config, 7day={}, daily={}", prefSevenDay, prefDaily);
+
+ final XiaomiProto.VitalityScore vitalityScore = XiaomiProto.VitalityScore.newBuilder()
+ .setSevenDay(prefSevenDay)
+ .setDailyProgress(prefDaily)
+ .build();
+
+ final XiaomiProto.Health health = XiaomiProto.Health.newBuilder()
+ .setVitalityScore(vitalityScore)
+ .build();
+
+ getSupport().sendCommand(
+ "set vitality score config",
+ XiaomiProto.Command.newBuilder()
+ .setType(COMMAND_TYPE)
+ .setSubtype(CMD_CONFIG_VITALITY_SCORE_SET)
+ .setHealth(health)
+ .build()
+ );
+ }
+
private void handleSpo2Config(final XiaomiProto.SpO2 spo2) {
LOG.debug("Got SpO2 config");
diff --git a/app/src/main/res/drawable/ic_health.xml b/app/src/main/res/drawable/ic_health.xml
new file mode 100644
index 000000000..1282ee360
--- /dev/null
+++ b/app/src/main/res/drawable/ic_health.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 121163615..15898934c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -2443,4 +2443,9 @@
Mi Watch Color Sport
Pixoo
Not set
+ Vitality Score
+ 7-day progress
+ Get a notification when your vitality score reaches 30, 60 or 100 in the past 7 days
+ Daily progress
+ Get a notification when you reached the maximum number of vitality points for the day
diff --git a/app/src/main/res/xml/devicesettings_vitality_score.xml b/app/src/main/res/xml/devicesettings_vitality_score.xml
new file mode 100644
index 000000000..eb109d7fc
--- /dev/null
+++ b/app/src/main/res/xml/devicesettings_vitality_score.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+