mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-01 20:15:52 +02:00
Xiaomi: Fix settings display items code
This commit is contained in:
parent
776346d311
commit
1c68252255
@ -46,7 +46,6 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
import nodomain.freeyourgadget.gadgetbridge.proto.xiaomi.XiaomiProto;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiPreferences;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.CheckSums;
|
import nodomain.freeyourgadget.gadgetbridge.util.CheckSums;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
@ -57,6 +56,10 @@ import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
|||||||
public class XiaomiSystemService extends AbstractXiaomiService implements XiaomiDataUploadService.Callback {
|
public class XiaomiSystemService extends AbstractXiaomiService implements XiaomiDataUploadService.Callback {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(XiaomiSystemService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(XiaomiSystemService.class);
|
||||||
|
|
||||||
|
// We persist the settings code when receiving the display items,
|
||||||
|
// so we can enforce it when sending them
|
||||||
|
private static final String PREF_SETTINGS_DISPLAY_ITEM_CODE = "xiaomi_settings_display_item_code";
|
||||||
|
|
||||||
public static final int COMMAND_TYPE = 2;
|
public static final int COMMAND_TYPE = 2;
|
||||||
|
|
||||||
public static final int CMD_BATTERY = 1;
|
public static final int CMD_BATTERY = 1;
|
||||||
@ -325,6 +328,8 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
final List<String> allScreens = new ArrayList<>(prefs.getList(DeviceSettingsUtils.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList()));
|
final List<String> allScreens = new ArrayList<>(prefs.getList(DeviceSettingsUtils.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList()));
|
||||||
final List<String> allLabels = new ArrayList<>(prefs.getList(DeviceSettingsUtils.getPrefPossibleValueLabelsKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList()));
|
final List<String> allLabels = new ArrayList<>(prefs.getList(DeviceSettingsUtils.getPrefPossibleValueLabelsKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), Collections.emptyList()));
|
||||||
final List<String> enabledScreens = new ArrayList<>(prefs.getList(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, Collections.emptyList()));
|
final List<String> enabledScreens = new ArrayList<>(prefs.getList(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, Collections.emptyList()));
|
||||||
|
final String settingsCode = prefs.getString(PREF_SETTINGS_DISPLAY_ITEM_CODE, null);
|
||||||
|
|
||||||
if (allScreens.isEmpty()) {
|
if (allScreens.isEmpty()) {
|
||||||
LOG.warn("No list of all screens");
|
LOG.warn("No list of all screens");
|
||||||
return;
|
return;
|
||||||
@ -346,8 +351,8 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
|
|
||||||
LOG.debug("Setting display items: {}", enabledScreens);
|
LOG.debug("Setting display items: {}", enabledScreens);
|
||||||
|
|
||||||
if (!enabledScreens.contains("setting")) {
|
if (settingsCode != null && !enabledScreens.contains(settingsCode)) {
|
||||||
enabledScreens.add("setting");
|
enabledScreens.add(settingsCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean inMoreSection = false;
|
boolean inMoreSection = false;
|
||||||
@ -370,7 +375,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
displayItem.setInMoreSection(true);
|
displayItem.setInMoreSection(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("setting".equals(enabledScreen)) {
|
if (enabledScreen.equals(settingsCode)) {
|
||||||
displayItem.setIsSettings(1);
|
displayItem.setIsSettings(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,6 +413,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
final List<String> allScreensLabels = new ArrayList<>();
|
final List<String> allScreensLabels = new ArrayList<>();
|
||||||
final List<String> mainScreens = new ArrayList<>();
|
final List<String> mainScreens = new ArrayList<>();
|
||||||
final List<String> moreScreens = new ArrayList<>();
|
final List<String> moreScreens = new ArrayList<>();
|
||||||
|
String settingsCode = null;
|
||||||
for (final XiaomiProto.DisplayItem displayItem : displayItems.getDisplayItemList()) {
|
for (final XiaomiProto.DisplayItem displayItem : displayItems.getDisplayItemList()) {
|
||||||
allScreens.add(displayItem.getCode());
|
allScreens.add(displayItem.getCode());
|
||||||
allScreensLabels.add(displayItem.getName().replace(",", ""));
|
allScreensLabels.add(displayItem.getName().replace(",", ""));
|
||||||
@ -418,6 +424,10 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
mainScreens.add(displayItem.getCode());
|
mainScreens.add(displayItem.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (displayItem.getIsSettings() == 1) {
|
||||||
|
settingsCode = displayItem.getCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> enabledScreens = new ArrayList<>(mainScreens);
|
final List<String> enabledScreens = new ArrayList<>(mainScreens);
|
||||||
@ -436,6 +446,7 @@ public class XiaomiSystemService extends AbstractXiaomiService implements Xiaomi
|
|||||||
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences()
|
final GBDeviceEventUpdatePreferences eventUpdatePreferences = new GBDeviceEventUpdatePreferences()
|
||||||
.withPreference(DeviceSettingsUtils.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), allScreensPrefValue)
|
.withPreference(DeviceSettingsUtils.getPrefPossibleValuesKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), allScreensPrefValue)
|
||||||
.withPreference(DeviceSettingsUtils.getPrefPossibleValueLabelsKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), allScreensLabelsPrefValue)
|
.withPreference(DeviceSettingsUtils.getPrefPossibleValueLabelsKey(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE), allScreensLabelsPrefValue)
|
||||||
|
.withPreference(PREF_SETTINGS_DISPLAY_ITEM_CODE, settingsCode)
|
||||||
.withPreference(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, prefValue);
|
.withPreference(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, prefValue);
|
||||||
|
|
||||||
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
getSupport().evaluateGBDeviceEvent(eventUpdatePreferences);
|
||||||
|
Loading…
Reference in New Issue
Block a user