1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-24 16:47:32 +01:00

Xiaomi: Configure fitness goal notification and secondary goal

This commit is contained in:
José Rebelo 2023-12-10 11:02:22 +00:00
parent 4635bf018a
commit dd0c9cf3e0
7 changed files with 93 additions and 3 deletions

View File

@ -371,6 +371,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_AUTH_KEY = "authkey";
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_HOURLY_CHIME_ENABLE = "hourly_chime_enable";
public static final String PREF_HOURLY_CHIME_START = "hourly_chime_start";

View File

@ -515,6 +515,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
addPreferenceHandlerFor(PREF_QC35_NOISE_CANCELLING_LEVEL);
addPreferenceHandlerFor(PREF_USER_FITNESS_GOAL);
addPreferenceHandlerFor(PREF_USER_FITNESS_GOAL_NOTIFICATION);
addPreferenceHandlerFor(PREF_USER_FITNESS_GOAL_SECONDARY);
addPreferenceHandlerFor(PREF_UM25_SHOW_THRESHOLD_NOTIFICATION);
addPreferenceHandlerFor(PREF_UM25_SHOW_THRESHOLD);

View File

@ -371,7 +371,8 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
settings.add(R.xml.devicesettings_heartrate_sleep_alert_activity_stress_spo2);
settings.add(R.xml.devicesettings_inactivity_dnd_no_threshold);
settings.add(R.xml.devicesettings_sleep_mode_schedule);
// TODO not implemented settings.add(R.xml.devicesettings_goal_notification);
settings.add(R.xml.devicesettings_goal_notification);
settings.add(R.xml.devicesettings_goal_secondary);
//
// Workout

View File

@ -52,7 +52,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiPreferences;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.XiaomiActivityFileFetcher;
@ -78,6 +77,8 @@ public class XiaomiHealthService extends AbstractXiaomiService {
private static final int CMD_CONFIG_STANDING_REMINDER_SET = 13;
private static final int CMD_CONFIG_STRESS_GET = 14;
private static final int CMD_CONFIG_STRESS_SET = 15;
private static final int CMD_CONFIG_GOAL_GET = 21;
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_WORKOUT_LOCATION = 48;
@ -127,7 +128,6 @@ public class XiaomiHealthService extends AbstractXiaomiService {
case CMD_CONFIG_HEART_RATE_SET:
LOG.debug("Got heart rate set ack, status={}", cmd.getStatus());
return;
case CMD_CONFIG_HEART_RATE_GET:
handleHeartRateConfig(cmd.getHealth().getHeartRate());
return;
@ -143,6 +143,12 @@ public class XiaomiHealthService extends AbstractXiaomiService {
case CMD_CONFIG_STRESS_SET:
LOG.debug("Got stress set ack, status={}", cmd.getStatus());
return;
case CMD_CONFIG_GOAL_GET:
handleGoalConfig(cmd.getHealth().getAchievementReminders());
return;
case CMD_CONFIG_GOAL_SET:
LOG.debug("Got goal set ack, status={}", cmd.getStatus());
return;
case CMD_WORKOUT_WATCH_STATUS:
handleWorkoutStatus(cmd.getHealth().getWorkoutStatusWatch());
return;
@ -164,6 +170,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
getSupport().sendCommand("get heart rate config", COMMAND_TYPE, CMD_CONFIG_HEART_RATE_GET);
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);
}
@Override
@ -179,6 +186,10 @@ public class XiaomiHealthService extends AbstractXiaomiService {
case ActivityUser.PREF_USER_ACTIVETIME_MINUTES:
setUserInfo();
return true;
case DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_NOTIFICATION:
case DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_SECONDARY:
sendGoalConfig();
return true;
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_USE_FOR_SLEEP_DETECTION:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_SLEEP_BREATHING_QUALITY_MONITORING:
case DeviceSettingsPreferenceConst.PREF_HEARTRATE_MEASUREMENT_INTERVAL:
@ -253,6 +264,57 @@ public class XiaomiHealthService extends AbstractXiaomiService {
);
}
private void handleGoalConfig(final XiaomiProto.AchievementReminders achievementReminders) {
LOG.debug("Got goal config");
final String secondaryValue;
switch (achievementReminders.getSuggested()) {
case 0:
secondaryValue = "active_time";
break;
case 1:
default:
secondaryValue = "standing_time";
}
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences()
.withPreference(DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_NOTIFICATION, achievementReminders.getEnabled())
.withPreference(DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_SECONDARY, secondaryValue);
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
}
public void sendGoalConfig() {
final boolean goalNotification = getDevicePrefs().getBoolean(DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_NOTIFICATION, false);
final String goalSecondary = getDevicePrefs().getString(DeviceSettingsPreferenceConst.PREF_USER_FITNESS_GOAL_SECONDARY, "standing_time");
LOG.debug("Setting goal config, notification={}, secondary={}", goalNotification, goalSecondary);
final XiaomiProto.AchievementReminders.Builder achievementReminders = XiaomiProto.AchievementReminders.newBuilder()
.setEnabled(goalNotification)
.setSuggested(1);
if (goalSecondary.equals("active_time")) {
achievementReminders.setSuggested(0);
} else {
achievementReminders.setSuggested(1);
}
final XiaomiProto.Health health = XiaomiProto.Health.newBuilder()
.setAchievementReminders(achievementReminders)
.build();
getSupport().sendCommand(
"set goal config",
XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE)
.setSubtype(CMD_CONFIG_GOAL_SET)
.setHealth(health)
.build()
);
}
private void handleSpo2Config(final XiaomiProto.SpO2 spo2) {
LOG.debug("Got SpO2 config");

View File

@ -2089,6 +2089,16 @@
<item>@string/timeformat_am_pm</item>
</string-array>
<string-array name="goal_fitness_secondary_goal_values">
<item>active_time</item>
<item>standing_time</item>
</string-array>
<string-array name="goal_fitness_secondary_goal_entries">
<item>@string/active_time</item>
<item>@string/standing_time</item>
</string-array>
<string-array name="pref_timeformat_values">
<item>@string/p_timeformat_auto</item>
<item>@string/p_timeformat_24h</item>

View File

@ -408,6 +408,7 @@
<string name="pref_title_unit_system">Units</string>
<string name="pref_title_timeformat">Time format</string>
<string name="pref_title_screentime">Screen on duration</string>
<string name="pref_title_goal_secondary">Secondary goal</string>
<string name="prefs_title_all_day_heart_rate">All day heart rate measurement</string>
<string name="preferences_hplus_settings">HPlus/Makibes settings</string>
<!-- WatchXPlus Preferences -->
@ -1100,6 +1101,8 @@
<string name="activity_prefs_activetime_minutes">Daily target: active time in minutes</string>
<string name="activity_prefs_goal_standing_time_minutes">Daily target: standing time in minutes</string>
<string name="activity_prefs_goal_fat_burn_time_minutes">Daily target: fat burn time in minutes</string>
<string name="active_time">Active time</string>
<string name="standing_time">Standing time</string>
<string name="pref_title_pebble_health_store_raw">Store raw record in the database</string>
<string name="pref_summary_pebble_health_store_raw">Stores the data \"as is\", increasing the database usage to allow for later interpretation.</string>
<string name="action_db_management">Data management</string>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
android:defaultValue="standing_time"
android:entries="@array/goal_fitness_secondary_goal_entries"
android:entryValues="@array/goal_fitness_secondary_goal_values"
android:icon="@drawable/ic_star_gray"
android:key="fitness_goal_secondary"
android:title="@string/pref_title_goal_secondary"
app:useSimpleSummaryProvider="true" />
</androidx.preference.PreferenceScreen>