mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 12:26:48 +01:00
Mi Band 3: Allow setting date format in per-device settings
Closes #1544
This commit is contained in:
parent
f7a4b3c06a
commit
8d50e8ef08
@ -282,6 +282,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
||||
|
||||
addPreferenceHandlerFor(PREF_SWIPE_UNLOCK);
|
||||
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
|
||||
addPreferenceHandlerFor("dateformat");
|
||||
addPreferenceHandlerFor(HuamiConst.PREF_DISPLAY_ITEMS);
|
||||
|
||||
String displayOnLiftState = prefs.getString(PREF_ACTIVATE_DISPLAY_ON_LIFT, PREF_DO_NOT_DISTURB_OFF);
|
||||
|
@ -136,6 +136,7 @@ public class HuamiService {
|
||||
public static final byte[] DATEFORMAT_TIME = new byte[] {ENDPOINT_DISPLAY, 0x0a, 0x0, 0x0 };
|
||||
public static final byte[] DATEFORMAT_TIME_12_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x0 };
|
||||
public static final byte[] DATEFORMAT_TIME_24_HOURS = new byte[] {ENDPOINT_DISPLAY, 0x02, 0x0, 0x1 };
|
||||
public static final byte[] DATEFORMAT_DATE_MM_DD_YYYY = new byte[]{ENDPOINT_DISPLAY, 30, 0x00, 'M', 'M', '/', 'd', 'd', '/', 'y', 'y', 'y', 'y'};
|
||||
public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01};
|
||||
public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x00};
|
||||
public static final byte[] COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST = new byte[]{ENDPOINT_DISPLAY, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00};
|
||||
|
@ -103,6 +103,7 @@ public class MiBand3Coordinator extends HuamiCoordinator {
|
||||
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
|
||||
return new int[]{
|
||||
R.xml.devicesettings_miband3,
|
||||
R.xml.devicesettings_dateformat,
|
||||
R.xml.devicesettings_nightmode,
|
||||
R.xml.devicesettings_donotdisturb_withauto,
|
||||
R.xml.devicesettings_liftwrist_display,
|
||||
|
@ -1553,6 +1553,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
case MiBandConst.PREF_SWIPE_UNLOCK:
|
||||
setBandScreenUnlock(builder);
|
||||
break;
|
||||
case "dateformat":
|
||||
setDateFormat(builder);
|
||||
break;
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
} catch (IOException e) {
|
||||
@ -1567,11 +1570,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onTestNewFunction() {
|
||||
try {
|
||||
new FetchSportsSummaryOperation(this).perform();
|
||||
} catch (IOException ex) {
|
||||
LOG.error("Unable to fetch MI activity data", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1593,6 +1592,26 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HuamiSupport setDateFormat(TransactionBuilder builder) {
|
||||
String dateFormat = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString("dateformat", "MM/dd/yyyy");
|
||||
if (dateFormat == null) {
|
||||
return null;
|
||||
}
|
||||
switch (dateFormat) {
|
||||
case "MM/dd/yyyy":
|
||||
case "dd.MM.yyyy":
|
||||
case "dd/MM/yyyy":
|
||||
byte[] command = HuamiService.DATEFORMAT_DATE_MM_DD_YYYY;
|
||||
System.arraycopy(dateFormat.getBytes(), 0, command, 3, 10);
|
||||
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command);
|
||||
break;
|
||||
default:
|
||||
LOG.warn("unsupported date format " + dateFormat);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private HuamiSupport setTimeFormat(TransactionBuilder builder) {
|
||||
boolean is24Format = DateFormat.is24HourFormat(getContext());
|
||||
LOG.info("Setting 24h time format to " + is24Format);
|
||||
|
@ -36,7 +36,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Coordin
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3FWHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband3.MiBand3Service;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@ -164,6 +163,7 @@ public class MiBand3Support extends AmazfitBipSupport {
|
||||
setLanguage(builder);
|
||||
setBandScreenUnlock(builder);
|
||||
setNightMode(builder);
|
||||
setDateFormat(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -150,6 +150,18 @@
|
||||
<item>@string/p_dateformat_datetime</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dateformats">
|
||||
<item>dd.MM.yyyy</item>
|
||||
<item>dd/MM/yyyy</item>
|
||||
<item>MM/dd/yyyy</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="dateformats_values">
|
||||
<item>dd.MM.yyyy</item>
|
||||
<item>dd/MM/yyyy</item>
|
||||
<item>MM/dd/yyyy</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="mi2_do_not_disturb">
|
||||
<item>@string/mi2_dnd_off</item>
|
||||
<item>@string/mi2_dnd_automatic</item>
|
||||
|
Loading…
Reference in New Issue
Block a user