From 5a49f1215ebe9cc77f5aca7e1d52b0dd0ea7a5f0 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 2 Sep 2016 10:54:32 +0200 Subject: [PATCH] Display known devices from db even if Bluetooth is off or unsupported This allows to view activity data without turning bt on or connecting to the pebble emulator via tcp/ip (needs modified manifest for internet access) --- .../gadgetbridge/util/DeviceHelper.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java index a9bbf1e80..118203d5d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/DeviceHelper.java @@ -3,7 +3,6 @@ package nodomain.freeyourgadget.gadgetbridge.util; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Context; -import android.support.annotation.NonNull; import android.widget.Toast; import org.slf4j.Logger; @@ -16,7 +15,6 @@ import java.util.List; import java.util.Set; import nodomain.freeyourgadget.gadgetbridge.GBApplication; -import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; @@ -100,27 +98,28 @@ public class DeviceHelper { GB.toast(context, context.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN); } else if (!btAdapter.isEnabled()) { GB.toast(context, context.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN); - } else { - List dbDevices = getDatabaseDevices(); + } + List dbDevices = getDatabaseDevices(); + if (btAdapter != null) { List bondedDevices = getBondedDevices(btAdapter); availableDevices.addAll(bondedDevices); - availableDevices.addAll(dbDevices); + } + availableDevices.addAll(dbDevices); - Prefs prefs = GBApplication.getPrefs(); - String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, ""); - if (miAddr.length() > 0) { - GBDevice miDevice = new GBDevice(miAddr, "MI", DeviceType.MIBAND); - if (!availableDevices.contains(miDevice)) { - availableDevices.add(miDevice); - } + Prefs prefs = GBApplication.getPrefs(); + String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, ""); + if (miAddr.length() > 0) { + GBDevice miDevice = new GBDevice(miAddr, "MI", DeviceType.MIBAND); + if (!availableDevices.contains(miDevice)) { + availableDevices.add(miDevice); } + } - String pebbleEmuAddr = prefs.getString("pebble_emu_addr", ""); - String pebbleEmuPort = prefs.getString("pebble_emu_port", ""); - if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) { - GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", DeviceType.PEBBLE); - availableDevices.add(pebbleEmuDevice); - } + String pebbleEmuAddr = prefs.getString("pebble_emu_addr", ""); + String pebbleEmuPort = prefs.getString("pebble_emu_port", ""); + if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) { + GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", DeviceType.PEBBLE); + availableDevices.add(pebbleEmuDevice); } return availableDevices; }