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 a13986ae8..cfe235889 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 @@ -141,6 +141,9 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_SLEEP_TIME = "prefs_enable_sleep_time"; public static final String PREF_SLEEP_TIME_START = "prefs_sleep_time_start"; public static final String PREF_SLEEP_TIME_END = "prefs_sleep_time_end"; + public static final String PREF_SLEEP_MODE_SCHEDULE_ENABLED = "sleep_mode_schedule_enabled"; + public static final String PREF_SLEEP_MODE_SCHEDULE_START = "sleep_mode_schedule_start"; + public static final String PREF_SLEEP_MODE_SCHEDULE_END = "sleep_mode_schedule_end"; public static final String PREF_SLEEP_MODE_SLEEP_SCREEN = "pref_sleep_mode_sleep_screen"; public static final String PREF_SLEEP_MODE_SMART_ENABLE = "pref_sleep_mode_smart_enable"; 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 f986a930a..243c67a78 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 @@ -551,6 +551,10 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i addPreferenceHandlerFor(PREF_PREFIX_NOTIFICATION_WITH_APP); + addPreferenceHandlerFor(PREF_SLEEP_MODE_SCHEDULE_ENABLED); + addPreferenceHandlerFor(PREF_SLEEP_MODE_SCHEDULE_START); + addPreferenceHandlerFor(PREF_SLEEP_MODE_SCHEDULE_END); + addPreferenceHandlerFor("lock"); String sleepTimeState = prefs.getString(PREF_SLEEP_TIME, PREF_DO_NOT_DISTURB_OFF); 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 6c0f1ab49..03907ab6e 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 @@ -312,7 +312,7 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator { settings.add(R.xml.devicesettings_header_health); 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_time); // TODO replace with sleep mode schedule + settings.add(R.xml.devicesettings_sleep_mode_schedule); settings.add(R.xml.devicesettings_goal_notification); // diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiScheduleService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiScheduleService.java index a10e757ff..cf2b7d8af 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiScheduleService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/xiaomi/services/XiaomiScheduleService.java @@ -325,9 +325,10 @@ public class XiaomiScheduleService extends AbstractXiaomiService { final String end = XiaomiPreferences.prefFromHourMin(sleepMode.getSchedule().getEnd()); final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences() - .withPreference(DeviceSettingsPreferenceConst.PREF_SLEEP_TIME, sleepMode.getEnabled()) - .withPreference(DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_START, start) - .withPreference(DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_END, end); + .withPreference("prefs_enable_sleep_time", null) + .withPreference(DeviceSettingsPreferenceConst.PREF_SLEEP_MODE_SCHEDULE_ENABLED, sleepMode.getEnabled()) + .withPreference(DeviceSettingsPreferenceConst.PREF_SLEEP_MODE_SCHEDULE_START, start) + .withPreference(DeviceSettingsPreferenceConst.PREF_SLEEP_MODE_SCHEDULE_END, end); getSupport().evaluateGBDeviceEvent(eventUpdatePreferences); } @@ -336,9 +337,9 @@ public class XiaomiScheduleService extends AbstractXiaomiService { LOG.debug("Set sleep mode config"); final Prefs prefs = getDevicePrefs(); - final boolean enabled = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SLEEP_TIME, false); - final Date start = prefs.getTimePreference(DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_START, "22:00"); - final Date end = prefs.getTimePreference(DeviceSettingsPreferenceConst.PREF_SLEEP_TIME_END, "06:00"); + final boolean enabled = prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SLEEP_MODE_SCHEDULE_ENABLED, false); + final Date start = prefs.getTimePreference(DeviceSettingsPreferenceConst.PREF_SLEEP_MODE_SCHEDULE_START, "22:00"); + final Date end = prefs.getTimePreference(DeviceSettingsPreferenceConst.PREF_SLEEP_MODE_SCHEDULE_END, "06:00"); final XiaomiProto.SleepMode sleepMode = XiaomiProto.SleepMode.newBuilder() .setEnabled(enabled) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e79b237aa..c27511017 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2411,4 +2411,8 @@ Running Alerts Focus + Bedtime + Wake Up + Sleep Mode Schedule + Send a reminder and enter sleep mode at bedtime. At the scheduled wake-up time, the wake-up alarm will sound. diff --git a/app/src/main/res/xml/devicesettings_sleep_mode_schedule.xml b/app/src/main/res/xml/devicesettings_sleep_mode_schedule.xml new file mode 100644 index 000000000..a746b4afb --- /dev/null +++ b/app/src/main/res/xml/devicesettings_sleep_mode_schedule.xml @@ -0,0 +1,26 @@ + + + + + + + + + + +