From c5102bdf707a42958d4db3d406f341a74b20dc4f Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Mon, 19 Aug 2024 23:18:20 +0200 Subject: [PATCH] Moyoung: Modernize classes and methods and fix compiler errors --- .../gadgetbridge/daogen/GBDaoGenerator.java | 8 +- ... => AbstractMoyoungDeviceCoordinator.java} | 87 +--- .../moyoung/ColmiI28UltraCoordinator.java | 43 ++ .../moyoung/MoyoungSampleProvider.java | 32 +- .../moyoung/MoyoungWeatherForecast.java | 2 +- .../gadgetbridge/model/DeviceType.java | 2 + .../devices/moyoung/FetchDataOperation.java | 2 +- .../devices/moyoung/MoyoungDeviceSupport.java | 405 +++++++----------- .../moyoung/QuerySettingsOperation.java | 5 +- .../TrainingFinishedDataOperation.java | 8 +- .../gadgetbridge/util/ArrayUtils.java | 2 + app/src/main/res/values/strings.xml | 1 + ...devicesettings_donotdisturb_no_auto_v2.xml | 1 - ...icesettings_moyoung_sedentary_reminder.xml | 1 - 14 files changed, 237 insertions(+), 362 deletions(-) rename app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/{MoyoungDeviceCoordinator.java => AbstractMoyoungDeviceCoordinator.java} (80%) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index 733192d08..f8e56204c 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -1041,14 +1041,14 @@ public class GBDaoGenerator { Entity activitySample = addEntity(schema, "MoyoungActivitySample"); activitySample.implementsSerializable(); addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device); - activitySample.addIntProperty(SAMPLE_STEPS).notNull().codeBeforeGetterAndSetter(OVERRIDE).codeBeforeGetter("@Override\n public int getRawIntensity() {\n return getSteps();\n }\n\n"); + activitySample.addIntProperty(SAMPLE_STEPS).notNull().codeBeforeGetterAndSetter(OVERRIDE); activitySample.addIntProperty(SAMPLE_RAW_KIND).notNull().codeBeforeGetterAndSetter(OVERRIDE); activitySample.addIntProperty("dataSource").notNull(); activitySample.addIntProperty("caloriesBurnt").notNull(); activitySample.addIntProperty("distanceMeters").notNull(); - addHeartRateProperties(activitySample); - addBloodPressureProperies(activitySample); - addBloodOxidationProperies(activitySample); +// addHeartRateProperties(activitySample); +// addBloodPressureProperies(activitySample); +// addBloodOxidationProperies(activitySample); activitySample.addIntProperty("batteryLevel").notNull(); return activitySample; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java similarity index 80% rename from app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungDeviceCoordinator.java rename to app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java index 9c0a2ad40..daec1b4a8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java @@ -17,15 +17,11 @@ package nodomain.freeyourgadget.gadgetbridge.devices.moyoung; import android.annotation.TargetApi; -import android.app.Activity; import android.bluetooth.le.ScanFilter; -import android.content.Context; -import android.net.Uri; import android.os.Build; import android.os.ParcelUuid; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import java.util.Collection; import java.util.Collections; @@ -33,7 +29,6 @@ import java.util.Collections; import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; -import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumDeviceVersion; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungEnumMetricSystem; @@ -50,21 +45,11 @@ import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSett import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; -import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; -import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; +import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; +import nodomain.freeyourgadget.gadgetbridge.service.devices.moyoung.MoyoungDeviceSupport; -public class MoyoungDeviceCoordinator extends AbstractDeviceCoordinator { - - @Override - public DeviceType getDeviceType() { - return DeviceType.DAFIT; - } - - @Override - public String getManufacturer() { - return "Media-Tech"; - } +public abstract class AbstractMoyoungDeviceCoordinator extends AbstractDeviceCoordinator { @NonNull @Override @@ -77,12 +62,8 @@ public class MoyoungDeviceCoordinator extends AbstractDeviceCoordinator { @NonNull @Override - public DeviceType getSupportedType(GBDeviceCandidate candidate) { - // TODO: It would be nice to also filter on "manufacturer" (which is used as a protocol version) being MOYOUNG-V2 or MOYOUNG but I have no idea if it's possible to do that at this point - if (candidate.supportsService(MoyoungConstants.UUID_SERVICE_MOYOUNG)) { - return DeviceType.DAFIT; - } - return DeviceType.UNKNOWN; + public Class getDeviceSupportClass() { + return MoyoungDeviceSupport.class; } @Override @@ -90,15 +71,9 @@ public class MoyoungDeviceCoordinator extends AbstractDeviceCoordinator { return BONDING_STYLE_NONE; } - @Nullable - @Override - public Class getPairingActivity() { - return null; - } - @Override protected void deleteDevice(@NonNull GBDevice gbDevice, @NonNull Device device, @NonNull DaoSession session) throws GBException { - + // TODO: remove device specific data } @Override @@ -117,43 +92,18 @@ public class MoyoungDeviceCoordinator extends AbstractDeviceCoordinator { } @Override - public InstallHandler findInstallHandler(Uri uri, Context context) { - return null; - } - - @Override - public boolean supportsScreenshots() { - return false; - } - - @Override - public int getAlarmSlotCount() { + public int getAlarmSlotCount(GBDevice device) { return 3; } - @Override - public boolean supportsSmartWakeup(GBDevice device) { - return false; - } - @Override public boolean supportsHeartRateMeasurement(GBDevice device) { return true; } - @Override - public boolean supportsAppsManagement() { - return false; - } - - @Override - public Class getAppsManagementActivity() { - return null; - } - @Override public boolean supportsCalendarEvents() { - return false; + return true; } @Override @@ -178,28 +128,9 @@ public class MoyoungDeviceCoordinator extends AbstractDeviceCoordinator { @Override public boolean supportsMusicInfo() { - return false; + return true; } - @Override - public boolean supportsLedColor() { - return false; - } - - @Override - public boolean supportsRgbLedColor() { - return false; - } - - @NonNull - @Override - public int[] getColorPresets() { - return new int[0]; - } - - @Override - public boolean supportsUnicodeEmojis() { return false; } - private static final MoyoungSetting[] MOYOUNG_SETTINGS = new MoyoungSetting[] { new MoyoungSettingUserInfo("USER_INFO", MoyoungConstants.CMD_SET_USER_INFO), new MoyoungSettingByte("STEP_LENGTH", (byte)-1, MoyoungConstants.CMD_SET_STEP_LENGTH), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java new file mode 100644 index 000000000..169e11979 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java @@ -0,0 +1,43 @@ +/* Copyright (C) 2024 Arjan Schrijver + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ +package nodomain.freeyourgadget.gadgetbridge.devices.moyoung; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.regex.Pattern; + +import nodomain.freeyourgadget.gadgetbridge.R; + +public class ColmiI28UltraCoordinator extends AbstractMoyoungDeviceCoordinator { + private static final Logger LOG = LoggerFactory.getLogger(ColmiI28UltraCoordinator.class); + + @Override + protected Pattern getSupportedDeviceName() { + return Pattern.compile("i28 Ultra"); + } + + @Override + public int getDeviceNameResource() { + return R.string.devicetype_colmi_i28_ultra; + } + + @Override + public String getManufacturer() { + return "Colmi"; + } +} \ No newline at end of file diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungSampleProvider.java index 29f96d4d4..cb00145e7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/MoyoungSampleProvider.java @@ -98,41 +98,41 @@ public class MoyoungSampleProvider extends AbstractSampleProvider Celcius diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java index 1cc63d99a..2dd953e5e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceType.java @@ -221,6 +221,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.mijia_lywsd.MijiaMhoC303Coor import nodomain.freeyourgadget.gadgetbridge.devices.miscale.MiSmartScaleCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.miscale.MiCompositionScaleCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.moondrop.MoondropSpaceTravelCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.ColmiI28UltraCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.no1f1.No1F1Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.nothing.CmfBudsPro2Coordinator; import nodomain.freeyourgadget.gadgetbridge.devices.nothing.Ear1Coordinator; @@ -558,6 +559,7 @@ public enum DeviceType { COLMI_R03(ColmiR03Coordinator.class), COLMI_R06(ColmiR06Coordinator.class), COLMI_R10(ColmiR10Coordinator.class), + COLMI_I28_ULTRA(ColmiI28UltraCoordinator.class), B_AND_W_P_SERIES(BandWPSeriesDeviceCoordinator.class), SCANNABLE(ScannableDeviceCoordinator.class), CYCLING_SENSOR(CyclingSensorCoordinator.class), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java index 8eb18e990..043ae2197 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java @@ -205,7 +205,7 @@ public class FetchDataOperation extends AbstractBTLEOperation T getSetting(String id) { - MoyoungDeviceCoordinator coordinator = (MoyoungDeviceCoordinator) DeviceHelper.getInstance().getCoordinator(getDevice()); + AbstractMoyoungDeviceCoordinator coordinator = (AbstractMoyoungDeviceCoordinator) getDevice().getDeviceCoordinator(); for(MoyoungSetting setting : coordinator.getSupportedSettings()) { if (setting.name.equals(id)) @@ -1274,19 +1182,19 @@ 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 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 MoyoungConstants.PREF_WATCH_FACE: String watchFacePref = prefs.getString(MoyoungConstants.PREF_WATCH_FACE, String.valueOf(1)); @@ -1310,47 +1218,47 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { sendSetting(versionSetting, versionSetting.findByValue(versionNum)); break; - case MiBandConst.PREF_DO_NOT_DISTURB: - case MiBandConst.PREF_DO_NOT_DISTURB_START: - case MiBandConst.PREF_DO_NOT_DISTURB_END: - String doNotDisturbPref = prefs.getString(MiBandConst.PREF_DO_NOT_DISTURB, MiBandConst.PREF_DO_NOT_DISTURB_OFF); - boolean doNotDisturbEnabled = !MiBandConst.PREF_DO_NOT_DISTURB_OFF.equals(doNotDisturbPref); +// case MiBandConst.PREF_DO_NOT_DISTURB: +// case MiBandConst.PREF_DO_NOT_DISTURB_START: +// case MiBandConst.PREF_DO_NOT_DISTURB_END: +// String doNotDisturbPref = prefs.getString(MiBandConst.PREF_DO_NOT_DISTURB, MiBandConst.PREF_DO_NOT_DISTURB_OFF); +// boolean doNotDisturbEnabled = !MiBandConst.PREF_DO_NOT_DISTURB_OFF.equals(doNotDisturbPref); +// +// Calendar doNotDisturbStart = getTimePref(prefs, MiBandConst.PREF_DO_NOT_DISTURB_START, "01:00"); +// Calendar doNotDisturbEnd = getTimePref(prefs, MiBandConst.PREF_DO_NOT_DISTURB_END, "06:00"); +// +// MoyoungSettingTimeRange.TimeRange doNotDisturb; +// if (doNotDisturbEnabled) +// doNotDisturb = new MoyoungSettingTimeRange.TimeRange( +// (byte) doNotDisturbStart.get(Calendar.HOUR_OF_DAY), (byte) doNotDisturbStart.get(Calendar.MINUTE), +// (byte) doNotDisturbEnd.get(Calendar.HOUR_OF_DAY), (byte) doNotDisturbEnd.get(Calendar.MINUTE)); +// else +// doNotDisturb = new MoyoungSettingTimeRange.TimeRange((byte)0, (byte)0, (byte)0, (byte)0); +// +// sendSetting(getSetting("DO_NOT_DISTURB_TIME"), doNotDisturb); +// break; - Calendar doNotDisturbStart = getTimePref(prefs, MiBandConst.PREF_DO_NOT_DISTURB_START, "01:00"); - Calendar doNotDisturbEnd = getTimePref(prefs, MiBandConst.PREF_DO_NOT_DISTURB_END, "06:00"); - - MoyoungSettingTimeRange.TimeRange doNotDisturb; - if (doNotDisturbEnabled) - doNotDisturb = new MoyoungSettingTimeRange.TimeRange( - (byte) doNotDisturbStart.get(Calendar.HOUR_OF_DAY), (byte) doNotDisturbStart.get(Calendar.MINUTE), - (byte) doNotDisturbEnd.get(Calendar.HOUR_OF_DAY), (byte) doNotDisturbEnd.get(Calendar.MINUTE)); - else - doNotDisturb = new MoyoungSettingTimeRange.TimeRange((byte)0, (byte)0, (byte)0, (byte)0); - - sendSetting(getSetting("DO_NOT_DISTURB_TIME"), doNotDisturb); - break; - - case HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT: - case HuamiConst.PREF_DISPLAY_ON_LIFT_START: - case HuamiConst.PREF_DISPLAY_ON_LIFT_END: - String quickViewPref = prefs.getString(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, MiBandConst.PREF_DO_NOT_DISTURB_OFF); - boolean quickViewEnabled = !quickViewPref.equals(getContext().getString(R.string.p_off)); - boolean quickViewScheduled = quickViewPref.equals(getContext().getString(R.string.p_scheduled)); - - Calendar quickViewStart = getTimePref(prefs, HuamiConst.PREF_DISPLAY_ON_LIFT_START, "00:00"); - Calendar quickViewEnd = getTimePref(prefs, HuamiConst.PREF_DISPLAY_ON_LIFT_END, "00:00"); - - MoyoungSettingTimeRange.TimeRange quickViewTime; - if (quickViewEnabled && quickViewScheduled) - quickViewTime = new MoyoungSettingTimeRange.TimeRange( - (byte) quickViewStart.get(Calendar.HOUR_OF_DAY), (byte) quickViewStart.get(Calendar.MINUTE), - (byte) quickViewEnd.get(Calendar.HOUR_OF_DAY), (byte) quickViewEnd.get(Calendar.MINUTE)); - else - quickViewTime = new MoyoungSettingTimeRange.TimeRange((byte)0, (byte)0, (byte)0, (byte)0); - - sendSetting(getSetting("QUICK_VIEW"), quickViewEnabled); - sendSetting(getSetting("QUICK_VIEW_TIME"), quickViewTime); - break; +// case HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT: +// case HuamiConst.PREF_DISPLAY_ON_LIFT_START: +// case HuamiConst.PREF_DISPLAY_ON_LIFT_END: +// String quickViewPref = prefs.getString(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, MiBandConst.PREF_DO_NOT_DISTURB_OFF); +// boolean quickViewEnabled = !quickViewPref.equals(getContext().getString(R.string.p_off)); +// boolean quickViewScheduled = quickViewPref.equals(getContext().getString(R.string.p_scheduled)); +// +// Calendar quickViewStart = getTimePref(prefs, HuamiConst.PREF_DISPLAY_ON_LIFT_START, "00:00"); +// Calendar quickViewEnd = getTimePref(prefs, HuamiConst.PREF_DISPLAY_ON_LIFT_END, "00:00"); +// +// MoyoungSettingTimeRange.TimeRange quickViewTime; +// if (quickViewEnabled && quickViewScheduled) +// quickViewTime = new MoyoungSettingTimeRange.TimeRange( +// (byte) quickViewStart.get(Calendar.HOUR_OF_DAY), (byte) quickViewStart.get(Calendar.MINUTE), +// (byte) quickViewEnd.get(Calendar.HOUR_OF_DAY), (byte) quickViewEnd.get(Calendar.MINUTE)); +// else +// quickViewTime = new MoyoungSettingTimeRange.TimeRange((byte)0, (byte)0, (byte)0, (byte)0); +// +// sendSetting(getSetting("QUICK_VIEW"), quickViewEnabled); +// sendSetting(getSetting("QUICK_VIEW_TIME"), quickViewTime); +// break; case MoyoungConstants.PREF_SEDENTARY_REMINDER: String sedentaryReminderPref = prefs.getString(MoyoungConstants.PREF_SEDENTARY_REMINDER, "off"); @@ -1397,9 +1305,9 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { querySetting(getSetting("TIME_SYSTEM")); break; - case DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM: - querySetting(getSetting("METRIC_SYSTEM")); - break; +// case DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM: +// querySetting(getSetting("METRIC_SYSTEM")); +// break; case MoyoungConstants.PREF_WATCH_FACE: querySetting(getSetting("DISPLAY_WATCH_FACE")); @@ -1413,18 +1321,18 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { querySetting(getSetting("DEVICE_VERSION")); break; - case MiBandConst.PREF_DO_NOT_DISTURB: - case MiBandConst.PREF_DO_NOT_DISTURB_START: - case MiBandConst.PREF_DO_NOT_DISTURB_END: - querySetting(getSetting("DO_NOT_DISTURB_TIME")); - break; +// case MiBandConst.PREF_DO_NOT_DISTURB: +// case MiBandConst.PREF_DO_NOT_DISTURB_START: +// case MiBandConst.PREF_DO_NOT_DISTURB_END: +// querySetting(getSetting("DO_NOT_DISTURB_TIME")); +// break; - case HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT: - case HuamiConst.PREF_DISPLAY_ON_LIFT_START: - case HuamiConst.PREF_DISPLAY_ON_LIFT_END: - querySetting(getSetting("QUICK_VIEW")); - querySetting(getSetting("QUICK_VIEW_TIME")); - break; +// case HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT: +// case HuamiConst.PREF_DISPLAY_ON_LIFT_START: +// case HuamiConst.PREF_DISPLAY_ON_LIFT_END: +// querySetting(getSetting("QUICK_VIEW")); +// querySetting(getSetting("QUICK_VIEW_TIME")); +// break; case MoyoungConstants.PREF_SEDENTARY_REMINDER: querySetting(getSetting("SEDENTARY_REMINDER")); @@ -1440,10 +1348,10 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { return; } - GBDeviceEventConfigurationRead configReadEvent = new GBDeviceEventConfigurationRead(); - configReadEvent.config = config; - configReadEvent.event = GBDeviceEventConfigurationRead.Event.IN_PROGRESS; - evaluateGBDeviceEvent(configReadEvent); +// GBDeviceEventConfigurationRead configReadEvent = new GBDeviceEventConfigurationRead(); +// configReadEvent.config = config; +// configReadEvent.event = GBDeviceEventConfigurationRead.Event.IN_PROGRESS; +// evaluateGBDeviceEvent(configReadEvent); } public void onReadConfigurationDone(MoyoungSetting setting, Object value, byte[] data) @@ -1463,15 +1371,15 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { throw new IllegalArgumentException("Invalid value"); break; - case "METRIC_SYSTEM": - MoyoungEnumMetricSystem metricSystem = (MoyoungEnumMetricSystem) value; - if (metricSystem == MoyoungEnumMetricSystem.METRIC_SYSTEM) - changedProperties.put(DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM, getContext().getString(R.string.p_unit_metric)); - else if (metricSystem == MoyoungEnumMetricSystem.IMPERIAL_SYSTEM) - changedProperties.put(DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM, getContext().getString(R.string.p_unit_imperial)); - else - throw new IllegalArgumentException("Invalid value"); - break; +// case "METRIC_SYSTEM": +// MoyoungEnumMetricSystem metricSystem = (MoyoungEnumMetricSystem) value; +// if (metricSystem == MoyoungEnumMetricSystem.METRIC_SYSTEM) +// changedProperties.put(DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM, getContext().getString(R.string.p_unit_metric)); +// else if (metricSystem == MoyoungEnumMetricSystem.IMPERIAL_SYSTEM) +// changedProperties.put(DeviceSettingsPreferenceConst.PREF_MEASUREMENTSYSTEM, getContext().getString(R.string.p_unit_imperial)); +// else +// throw new IllegalArgumentException("Invalid value"); +// break; case "DISPLAY_WATCH_FACE": byte watchFace = (Byte) value; @@ -1493,37 +1401,37 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { changedProperties.put(MoyoungConstants.PREF_DEVICE_VERSION, String.valueOf(deviceVersion.value())); break; - case "DO_NOT_DISTURB_TIME": - MoyoungSettingTimeRange.TimeRange doNotDisturb = (MoyoungSettingTimeRange.TimeRange) value; - if (doNotDisturb.start_h == 0 && doNotDisturb.start_m == 0 && - doNotDisturb.end_h == 0 && doNotDisturb.end_m == 0) - changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB, MiBandConst.PREF_DO_NOT_DISTURB_OFF); - else - changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB, MiBandConst.PREF_DO_NOT_DISTURB_SCHEDULED); - changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB_START, String.format(Locale.ROOT, "%02d:%02d", doNotDisturb.start_h, doNotDisturb.start_m)); - changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB_END, String.format(Locale.ROOT, "%02d:%02d", doNotDisturb.end_h, doNotDisturb.end_m)); - break; +// case "DO_NOT_DISTURB_TIME": +// MoyoungSettingTimeRange.TimeRange doNotDisturb = (MoyoungSettingTimeRange.TimeRange) value; +// if (doNotDisturb.start_h == 0 && doNotDisturb.start_m == 0 && +// doNotDisturb.end_h == 0 && doNotDisturb.end_m == 0) +// changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB, MiBandConst.PREF_DO_NOT_DISTURB_OFF); +// else +// changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB, MiBandConst.PREF_DO_NOT_DISTURB_SCHEDULED); +// changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB_START, String.format(Locale.ROOT, "%02d:%02d", doNotDisturb.start_h, doNotDisturb.start_m)); +// changedProperties.put(MiBandConst.PREF_DO_NOT_DISTURB_END, String.format(Locale.ROOT, "%02d:%02d", doNotDisturb.end_h, doNotDisturb.end_m)); +// break; - case "QUICK_VIEW": - boolean quickViewEnabled = (Boolean) value; - boolean quickViewScheduled = prefs.getString(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_off)).equals(getContext().getString(R.string.p_scheduled)); - changedProperties.put(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, quickViewEnabled ? (quickViewScheduled ? getContext().getString(R.string.p_scheduled) : getContext().getString(R.string.p_on)) : getContext().getString(R.string.p_off)); - break; +// case "QUICK_VIEW": +// boolean quickViewEnabled = (Boolean) value; +// boolean quickViewScheduled = prefs.getString(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_off)).equals(getContext().getString(R.string.p_scheduled)); +// changedProperties.put(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, quickViewEnabled ? (quickViewScheduled ? getContext().getString(R.string.p_scheduled) : getContext().getString(R.string.p_on)) : getContext().getString(R.string.p_off)); +// break; - case "QUICK_VIEW_TIME": - boolean quickViewEnabled2 = !prefs.getString(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_off)).equals(getContext().getString(R.string.p_off)); - MoyoungSettingTimeRange.TimeRange quickViewTime = (MoyoungSettingTimeRange.TimeRange) value; - if (quickViewEnabled2) - { - if (quickViewTime.start_h == 0 && quickViewTime.start_m == 0 && - quickViewTime.end_h == 0 && quickViewTime.end_m == 0) - changedProperties.put(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_on)); - else - changedProperties.put(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_scheduled)); - } - changedProperties.put(HuamiConst.PREF_DISPLAY_ON_LIFT_START, String.format(Locale.ROOT, "%02d:%02d", quickViewTime.start_h, quickViewTime.start_m)); - changedProperties.put(HuamiConst.PREF_DISPLAY_ON_LIFT_END, String.format(Locale.ROOT, "%02d:%02d", quickViewTime.end_h, quickViewTime.end_m)); - break; +// case "QUICK_VIEW_TIME": +// boolean quickViewEnabled2 = !prefs.getString(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_off)).equals(getContext().getString(R.string.p_off)); +// MoyoungSettingTimeRange.TimeRange quickViewTime = (MoyoungSettingTimeRange.TimeRange) value; +// if (quickViewEnabled2) +// { +// if (quickViewTime.start_h == 0 && quickViewTime.start_m == 0 && +// quickViewTime.end_h == 0 && quickViewTime.end_m == 0) +// changedProperties.put(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_on)); +// else +// changedProperties.put(HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT, getContext().getString(R.string.p_scheduled)); +// } +// changedProperties.put(HuamiConst.PREF_DISPLAY_ON_LIFT_START, String.format(Locale.ROOT, "%02d:%02d", quickViewTime.start_h, quickViewTime.start_m)); +// changedProperties.put(HuamiConst.PREF_DISPLAY_ON_LIFT_END, String.format(Locale.ROOT, "%02d:%02d", quickViewTime.end_h, quickViewTime.end_m)); +// break; case "SEDENTARY_REMINDER": boolean sedentaryReminderEnabled = (Boolean) value; @@ -1541,13 +1449,13 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { for (Map.Entry property : changedProperties.entrySet()) prefsEditor.putString(property.getKey(), property.getValue()); prefsEditor.apply(); - for (Map.Entry property : changedProperties.entrySet()) - { - GBDeviceEventConfigurationRead configReadEvent = new GBDeviceEventConfigurationRead(); - configReadEvent.config = property.getKey(); - configReadEvent.event = GBDeviceEventConfigurationRead.Event.SUCCESS; - evaluateGBDeviceEvent(configReadEvent); - } +// for (Map.Entry property : changedProperties.entrySet()) +// { +// GBDeviceEventConfigurationRead configReadEvent = new GBDeviceEventConfigurationRead(); +// configReadEvent.config = property.getKey(); +// configReadEvent.event = GBDeviceEventConfigurationRead.Event.SUCCESS; +// evaluateGBDeviceEvent(configReadEvent); +// } } @Override @@ -1555,13 +1463,14 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { try { new QuerySettingsOperation(this).perform(); } catch (IOException e) { - e.printStackTrace(); + LOG.debug("Error while testing new function: ", e); } } @Override - public void onSendWeather(WeatherSpec weatherSpec) { + public void onSendWeather(ArrayList weatherSpecs) { try { + WeatherSpec weatherSpec = weatherSpecs.get(0); TransactionBuilder builder = performInitialized("onSendWeather"); MoyoungWeatherToday weatherToday = new MoyoungWeatherToday(weatherSpec); @@ -1594,14 +1503,4 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { e.printStackTrace(); } } - - @Override - public void onSetFmFrequency(float frequency) { - throw new UnsupportedOperationException(); - } - - @Override - public void onSetLedColor(int color) { - throw new UnsupportedOperationException(); - } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java index 5ac5e87c1..32e7a5f0d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java @@ -27,13 +27,12 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.UUID; +import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.AbstractMoyoungDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants; -import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.moyoung.settings.MoyoungSetting; import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus; -import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper; public class QuerySettingsOperation extends AbstractBTLEOperation { @@ -51,7 +50,7 @@ public class QuerySettingsOperation extends AbstractBTLEOperationColmi R03 Colmi R06 Colmi R10 + Colmi i28 Ultra Bowers and Wilkins P series Choose export location General diff --git a/app/src/main/res/xml/devicesettings_donotdisturb_no_auto_v2.xml b/app/src/main/res/xml/devicesettings_donotdisturb_no_auto_v2.xml index 486bde81d..e6b2a4204 100644 --- a/app/src/main/res/xml/devicesettings_donotdisturb_no_auto_v2.xml +++ b/app/src/main/res/xml/devicesettings_donotdisturb_no_auto_v2.xml @@ -18,7 +18,6 @@ android:entryValues="@array/do_not_disturb_no_auto_values" android:key="do_not_disturb" android:summary="%s" - app:dependentValue="@string/p_scheduled" android:title="@string/mi2_prefs_do_not_disturb" />