1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-10 12:09:27 +01:00

Xiaomi: Set device language

This commit is contained in:
José Rebelo 2023-10-22 14:53:48 +01:00
parent 48e149aefe
commit b0d3fe6a51
5 changed files with 80 additions and 6 deletions

View File

@ -410,10 +410,36 @@ public abstract class XiaomiCoordinator extends AbstractBLEDeviceCoordinator {
@Override
public String[] getSupportedLanguageSettings(final GBDevice device) {
// TODO check which are supported
final List<String> allLanguages = new ArrayList<>(HuamiLanguageType.idLookup.keySet());
allLanguages.add(0, "auto");
return allLanguages.toArray(new String[0]);
return new String[]{
"auto",
"ar_SA",
"cs_CZ",
"da_DK",
"de_DE",
"el_GR",
"en_US",
"es_ES",
"fr_FR",
"he_IL",
"id_ID",
"it_IT",
"ja_JP",
"ko_KO",
"nl_NL",
"nb_NO",
"pl_PL",
"pt_BR",
"pt_PT",
"ro_RO",
"ru_RU",
"sv_SE",
"th_TH",
"tr_TR",
"uk_UA",
"vi_VN",
"zh_CN",
"zh_TW",
};
}
@Override

View File

@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@ -36,11 +37,9 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdatePreferences;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.Huami2021Coordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst;
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiPreferences;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
@ -55,6 +54,7 @@ public class XiaomiSystemService extends AbstractXiaomiService {
public static final int CMD_BATTERY = 1;
public static final int CMD_DEVICE_INFO = 2;
public static final int CMD_CLOCK = 3;
public static final int CMD_LANGUAGE = 6;
public static final int CMD_PASSWORD_GET = 9;
public static final int CMD_FIND_PHONE = 17;
public static final int CMD_FIND_WATCH = 18;
@ -114,6 +114,9 @@ public class XiaomiSystemService extends AbstractXiaomiService {
@Override
public boolean onSendConfiguration(final String config, final Prefs prefs) {
switch (config) {
case DeviceSettingsPreferenceConst.PREF_LANGUAGE:
setLanguage();
return true;
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT:
setCurrentTime();
return true;
@ -128,6 +131,35 @@ public class XiaomiSystemService extends AbstractXiaomiService {
return super.onSendConfiguration(config, prefs);
}
public void setLanguage() {
String localeString = GBApplication.getDeviceSpecificSharedPrefs(getSupport().getDevice().getAddress()).getString(
DeviceSettingsPreferenceConst.PREF_LANGUAGE, DeviceSettingsPreferenceConst.PREF_LANGUAGE_AUTO
);
if (DeviceSettingsPreferenceConst.PREF_LANGUAGE_AUTO.equals(localeString)) {
String language = Locale.getDefault().getLanguage();
String country = Locale.getDefault().getCountry();
if (StringUtils.isNullOrEmpty(country)) {
// sometimes country is null, no idea why, guess it.
country = language;
}
localeString = language + "_" + country.toUpperCase();
}
LOG.info("Set language: {}", localeString);
getSupport().sendCommand(
"set language",
XiaomiProto.Command.newBuilder()
.setType(COMMAND_TYPE)
.setSubtype(CMD_LANGUAGE)
.setSystem(XiaomiProto.System.newBuilder().setLanguage(
XiaomiProto.Language.newBuilder().setCode(localeString.toLowerCase(Locale.ROOT))
))
.build()
);
}
public void setCurrentTime() {
LOG.debug("Setting current time");

View File

@ -94,6 +94,9 @@ message System {
// 2, 7 get | 2, 8 set
optional Camera camera = 15;
// 2, 6
optional Language language = 20;
// 2, 51 get | 2, 52 create
optional Widgets widgets = 28;
// 2, 53
@ -189,6 +192,10 @@ message Camera {
required bool enabled = 1;
}
message Language {
optional string code = 1; // pt_pt, en_us
}
message Widgets {
repeated Widget widget = 1;
optional uint32 unknown2 = 2; // 1

View File

@ -2210,6 +2210,10 @@
<item name="ja_JP">@string/japanese</item>
<item name="ko_KO">@string/korean</item>
<item name="he_IL">@string/hebrew</item>
<item name="da_DK">@string/danish</item>
<item name="nb_NO">@string/norwegian_bokmal</item>
<item name="ro_RO">@string/romanian</item>
<item name="sv_SE">@string/swedish</item>
</string-array>
<string-array name="pref_language_all_values">
@ -2244,6 +2248,10 @@
<item>ja_JP</item>
<item>ko_KO</item>
<item>he_IL</item>
<item>da_DK</item>
<item>nb_NO</item>
<item>ro_RO</item>
<item>sv_SE</item>
</string-array>
<string-array name="pref_amazfitbip_language">

View File

@ -1032,6 +1032,7 @@
<string name="hebrew">Hebrew</string>
<string name="swedish">Swedish</string>
<string name="czesh">Czech</string>
<string name="danish">Danish</string>
<string name="FetchActivityOperation_about_to_transfer_since">About to transfer data since %1$s</string>
<string name="waiting_for_reconnect">Waiting for reconnect</string>
<string name="activity_prefs_about_you">About you</string>