1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-25 11:26:47 +01:00

Mi Band 8: Replace sleep time with sleep mode schedule (fix crash)

This commit is contained in:
José Rebelo 2023-10-08 14:08:43 +01:00
parent 76c2a18af5
commit 809a809082
6 changed files with 45 additions and 7 deletions

View File

@ -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";

View File

@ -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);

View File

@ -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);
//

View File

@ -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)

View File

@ -2411,4 +2411,8 @@
<string name="menuitem_running">Running</string>
<string name="menuitem_alerts">Alerts</string>
<string name="menuitem_focus">Focus</string>
<string name="bedtime">Bedtime</string>
<string name="wake_up_time">Wake Up</string>
<string name="pref_sleep_mode_schedule_title">Sleep Mode Schedule</string>
<string name="pref_sleep_mode_schedule_summary">Send a reminder and enter sleep mode at bedtime. At the scheduled wake-up time, the wake-up alarm will sound.</string>
</resources>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen
android:icon="@drawable/ic_activity_sleep"
android:key="prefs_sleep_mode_schedule"
android:persistent="false"
android:title="@string/pref_sleep_mode_title">
<SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_activity_sleep"
android:key="sleep_mode_schedule_enabled"
android:summary="@string/pref_sleep_mode_schedule_summary"
android:title="@string/pref_sleep_mode_schedule_title" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="22:00"
android:key="sleep_mode_schedule_start"
android:title="@string/bedtime" />
<nodomain.freeyourgadget.gadgetbridge.util.XTimePreference
android:defaultValue="06:00"
android:key="sleep_mode_schedule_end"
android:title="@string/wake_up_time" />
</PreferenceScreen>
</androidx.preference.PreferenceScreen>