From 14df63854fcb08b47218413ab5429ca1d33385e3 Mon Sep 17 00:00:00 2001 From: Ascense Date: Mon, 14 Aug 2023 00:33:47 +0300 Subject: [PATCH] Withings Steel HR: Support setting device language --- .../WithingsSteelHRDeviceCoordinator.java | 12 ++++++ .../WithingsSteelHRDeviceSupport.java | 37 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java index f964e0272..4ee7c8e6a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/withingssteelhr/WithingsSteelHRDeviceCoordinator.java @@ -172,4 +172,16 @@ public class WithingsSteelHRDeviceCoordinator extends AbstractDeviceCoordinator public boolean supportsFindDevice() { return false; } + + @Override + public String[] getSupportedLanguageSettings(GBDevice device) { + return new String[]{ + "auto", + "de_DE", + "en_US", + "es_ES", + "fr_FR", + "it_IT", + }; + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java index 00ad34dd2..10a637e80 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/withingssteelhr/WithingsSteelHRDeviceSupport.java @@ -117,6 +117,9 @@ import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LANGUAGE; +import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_LANGUAGE_AUTO; + public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport { private static final Logger logger = LoggerFactory.getLogger(WithingsSteelHRDeviceSupport.class); @@ -215,7 +218,7 @@ public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport { mtuSize = mtu; if (firstTimeConnect) { addSimpleConversationToQueue(new WithingsMessage(WithingsMessageType.INITIAL_CONNECT)); - addSimpleConversationToQueue(new WithingsMessage(WithingsMessageType.SET_LOCALE, new Locale("de"))); + addSimpleConversationToQueue(new WithingsMessage(WithingsMessageType.SET_LOCALE, getLocale())); addSimpleConversationToQueue(new WithingsMessage(WithingsMessageType.START_HANDS_CALIBRATION)); addSimpleConversationToQueue(new WithingsMessage(WithingsMessageType.STOP_HANDS_CALIBRATION)); addSimpleConversationToQueue(new WithingsMessage(WithingsMessageType.SET_TIME, new Time())); @@ -400,6 +403,9 @@ public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport { case HuamiConst.PREF_WORKOUT_ACTIVITY_TYPES_SORTABLE: setWorkoutActivityTypes(); break; + case PREF_LANGUAGE: + setLanguage(); + break; default: logger.debug("unknown configuration setting received: " + config); } @@ -701,6 +707,35 @@ public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport { return message; } + protected void setLanguage() { + Locale locale = getLocale(); + + conversationQueue.clear(); + addSimpleConversationToQueue(new WithingsMessage(WithingsMessageType.SET_LOCALE, locale)); + conversationQueue.send(); + } + + private Locale getLocale() { + String localeString = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()) + .getString(PREF_LANGUAGE, PREF_LANGUAGE_AUTO); + + if (localeString == null || localeString.equals(PREF_LANGUAGE_AUTO)) { + localeString = java.util.Locale.getDefault().getLanguage(); + } + + String language = localeString.substring(0, 2); + switch (language) { + case "de": + case "en": + case "es": + case "fr": + case "it": + return new Locale(language); + default: + return new Locale("en"); + } + } + private short getTimeMode() { GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()))); String tmode = gbPrefs.getTimeFormat();