From e15afaab2fbe7ec42f6f542b411bd9d4a0e25659 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Mon, 6 Aug 2018 23:13:25 +0200 Subject: [PATCH] Probe connected devices first for firmware installation --- .../activities/FwAppInstallerActivity.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java index 5ab284a7d..a433c1ccf 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/FwAppInstallerActivity.java @@ -43,6 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.adapter.ItemWithDetailsAdapter; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; +import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; @@ -191,7 +192,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal } private InstallHandler findInstallHandlerFor(Uri uri) { - for (DeviceCoordinator coordinator : DeviceHelper.getInstance().getAllCoordinators()) { + for (DeviceCoordinator coordinator : getAllCoordinatorsConnectedFirst()) { InstallHandler handler = coordinator.findInstallHandler(uri, this); if (handler != null) { return handler; @@ -200,6 +201,29 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal return null; } + private List getAllCoordinatorsConnectedFirst() { + DeviceManager deviceManager = ((GBApplication) getApplicationContext()).getDeviceManager(); + List connectedCoordinators = new ArrayList<>(); + List allCoordinators = DeviceHelper.getInstance().getAllCoordinators(); + List sortedCoordinators = new ArrayList<>(allCoordinators.size()); + + GBDevice connectedDevice = deviceManager.getSelectedDevice(); + if (connectedDevice != null && connectedDevice.isConnected()) { + DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(connectedDevice); + if (coordinator != null) { + connectedCoordinators.add(coordinator); + } + } + + sortedCoordinators.addAll(connectedCoordinators); + for (DeviceCoordinator coordinator : allCoordinators) { + if (!connectedCoordinators.contains(coordinator)) { + sortedCoordinators.add(coordinator); + } + } + return sortedCoordinators; + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {