mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 02:25:50 +01:00
Xiaomi: Add vitality score notification preferences
This commit is contained in:
parent
dd0c9cf3e0
commit
c38d2044d8
@ -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";
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
|
||||
|
10
app/src/main/res/drawable/ic_health.xml
Normal file
10
app/src/main/res/drawable/ic_health.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#7E7E7E"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10.5,13H8v-3h2.5V7.5h3V10H16v3h-2.5v2.5h-3V13zM12,2L4,5v6.09c0,5.05 3.41,9.76 8,10.91c4.59,-1.15 8,-5.86 8,-10.91V5L12,2z" />
|
||||
</vector>
|
@ -2443,4 +2443,9 @@
|
||||
<string name="devicetype_mi_watch_color_sport">Mi Watch Color Sport</string>
|
||||
<string name="devicetype_pixoo">Pixoo</string>
|
||||
<string name="not_set">Not set</string>
|
||||
<string name="pref_vitality_score_title">Vitality Score</string>
|
||||
<string name="pref_vitality_score_7_day_title">7-day progress</string>
|
||||
<string name="pref_vitality_score_7_day_summary">Get a notification when your vitality score reaches 30, 60 or 100 in the past 7 days</string>
|
||||
<string name="pref_vitality_score_daily_title">Daily progress</string>
|
||||
<string name="pref_vitality_score_daily_summary">Get a notification when you reached the maximum number of vitality points for the day</string>
|
||||
</resources>
|
||||
|
23
app/src/main/res/xml/devicesettings_vitality_score.xml
Normal file
23
app/src/main/res/xml/devicesettings_vitality_score.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceScreen
|
||||
android:icon="@drawable/ic_health"
|
||||
android:key="pref_screen_vitality_score"
|
||||
android:persistent="false"
|
||||
android:title="@string/pref_vitality_score_title">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_notifications"
|
||||
android:key="pref_vitality_score_7_day"
|
||||
android:summary="@string/pref_vitality_score_7_day_summary"
|
||||
android:title="@string/pref_vitality_score_7_day_title" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:icon="@drawable/ic_notifications"
|
||||
android:key="pref_vitality_score_daily"
|
||||
android:summary="@string/pref_vitality_score_daily_summary"
|
||||
android:title="@string/pref_vitality_score_daily_title" />
|
||||
</PreferenceScreen>
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user