1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-29 12:05:53 +01:00

Huami: make time format 12h/24h configurable (was automatic before)

Fixes #1736
This commit is contained in:
Andreas Shimokawa 2020-01-04 23:40:50 +01:00
parent 0b673646e3
commit 1c82c4e8e1
16 changed files with 53 additions and 7 deletions

View File

@ -55,6 +55,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
@ -198,7 +199,9 @@ public class HPlusCoordinator extends AbstractDeviceCoordinator {
}
public static byte getTimeMode(String deviceAddress) {
String tmode = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress).getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, "24h");
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(deviceAddress)));
String tmode = gbPrefs.getTimeFormat();
if ("24h".equals(tmode)) {
return HPlusConstants.ARG_TIMEMODE_24H;

View File

@ -81,6 +81,7 @@ public class AmazfitBipCoordinator extends HuamiCoordinator {
public int[] getSupportedDeviceSpecificSettings(GBDevice device) {
return new int[]{
R.xml.devicesettings_amazfitbip,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_custom_emoji_font,
R.xml.devicesettings_liftwrist_display,

View File

@ -85,6 +85,7 @@ public class AmazfitCorCoordinator extends HuamiCoordinator {
return new int[]{
R.xml.devicesettings_amazfitcor,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_custom_emoji_font,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_disconnectnotification,

View File

@ -87,6 +87,7 @@ public class AmazfitCor2Coordinator extends HuamiCoordinator {
return new int[]{
R.xml.devicesettings_amazfitcor,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_custom_emoji_font,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_disconnectnotification,

View File

@ -90,6 +90,7 @@ public class AmazfitGTRCoordinator extends HuamiCoordinator {
return new int[]{
R.xml.devicesettings_amazfitgtr,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_disconnectnotification,
R.xml.devicesettings_expose_hr_thirdparty,

View File

@ -90,6 +90,7 @@ public class AmazfitGTSCoordinator extends HuamiCoordinator {
return new int[]{
R.xml.devicesettings_amazfitgtr,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_disconnectnotification,
R.xml.devicesettings_expose_hr_thirdparty,

View File

@ -80,6 +80,7 @@ public class MiBand2Coordinator extends HuamiCoordinator {
return new int[]{
R.xml.devicesettings_miband2,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_donotdisturb_withauto,
R.xml.devicesettings_liftwrist_display,
R.xml.devicesettings_rotatewrist_cycleinfo,

View File

@ -104,6 +104,7 @@ public class MiBand3Coordinator extends HuamiCoordinator {
return new int[]{
R.xml.devicesettings_miband3,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_dateformat,
R.xml.devicesettings_nightmode,
R.xml.devicesettings_donotdisturb_withauto,

View File

@ -91,6 +91,7 @@ public class MiBand4Coordinator extends HuamiCoordinator {
R.xml.devicesettings_miband3,
R.xml.devicesettings_wearlocation,
R.xml.devicesettings_custom_emoji_font,
R.xml.devicesettings_timeformat,
R.xml.devicesettings_dateformat,
R.xml.devicesettings_nightmode,
R.xml.devicesettings_liftwrist_display,

View File

@ -35,6 +35,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
@ -48,6 +49,8 @@ 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.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.GBApplication.getContext;
@ -75,7 +78,9 @@ public class MakibesHR3Coordinator extends AbstractDeviceCoordinator {
}
public static byte getTimeMode(SharedPreferences sharedPrefs) {
String timeMode = sharedPrefs.getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, getContext().getString(R.string.p_timeformat_24h));
GBPrefs gbPrefs = new GBPrefs(new Prefs(sharedPrefs));
String timeMode = gbPrefs.getTimeFormat();
if (timeMode.equals(getContext().getString(R.string.p_timeformat_24h))) {
return MakibesHR3Constants.ARG_SET_TIMEMODE_24H;

View File

@ -130,6 +130,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
@ -1700,6 +1701,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case MiBandConst.PREF_SWIPE_UNLOCK:
setBandScreenUnlock(builder);
break;
case DeviceSettingsPreferenceConst.PREF_TIMEFORMAT:
setTimeFormat(builder);
break;
case DeviceSettingsPreferenceConst.PREF_DATEFORMAT:
setDateFormat(builder);
break;
@ -1952,9 +1956,11 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
}
private HuamiSupport setTimeFormat(TransactionBuilder builder) {
boolean is24Format = DateFormat.is24HourFormat(getContext());
LOG.info("Setting 24h time format to " + is24Format);
if (is24Format) {
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress())));
String timeFormat = gbPrefs.getTimeFormat();
LOG.info("Setting time format to " + timeFormat);
if (timeFormat.equals("24h")) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.DATEFORMAT_TIME_24_HOURS);
} else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.DATEFORMAT_TIME_12_HOURS);

View File

@ -67,6 +67,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.util.AlarmUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
/**
@ -1682,7 +1683,9 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
}
private void setTimeFormate(TransactionBuilder builder) {
String timeFormat = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()).getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, "24h");
GBPrefs gbPrefs = new GBPrefs(new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress())));
String timeFormat = gbPrefs.getTimeFormat();
int type = 1;
if ("am/pm".equals(timeFormat)) {
type = 2;

View File

@ -17,9 +17,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.util;
import android.text.format.DateFormat;
import java.text.ParseException;
import java.util.Date;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
public class GBPrefs {
public static final String PACKAGE_BLACKLIST = "package_blacklist";
public static final String PACKAGE_PEBBLEMSG_BLACKLIST = "package_pebblemsg_blacklist";
@ -81,4 +86,17 @@ public class GBPrefs {
public int getUserGender() {
return 0;
}
public String getTimeFormat() {
String timeFormat = mPrefs.getString(DeviceSettingsPreferenceConst.PREF_TIMEFORMAT, "auto");
if ("auto".equals(timeFormat)) {
if (DateFormat.is24HourFormat(GBApplication.getContext())) {
timeFormat = "24h";
} else {
timeFormat = "am/pm";
}
}
return timeFormat;
}
}

View File

@ -365,11 +365,13 @@
</string-array>
<string-array name="pref_timeformat_entries">
<item>@string/automatic</item>
<item>@string/timeformat_24h</item>
<item>@string/timeformat_am_pm</item>
</string-array>
<string-array name="pref_timeformat_values">
<item>@string/p_timeformat_auto</item>
<item>@string/p_timeformat_24h</item>
<item>@string/p_timeformat_am_pm</item>
</string-array>

View File

@ -43,6 +43,7 @@
<item name="p_unit_metric" type="string">metric</item>
<item name="p_unit_imperial" type="string">imperial</item>
<item name="p_timeformat_auto" type="string">auto</item>
<item name="p_timeformat_24h" type="string">24h</item>
<item name="p_timeformat_am_pm" type="string">am/pm</item>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:defaultValue="24h"
android:defaultValue="@string/p_timeformat_auto"
android:entries="@array/pref_timeformat_entries"
android:entryValues="@array/pref_timeformat_values"
android:icon="@drawable/ic_access_time"