mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 10:05:49 +01:00
Ímplement sorting menu items for newer Huami devices
- Amazfit GTR/GTS - Amazfit Bip S - Mi Band 5/Amazfit Band 5
This commit is contained in:
parent
e1f2e0c830
commit
8cb2fb980a
@ -92,10 +92,12 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_END;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISCONNECT_NOTIFICATION_START;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_END;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DISPLAY_ON_LIFT_START;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_EXPOSE_HR_THIRDPARTY;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_SHORTCUTS_SORTABLE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_END;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_DO_NOT_DISTURB_OFF;
|
||||
@ -352,7 +354,9 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
||||
addPreferenceHandlerFor(PREF_MI2_DATEFORMAT);
|
||||
addPreferenceHandlerFor(PREF_DATEFORMAT);
|
||||
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS);
|
||||
addPreferenceHandlerFor(PREF_DISPLAY_ITEMS_SORTABLE);
|
||||
addPreferenceHandlerFor(PREF_SHORTCUTS);
|
||||
addPreferenceHandlerFor(PREF_SHORTCUTS_SORTABLE);
|
||||
addPreferenceHandlerFor(PREF_LANGUAGE);
|
||||
addPreferenceHandlerFor(PREF_EXPOSE_HR_THIRDPARTY);
|
||||
addPreferenceHandlerFor(PREF_WEARLOCATION);
|
||||
|
@ -61,7 +61,9 @@ public class HuamiConst {
|
||||
public static final String PREF_DISCONNECT_NOTIFICATION_END = "disconnect_notification_end";
|
||||
|
||||
public static final String PREF_DISPLAY_ITEMS = "display_items";
|
||||
public static final String PREF_DISPLAY_ITEMS_SORTABLE = "display_items_sortable";
|
||||
public static final String PREF_SHORTCUTS = "shortcuts";
|
||||
public static final String PREF_SHORTCUTS_SORTABLE = "shortcuts_sortable";
|
||||
public static final String PREF_EXPOSE_HR_THIRDPARTY = "expose_hr_thirdparty";
|
||||
public static final String PREF_USE_CUSTOM_FONT = "use_custom_font";
|
||||
|
||||
|
@ -1884,9 +1884,11 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
setDisconnectNotification(builder);
|
||||
break;
|
||||
case HuamiConst.PREF_DISPLAY_ITEMS:
|
||||
case HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE:
|
||||
setDisplayItems(builder);
|
||||
break;
|
||||
case HuamiConst.PREF_SHORTCUTS:
|
||||
case HuamiConst.PREF_SHORTCUTS_SORTABLE:
|
||||
setShortcuts(builder);
|
||||
break;
|
||||
case MiBandConst.PREF_MI2_ROTATE_WRIST_TO_SWITCH_INFO:
|
||||
@ -2314,47 +2316,46 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
protected HuamiSupport setDisplayItemsNew(TransactionBuilder builder, boolean isShortcuts, int defaultSettings, Map<String, Integer> keyIdMap) {
|
||||
if (gbDevice.getFirmwareVersion() == null) {
|
||||
LOG.warn("Device not initialized yet, won't set menu items");
|
||||
return this;
|
||||
}
|
||||
|
||||
SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress());
|
||||
Set<String> pages;
|
||||
String pages;
|
||||
List<String> enabledList;
|
||||
byte menuType;
|
||||
if (isShortcuts) {
|
||||
menuType = (byte) 0xfd;
|
||||
pages = prefs.getStringSet(HuamiConst.PREF_SHORTCUTS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_bips_shortcuts_default))));
|
||||
LOG.info("Setting shortcuts to " + (pages == null ? "none" : pages));
|
||||
pages = prefs.getString(HuamiConst.PREF_SHORTCUTS_SORTABLE, null);
|
||||
LOG.info("Setting shortcuts");
|
||||
} else {
|
||||
menuType = (byte) 0xff;
|
||||
pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(defaultSettings))));
|
||||
LOG.info("Setting display items to " + (pages == null ? "none" : pages));
|
||||
pages = prefs.getString(HuamiConst.PREF_DISPLAY_ITEMS_SORTABLE, null);
|
||||
LOG.info("Setting menu items");
|
||||
}
|
||||
if (pages == null) {
|
||||
enabledList = Arrays.asList(getContext().getResources().getStringArray(defaultSettings));
|
||||
} else {
|
||||
enabledList = Arrays.asList(pages.split(","));
|
||||
}
|
||||
LOG.info("enabled items" + enabledList);
|
||||
|
||||
if (pages != null) {
|
||||
byte[] command = new byte[keyIdMap.size() * 4 + 1];
|
||||
command[0] = 0x1e;
|
||||
// it seem that we first have to put all ENABLED items into the array
|
||||
// it seem that we first have to put all ENABLED items into the array, oder does matter
|
||||
int pos = 1;
|
||||
int index = 0;
|
||||
for (Map.Entry<String, Integer> entry : keyIdMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
int id = entry.getValue();
|
||||
|
||||
if (pages.contains(key)) {
|
||||
for (String key : enabledList) {
|
||||
Integer id = keyIdMap.get(key);
|
||||
if (id != null) {
|
||||
command[pos++] = (byte) index++;
|
||||
command[pos++] = 0x00;
|
||||
command[pos++] = menuType;
|
||||
command[pos++] = (byte) id;
|
||||
command[pos++] = id.byteValue();
|
||||
}
|
||||
}
|
||||
// And then all DISABLED ones
|
||||
// And then all DISABLED ones, order does not matter
|
||||
for (Map.Entry<String, Integer> entry : keyIdMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
int id = entry.getValue();
|
||||
|
||||
if (!pages.contains(key)) {
|
||||
if (!enabledList.contains(key)) {
|
||||
command[pos++] = (byte) index++;
|
||||
command[pos++] = 0x01;
|
||||
command[pos++] = (byte) menuType;
|
||||
@ -2362,7 +2363,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
writeToChunked(builder, 2, command);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<MultiSelectListPreference
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:icon="@drawable/ic_widgets"
|
||||
android:defaultValue="@array/pref_bips_display_items_default"
|
||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||
android:entries="@array/pref_bips_display_items"
|
||||
android:entryValues="@array/pref_bips_display_items_values"
|
||||
android:key="display_items"
|
||||
android:key="display_items_sortable"
|
||||
android:persistent="true"
|
||||
android:summary="@string/mi2_prefs_display_items_summary"
|
||||
android:title="@string/mi2_prefs_display_items" />
|
||||
<MultiSelectListPreference
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:defaultValue="@array/pref_bips_shortcuts_default"
|
||||
android:dialogTitle="@string/bip_prefs_shortcuts"
|
||||
android:entries="@array/pref_bips_shortcuts"
|
||||
android:entryValues="@array/pref_bips_shortcuts_values"
|
||||
android:key="shortcuts"
|
||||
android:key="shortcuts_sortable"
|
||||
android:persistent="true"
|
||||
android:summary="@string/bip_prefs_shotcuts_summary"
|
||||
android:title="@string/bip_prefs_shortcuts" />
|
||||
<ListPreference
|
||||
|
@ -1,12 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<MultiSelectListPreference
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:icon="@drawable/ic_widgets"
|
||||
android:defaultValue="@array/pref_gts_display_items_default"
|
||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||
android:entries="@array/pref_gts_display_items"
|
||||
android:entryValues="@array/pref_gts_display_items_values"
|
||||
android:key="display_items"
|
||||
android:key="display_items_sortable"
|
||||
android:persistent="true"
|
||||
android:summary="@string/mi2_prefs_display_items_summary"
|
||||
android:title="@string/mi2_prefs_display_items" />
|
||||
<ListPreference
|
||||
|
@ -1,12 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<MultiSelectListPreference
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:icon="@drawable/ic_widgets"
|
||||
android:defaultValue="@array/pref_miband5_display_items_default"
|
||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||
android:entries="@array/pref_miband5_display_items"
|
||||
android:entryValues="@array/pref_miband5_display_items_values"
|
||||
android:key="display_items"
|
||||
android:key="display_items_sortable"
|
||||
android:persistent="true"
|
||||
android:summary="@string/mi2_prefs_display_items_summary"
|
||||
android:title="@string/mi2_prefs_display_items" />
|
||||
<ListPreference
|
||||
|
Loading…
Reference in New Issue
Block a user