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 112ff24e1..f40d5bb1e 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 @@ -35,6 +35,8 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_SCHEDULED; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_NIGHT_MODE_START; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_SWIPE_UNLOCK; +import static nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants.PREF_MOYOUNG_DEVICE_VERSION; +import static nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants.PREF_MOYOUNG_WATCH_FACE; import android.content.Context; import android.content.Intent; @@ -777,6 +779,9 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i addPreferenceHandlerFor(PREF_FEMOMETER_MEASUREMENT_MODE); + addPreferenceHandlerFor(PREF_MOYOUNG_WATCH_FACE); + addPreferenceHandlerFor(PREF_MOYOUNG_DEVICE_VERSION); + addPreferenceHandlerFor(PREF_QC35_NOISE_CANCELLING_LEVEL); addPreferenceHandlerFor(PREF_USER_FITNESS_GOAL); addPreferenceHandlerFor(PREF_USER_FITNESS_GOAL_NOTIFICATION); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java index 9fec28cca..3aee21fd7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java @@ -199,9 +199,8 @@ public abstract class AbstractMoyoungDeviceCoordinator extends AbstractBLEDevice final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings(); final List generic = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.GENERIC); generic.add(R.xml.devicesettings_moyoung_device_version); - generic.add(R.xml.devicesettings_colmi_r0x); + generic.add(R.xml.devicesettings_heartrate_interval); generic.add(R.xml.devicesettings_timeformat); - generic.add(R.xml.devicesettings_measurementsystem); generic.add(R.xml.devicesettings_moyoung_watchface); generic.add(R.xml.devicesettings_liftwrist_display); generic.add(R.xml.devicesettings_moyoung_sedentary_reminder); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungConstants.java index de722d697..18d2809c7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungConstants.java @@ -402,10 +402,10 @@ public class MoyoungConstants { } - public static final String PREF_WATCH_FACE = "moyoung_watch_face"; + public static final String PREF_MOYOUNG_WATCH_FACE = "moyoung_watch_face"; public static final String PREF_LANGUAGE = "moyoung_language"; public static final String PREF_LANGUAGE_SUPPORT = "moyoung_language_supported"; - public static final String PREF_DEVICE_VERSION = "moyoung_device_version"; + public static final String PREF_MOYOUNG_DEVICE_VERSION = "moyoung_device_version"; public static final String PREF_SEDENTARY_REMINDER = "sedentary_reminder"; public static final String PREF_SEDENTARY_REMINDER_PERIOD = "sedentary_reminder_period"; public static final String PREF_SEDENTARY_REMINDER_STEPS = "sedentary_reminder_steps"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungDeviceSupport.java index 7fac3ba90..e0370dc05 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungDeviceSupport.java @@ -50,6 +50,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.Logging; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils; +import nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; @@ -57,6 +58,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInf import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl; +import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.AbstractMoyoungDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants; @@ -68,6 +70,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungHeart import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.samples.MoyoungSpo2SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumDeviceVersion; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumLanguage; +import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumMetricSystem; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumTimeSystem; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSetting; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSettingEnum; @@ -175,6 +178,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { builder.notify(getCharacteristic(MoyoungConstants.UUID_CHARACTERISTIC_DATA_IN), true); deviceInfoProfile.requestDeviceInfo(builder); setTime(builder); + setMeasurementSystem(builder); sendSetting(builder, getSetting("USER_INFO"), new ActivityUser()); // these settings are write-only, so write them just in case because there is no way to know if they desynced somehow sendSetting(builder, getSetting("GOAL_STEP"), new ActivityUser().getStepsGoal()); batteryInfoProfile.requestBatteryInfo(builder); @@ -435,6 +439,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { if (packetType == MoyoungConstants.CMD_QUERY_DISPLAY_WATCH_FACE) { LOG.info("Watchface changed on watch to nr {}", payload[0]); + onReadConfigurationDone(getSetting("DISPLAY_WATCH_FACE"), payload[0], null); return true; } @@ -541,6 +546,26 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { sendNotification(MoyoungConstants.NOTIFICATION_TYPE_CALL_OFF_HOOK, ""); } + private void setMeasurementSystem(TransactionBuilder builder) { + Prefs prefs = GBApplication.getPrefs(); + String unit = prefs.getString(SettingsActivity.PREF_MEASUREMENT_SYSTEM, GBApplication.getContext().getString(R.string.p_unit_metric)); + + MoyoungEnumMetricSystem metricSystem = null; + if (unit.equals(getContext().getString(R.string.p_unit_metric))) + metricSystem = MoyoungEnumMetricSystem.METRIC_SYSTEM; + else if (unit.equals(getContext().getString(R.string.p_unit_imperial))) + metricSystem = MoyoungEnumMetricSystem.IMPERIAL_SYSTEM; + else + LOG.warn("Invalid unit preference: {}", unit); + + if (metricSystem != null) { + if (builder == null) + sendSetting(getSetting("METRIC_SYSTEM"), metricSystem); + else + sendSetting(builder, getSetting("METRIC_SYSTEM"), metricSystem); + } + } + private void setTime(TransactionBuilder builder) { ByteBuffer buffer = ByteBuffer.allocate(5); buffer.putInt(MoyoungConstants.LocalTimeToWatchTime(new Date())); // The watch is hardcoded to GMT+8 internally... @@ -1285,22 +1310,12 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { sendSetting(getSetting("TIME_SYSTEM"), timeSystem); break; -// case DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM: -// String metricSystemPref = prefs.getString(DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM, getContext().getString(R.string.p_unit_metric)); -// -// MoyoungEnumMetricSystem metricSystem; -// if (metricSystemPref.equals(getContext().getString(R.string.p_unit_metric))) -// metricSystem = MoyoungEnumMetricSystem.METRIC_SYSTEM; -// else if (metricSystemPref.equals(getContext().getString(R.string.p_unit_imperial))) -// metricSystem = MoyoungEnumMetricSystem.IMPERIAL_SYSTEM; -// else -// throw new IllegalArgumentException(); -// -// sendSetting(getSetting("METRIC_SYSTEM"), metricSystem); -// break; + case SettingsActivity.PREF_MEASUREMENT_SYSTEM: + setMeasurementSystem(null); + break; - case MoyoungConstants.PREF_WATCH_FACE: - String watchFacePref = prefs.getString(MoyoungConstants.PREF_WATCH_FACE, String.valueOf(1)); + case MoyoungConstants.PREF_MOYOUNG_WATCH_FACE: + String watchFacePref = prefs.getString(MoyoungConstants.PREF_MOYOUNG_WATCH_FACE, String.valueOf(1)); byte watchFace = Byte.valueOf(watchFacePref); sendSetting(getSetting("DISPLAY_WATCH_FACE"), watchFace); break; @@ -1364,8 +1379,8 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { sendSetting(languageSetting, languageSetting.findByValue(languageCode)); break; - case MoyoungConstants.PREF_DEVICE_VERSION: - String versionPref = prefs.getString(MoyoungConstants.PREF_DEVICE_VERSION, + case MoyoungConstants.PREF_MOYOUNG_DEVICE_VERSION: + String versionPref = prefs.getString(MoyoungConstants.PREF_MOYOUNG_DEVICE_VERSION, String.valueOf(MoyoungEnumDeviceVersion.INTERNATIONAL_EDITION.value())); byte versionNum = Byte.valueOf(versionPref); MoyoungSettingEnum versionSetting = getSetting("DEVICE_VERSION"); @@ -1463,7 +1478,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { // querySetting(getSetting("METRIC_SYSTEM")); // break; - case MoyoungConstants.PREF_WATCH_FACE: + case MoyoungConstants.PREF_MOYOUNG_WATCH_FACE: querySetting(getSetting("DISPLAY_WATCH_FACE")); break; @@ -1471,7 +1486,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { querySetting(getSetting("DEVICE_LANGUAGE")); break; - case MoyoungConstants.PREF_DEVICE_VERSION: + case MoyoungConstants.PREF_MOYOUNG_DEVICE_VERSION: querySetting(getSetting("DEVICE_VERSION")); break; @@ -1511,18 +1526,19 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { public void onReadConfigurationDone(MoyoungSetting setting, Object value, byte[] data) { LOG.info("CONFIG " + setting.name + " = " + value); - Prefs prefs = getDevicePrefs(); - Map changedProperties = new ArrayMap<>(); - SharedPreferences.Editor prefsEditor = prefs.getPreferences().edit(); + final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences(); +// Prefs prefs = getDevicePrefs(); +// Map changedProperties = new ArrayMap<>(); +// SharedPreferences.Editor prefsEditor = prefs.getPreferences().edit(); switch (setting.name) { case "TIME_SYSTEM": MoyoungEnumTimeSystem timeSystem = (MoyoungEnumTimeSystem) value; - if (timeSystem == MoyoungEnumTimeSystem.TIME_SYSTEM_24) - changedProperties.put(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h)); - else if (timeSystem == MoyoungEnumTimeSystem.TIME_SYSTEM_12) - changedProperties.put(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_am_pm)); - else - throw new IllegalArgumentException("Invalid value"); +// if (timeSystem == MoyoungEnumTimeSystem.TIME_SYSTEM_24) +// changedProperties.put(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h)); +// else if (timeSystem == MoyoungEnumTimeSystem.TIME_SYSTEM_12) +// changedProperties.put(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_am_pm)); +// else +// throw new IllegalArgumentException("Invalid value"); break; // case "METRIC_SYSTEM": @@ -1536,23 +1552,28 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { // break; case "DISPLAY_WATCH_FACE": - byte watchFace = (Byte) value; - changedProperties.put(MoyoungConstants.PREF_WATCH_FACE, String.valueOf(watchFace)); +// byte watchFace = (Byte) value; +// changedProperties.put(MoyoungConstants.PREF_MOYOUNG_WATCH_FACE, String.valueOf(watchFace)); + eventUpdatePreferences.withPreference( + MoyoungConstants.PREF_MOYOUNG_WATCH_FACE, + String.valueOf((byte) value) + ); + evaluateGBDeviceEvent(eventUpdatePreferences); break; case "DEVICE_LANGUAGE": MoyoungEnumLanguage language = (MoyoungEnumLanguage) value; - changedProperties.put(MoyoungConstants.PREF_LANGUAGE, String.valueOf(language.value())); - MoyoungEnumLanguage[] supportedLanguages = ((MoyoungSettingLanguage) setting).decodeSupportedValues(data); - Set supportedLanguagesList = new HashSet<>(); - for(MoyoungEnumLanguage supportedLanguage : supportedLanguages) - supportedLanguagesList.add(String.valueOf(supportedLanguage.value())); - prefsEditor.putStringSet(MoyoungConstants.PREF_LANGUAGE_SUPPORT, supportedLanguagesList); +// changedProperties.put(MoyoungConstants.PREF_LANGUAGE, String.valueOf(language.value())); +// MoyoungEnumLanguage[] supportedLanguages = ((MoyoungSettingLanguage) setting).decodeSupportedValues(data); +// Set supportedLanguagesList = new HashSet<>(); +// for(MoyoungEnumLanguage supportedLanguage : supportedLanguages) +// supportedLanguagesList.add(String.valueOf(supportedLanguage.value())); +// prefsEditor.putStringSet(MoyoungConstants.PREF_LANGUAGE_SUPPORT, supportedLanguagesList); break; case "DEVICE_VERSION": MoyoungEnumDeviceVersion deviceVersion = (MoyoungEnumDeviceVersion) value; - changedProperties.put(MoyoungConstants.PREF_DEVICE_VERSION, String.valueOf(deviceVersion.value())); +// changedProperties.put(MoyoungConstants.PREF_MOYOUNG_DEVICE_VERSION, String.valueOf(deviceVersion.value())); break; // case "DO_NOT_DISTURB_TIME": @@ -1589,20 +1610,20 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { case "SEDENTARY_REMINDER": boolean sedentaryReminderEnabled = (Boolean) value; - changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER, sedentaryReminderEnabled ? "on": "off"); +// changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER, sedentaryReminderEnabled ? "on": "off"); break; case "REMINDERS_TO_MOVE_PERIOD": MoyoungSettingRemindersToMove.RemindersToMove remindersToMove = (MoyoungSettingRemindersToMove.RemindersToMove) value; - changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_PERIOD, String.valueOf(remindersToMove.period)); - changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_STEPS, String.valueOf(remindersToMove.steps)); - changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_START, String.valueOf(remindersToMove.start_h)); - changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_END, String.valueOf(remindersToMove.end_h)); +// changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_PERIOD, String.valueOf(remindersToMove.period)); +// changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_STEPS, String.valueOf(remindersToMove.steps)); +// changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_START, String.valueOf(remindersToMove.start_h)); +// changedProperties.put(MoyoungConstants.PREF_SEDENTARY_REMINDER_END, String.valueOf(remindersToMove.end_h)); break; } - for (Map.Entry property : changedProperties.entrySet()) - prefsEditor.putString(property.getKey(), property.getValue()); - prefsEditor.apply(); +// for (Map.Entry property : changedProperties.entrySet()) +// prefsEditor.putString(property.getKey(), property.getValue()); +// prefsEditor.apply(); // for (Map.Entry property : changedProperties.entrySet()) // { // GBDeviceEventConfigurationRead configReadEvent = new GBDeviceEventConfigurationRead(); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index d49f3f6c6..23428f238 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -2645,6 +2645,7 @@ Watch face 8 Watch face 9 Watch face 10 + Watch face 11 @@ -2658,6 +2659,7 @@ 8 9 10 + 11 diff --git a/app/src/main/res/xml/devicesettings_heartrate_interval.xml b/app/src/main/res/xml/devicesettings_heartrate_interval.xml new file mode 100644 index 000000000..c2d0dac0f --- /dev/null +++ b/app/src/main/res/xml/devicesettings_heartrate_interval.xml @@ -0,0 +1,11 @@ + + + + diff --git a/app/src/main/res/xml/devicesettings_measurementsystem.xml b/app/src/main/res/xml/devicesettings_measurementsystem.xml deleted file mode 100644 index f324f3fa4..000000000 --- a/app/src/main/res/xml/devicesettings_measurementsystem.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/app/src/main/res/xml/devicesettings_moyoung_device_version.xml b/app/src/main/res/xml/devicesettings_moyoung_device_version.xml index 96db58259..b30112db9 100644 --- a/app/src/main/res/xml/devicesettings_moyoung_device_version.xml +++ b/app/src/main/res/xml/devicesettings_moyoung_device_version.xml @@ -6,5 +6,6 @@ android:entryValues="@array/pref_moyoung_device_version_values" android:key="moyoung_device_version" android:summary="%s" - android:title="@string/pref_device_version" /> + android:title="@string/pref_device_version" + android:icon="@drawable/ic_language" />