From e7a1e1b8c3c908c06757482bf06c650542fb9230 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Mon, 19 Feb 2018 18:27:48 +0100 Subject: [PATCH] Move the connected device to top in control center What happens in reality is that devices are sorted according to their connection status first, and then by name. So even if/when we support multiple device connection, the order should remain sane. This closes #842. --- CHANGELOG.md | 3 +++ .../freeyourgadget/gadgetbridge/devices/DeviceManager.java | 5 ++++- .../nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java | 4 ++++ app/src/main/res/xml/changelog_master.xml | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ab048dd..695776c7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ### Changelog +#### Version next +* Move the connected device to top in control center + #### Version 0.24.6 * Display the chat icon for notifications coming from Kontalk and Antox * Pebble: Fix for background js which try to send floats (e.g. TrekVolle) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java index 445d5479a..7d4901c3d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/DeviceManager.java @@ -163,7 +163,10 @@ public class DeviceManager { Collections.sort(deviceList, new Comparator() { @Override public int compare(GBDevice lhs, GBDevice rhs) { - return Collator.getInstance().compare(lhs.getName(), rhs.getName()); + if (rhs.getStateOrdinal() - lhs.getStateOrdinal() == 0) { + return Collator.getInstance().compare(lhs.getName(), rhs.getName()); + } + return (rhs.getStateOrdinal() - lhs.getStateOrdinal()); } }); notifyDevicesChanged(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java index 2444aabcc..ccffbdb66 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDevice.java @@ -252,6 +252,10 @@ public class GBDevice implements Parcelable { return mState; } + public int getStateOrdinal() { + return mState.ordinal(); + } + public void setState(State state) { mState = state; if (state.ordinal() <= State.CONNECTED.ordinal()) { diff --git a/app/src/main/res/xml/changelog_master.xml b/app/src/main/res/xml/changelog_master.xml index 703cdfbb7..b37564797 100644 --- a/app/src/main/res/xml/changelog_master.xml +++ b/app/src/main/res/xml/changelog_master.xml @@ -1,5 +1,8 @@ + + Move the connected device to top in control center + Display the chat icon for notifications coming from Kontalk and Antox Pebble: Fix for background js which try to send floats (e.g. TrekVolle)