From fd69b1a3ea9ee4454e5efd2f1ad5efb4312266fb Mon Sep 17 00:00:00 2001 From: Damien Gaignon Date: Mon, 7 Mar 2022 15:51:54 +0100 Subject: [PATCH] Move mi2_inactivity constants to inactivity --- .../DeviceSettingsPreferenceConst.java | 3 ++ .../DeviceSpecificSettingsFragment.java | 3 ++ .../devices/huami/HuamiCoordinator.java | 14 +++--- .../devices/miband/MiBandConst.java | 7 --- .../miband/MiBandPreferencesActivity.java | 44 +++++++++---------- .../service/devices/huami/HuamiSupport.java | 21 ++++++--- app/src/main/res/xml/miband_preferences.xml | 28 ++++++------ 7 files changed, 63 insertions(+), 57 deletions(-) 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 9c2343a47..592b77576 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 @@ -74,6 +74,9 @@ public class DeviceSettingsPreferenceConst { public static final String PREF_INACTIVITY_FR = "inactivity_warnings_fr"; public static final String PREF_INACTIVITY_SA = "inactivity_warnings_sa"; public static final String PREF_INACTIVITY_SU = "inactivity_warnings_su"; + public static final String PREF_INACTIVITY_DND = "inactivity_warnings_dnd"; + public static final String PREF_INACTIVITY_DND_START = "inactivity_warnings_dnd_start"; + public static final String PREF_INACTIVITY_DND_END = "inactivity_warnings_dnd_end"; public static final String PREF_AUTOHEARTRATE_SWITCH = "pref_autoheartrate_switch"; public static final String PREF_AUTOHEARTRATE_SLEEP = "pref_autoheartrate_sleep"; 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 796f89ebc..85d64036e 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 @@ -376,6 +376,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp addPreferenceHandlerFor(PREF_INACTIVITY_FR); addPreferenceHandlerFor(PREF_INACTIVITY_SA); addPreferenceHandlerFor(PREF_INACTIVITY_SU); + addPreferenceHandlerFor(PREF_INACTIVITY_DND); + addPreferenceHandlerFor(PREF_INACTIVITY_DND_START); + addPreferenceHandlerFor(PREF_INACTIVITY_DND_END); addPreferenceHandlerFor(PREF_AUTOHEARTRATE_SWITCH); addPreferenceHandlerFor(PREF_AUTOHEARTRATE_SLEEP); addPreferenceHandlerFor(PREF_AUTOHEARTRATE_INTERVAL); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java index dc7f0dd8d..5c143ba67 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/HuamiCoordinator.java @@ -209,33 +209,33 @@ public abstract class HuamiCoordinator extends AbstractDeviceCoordinator { public static boolean getInactivityWarnings() { Prefs prefs = GBApplication.getPrefs(); - return prefs.getBoolean(MiBandConst.PREF_MI2_INACTIVITY_WARNINGS, false); + return prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE, false); } public static int getInactivityWarningsThreshold() { Prefs prefs = GBApplication.getPrefs(); - return prefs.getInt(MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD, 60); + return prefs.getInt(DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD, 60); } public static boolean getInactivityWarningsDnd() { Prefs prefs = GBApplication.getPrefs(); - return prefs.getBoolean(MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND, false); + return prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND, false); } public static Date getInactivityWarningsStart() { - return getTimePreference(MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_START, "06:00"); + return getTimePreference(DeviceSettingsPreferenceConst.PREF_INACTIVITY_START, "06:00"); } public static Date getInactivityWarningsEnd() { - return getTimePreference(MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_END, "22:00"); + return getTimePreference(DeviceSettingsPreferenceConst.PREF_INACTIVITY_END, "22:00"); } public static Date getInactivityWarningsDndStart() { - return getTimePreference(MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_START, "12:00"); + return getTimePreference(DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_START, "12:00"); } public static Date getInactivityWarningsDndEnd() { - return getTimePreference(MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_END, "14:00"); + return getTimePreference(DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_END, "14:00"); } public static Date getDoNotDisturbStart(String deviceAddress) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java index e6e79ef1d..83cadd3a2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java @@ -36,13 +36,6 @@ public final class MiBandConst { public static final String PREF_MI2_DISPLAY_ITEM_BATTERY = "battery"; public static final String PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO = "rotate_wrist_to_cycle_info"; public static final String PREF_MI2_ENABLE_TEXT_NOTIFICATIONS = "mi2_enable_text_notifications"; - public static final String PREF_MI2_INACTIVITY_WARNINGS = "mi2_inactivity_warnings"; - public static final String PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD = "mi2_inactivity_warnings_threshold"; - public static final String PREF_MI2_INACTIVITY_WARNINGS_START = "mi2_inactivity_warnings_start"; - public static final String PREF_MI2_INACTIVITY_WARNINGS_END = "mi2_inactivity_warnings_end"; - public static final String PREF_MI2_INACTIVITY_WARNINGS_DND = "mi2_inactivity_warnings_dnd"; - public static final String PREF_MI2_INACTIVITY_WARNINGS_DND_START = "mi2_inactivity_warnings_dnd_start"; - public static final String PREF_MI2_INACTIVITY_WARNINGS_DND_END = "mi2_inactivity_warnings_dnd_end"; public static final String PREF_MIBAND_SETUP_BT_PAIRING = "mi_setup_bt_pairing"; public static final String PREF_SWIPE_UNLOCK = "swipe_unlock"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java index 8ccdc77f8..882cb0316 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java @@ -37,16 +37,16 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_START; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_END; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_START; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_END; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_ALARM_CLOCK; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_GOAL_NOTIFICATION; -import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS; -import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND; -import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_END; -import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_START; -import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_END; -import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_START; -import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.VIBRATION_COUNT; @@ -97,98 +97,98 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity { }); - final Preference inactivityWarnings = findPreference(PREF_MI2_INACTIVITY_WARNINGS); + final Preference inactivityWarnings = findPreference(PREF_INACTIVITY_ENABLE); inactivityWarnings.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { invokeLater(new Runnable() { @Override public void run() { - GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS); + GBApplication.deviceService().onSendConfiguration(PREF_INACTIVITY_ENABLE); } }); return true; } }); - final Preference inactivityWarningsThreshold = findPreference(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD); + final Preference inactivityWarningsThreshold = findPreference(PREF_INACTIVITY_THRESHOLD); inactivityWarningsThreshold.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { invokeLater(new Runnable() { @Override public void run() { - GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD); + GBApplication.deviceService().onSendConfiguration(PREF_INACTIVITY_THRESHOLD); } }); return true; } }); - final Preference inactivityWarningsStart = findPreference(PREF_MI2_INACTIVITY_WARNINGS_START); + final Preference inactivityWarningsStart = findPreference(PREF_INACTIVITY_START); inactivityWarningsStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { invokeLater(new Runnable() { @Override public void run() { - GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_START); + GBApplication.deviceService().onSendConfiguration(PREF_INACTIVITY_START); } }); return true; } }); - final Preference inactivityWarningsEnd = findPreference(PREF_MI2_INACTIVITY_WARNINGS_END); + final Preference inactivityWarningsEnd = findPreference(PREF_INACTIVITY_END); inactivityWarningsEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { invokeLater(new Runnable() { @Override public void run() { - GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_END); + GBApplication.deviceService().onSendConfiguration(PREF_INACTIVITY_END); } }); return true; } }); - final Preference inactivityWarningsDnd = findPreference(PREF_MI2_INACTIVITY_WARNINGS_DND); + final Preference inactivityWarningsDnd = findPreference(PREF_INACTIVITY_DND); inactivityWarningsDnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { invokeLater(new Runnable() { @Override public void run() { - GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_DND); + GBApplication.deviceService().onSendConfiguration(PREF_INACTIVITY_DND); } }); return true; } }); - final Preference inactivityWarningsDndStart = findPreference(PREF_MI2_INACTIVITY_WARNINGS_DND_START); + final Preference inactivityWarningsDndStart = findPreference(PREF_INACTIVITY_DND_START); inactivityWarningsDndStart.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { invokeLater(new Runnable() { @Override public void run() { - GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_DND_START); + GBApplication.deviceService().onSendConfiguration(PREF_INACTIVITY_DND_START); } }); return true; } }); - final Preference inactivityWarningsDndEnd = findPreference(PREF_MI2_INACTIVITY_WARNINGS_DND_END); + final Preference inactivityWarningsDndEnd = findPreference(PREF_INACTIVITY_DND_END); inactivityWarningsDndEnd.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { invokeLater(new Runnable() { @Override public void run() { - GBApplication.deviceService().onSendConfiguration(PREF_MI2_INACTIVITY_WARNINGS_DND_END); + GBApplication.deviceService().onSendConfiguration(PREF_INACTIVITY_DND_END); } }); return true; @@ -264,7 +264,7 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity { prefKeys.add(PREF_USER_NAME); prefKeys.add(PREF_MIBAND_ADDRESS); prefKeys.add(ActivityUser.PREF_USER_STEPS_GOAL); - prefKeys.add(PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD); + prefKeys.add(PREF_INACTIVITY_THRESHOLD); prefKeys.add(getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_ALARM_CLOCK)); prefKeys.add(getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_INCOMING_CALL)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index 2f3cb0ea3..d70e57526 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -154,6 +154,13 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_START; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_END; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DO_NOT_DISTURB_LIFT_WRIST; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_ENABLE; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_START; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_END; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_THRESHOLD; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_START; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_INACTIVITY_DND_END; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LANGUAGE; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_RESERVER_ALARMS_CALENDAR; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_RESERVER_REMINDERS_CALENDAR; @@ -2242,13 +2249,13 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { case PREF_DO_NOT_DISTURB_LIFT_WRIST: setDoNotDisturb(builder); break; - case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS: - case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_THRESHOLD: - case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_START: - case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_END: - case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND: - case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_START: - case MiBandConst.PREF_MI2_INACTIVITY_WARNINGS_DND_END: + case PREF_INACTIVITY_ENABLE: + case PREF_INACTIVITY_THRESHOLD: + case PREF_INACTIVITY_START: + case PREF_INACTIVITY_END: + case PREF_INACTIVITY_DND: + case PREF_INACTIVITY_DND_START: + case PREF_INACTIVITY_DND_END: setInactivityWarnings(builder); break; case SettingsActivity.PREF_MEASUREMENT_SYSTEM: diff --git a/app/src/main/res/xml/miband_preferences.xml b/app/src/main/res/xml/miband_preferences.xml index 2ef12c9c4..ca1ba6553 100644 --- a/app/src/main/res/xml/miband_preferences.xml +++ b/app/src/main/res/xml/miband_preferences.xml @@ -36,7 +36,7 @@ android:title="@string/prefs_title_heartrate_measurement_interval" /> @@ -48,47 +48,47 @@