1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 14:32:54 +01:00

Amazfit GTS2 mini: Fix language selection

This commit is contained in:
Andreas Shimokawa 2021-12-13 10:08:39 +01:00
parent 2e8f44cd85
commit a917d3786f
3 changed files with 32 additions and 21 deletions

View File

@ -2907,6 +2907,30 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
return this; return this;
} }
/*
Some newer devices seem to support setting the language by id again instead of a locale string
Amazfit Bip U and GTS 2 mini tested so far
*/
protected HuamiSupport setLanguageByIdNew(TransactionBuilder builder) {
byte language_code = 0x02; // english default
String localeString = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString("language", "auto");
if (localeString == null || localeString.equals("auto")) {
String language = Locale.getDefault().getLanguage();
String country = Locale.getDefault().getCountry();
localeString = language + "_" + country.toUpperCase();
}
Integer id = HuamiLanguageType.idLookup.get(localeString);
if (id != null) {
language_code = id.byteValue();
}
final byte[] command = new byte[]{0x06, 0x3b, 0x00, language_code, 0x03};
writeToConfiguration(builder, command);
return this;
}
private HuamiSupport setExposeHRThridParty(TransactionBuilder builder) { private HuamiSupport setExposeHRThridParty(TransactionBuilder builder) {
boolean enable = HuamiCoordinator.getExposeHRThirdParty(gbDevice.getAddress()); boolean enable = HuamiCoordinator.getExposeHRThirdParty(gbDevice.getAddress());

View File

@ -21,13 +21,10 @@ import android.content.Context;
import android.net.Uri; import android.net.Uri;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbipu.AmazfitBipUFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbipu.AmazfitBipUFWHelper;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiLanguageType;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbips.AmazfitBipSSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbips.AmazfitBipSSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation;
@ -37,24 +34,7 @@ public class AmazfitBipUSupport extends AmazfitBipSSupport {
@Override @Override
protected HuamiSupport setLanguage(TransactionBuilder builder) { protected HuamiSupport setLanguage(TransactionBuilder builder) {
byte language_code = 0x02; // english default return setLanguageByIdNew(builder);
String localeString = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString("language", "auto");
if (localeString == null || localeString.equals("auto")) {
String language = Locale.getDefault().getLanguage();
String country = Locale.getDefault().getCountry();
localeString = language + "_" + country.toUpperCase();
}
Integer id = HuamiLanguageType.idLookup.get(localeString);
if (id != null) {
language_code = id.byteValue();
}
final byte[] command = new byte[]{0x06, 0x3b, 0x00, language_code, 0x03};
writeToConfiguration(builder, command);
return this;
} }
@Override @Override

View File

@ -24,9 +24,16 @@ import java.io.IOException;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2MiniFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts2.AmazfitGTS2MiniFWHelper;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support { public class AmazfitGTS2MiniSupport extends AmazfitGTS2Support {
@Override
protected HuamiSupport setLanguage(TransactionBuilder builder) {
return setLanguageByIdNew(builder);
}
@Override @Override
public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException {
return new AmazfitGTS2MiniFWHelper(uri, context); return new AmazfitGTS2MiniFWHelper(uri, context);