use DeviceHelper in DeviceSupportFactory to determine supported device from bt addresses
This fixes a bug when Pebble was detected as Mi when unpaired. Since we were not able to read the device name, it was considered MI by duplicated and faulty code. Fixes #177.
This commit is contained in:
parent
729555b045
commit
aca0149b45
|
@ -52,7 +52,6 @@ public class ControlCenter extends Activity {
|
||||||
= "nodomain.freeyourgadget.gadgetbridge.controlcenter.action.set_version";
|
= "nodomain.freeyourgadget.gadgetbridge.controlcenter.action.set_version";
|
||||||
|
|
||||||
private TextView hintTextView;
|
private TextView hintTextView;
|
||||||
private ListView deviceListView;
|
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
private GBDeviceAdapter mGBDeviceAdapter;
|
private GBDeviceAdapter mGBDeviceAdapter;
|
||||||
private GBDevice selectedDevice = null;
|
private GBDevice selectedDevice = null;
|
||||||
|
@ -124,7 +123,7 @@ public class ControlCenter extends Activity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_controlcenter);
|
setContentView(R.layout.activity_controlcenter);
|
||||||
hintTextView = (TextView) findViewById(R.id.hintTextView);
|
hintTextView = (TextView) findViewById(R.id.hintTextView);
|
||||||
deviceListView = (ListView) findViewById(R.id.deviceListView);
|
ListView deviceListView = (ListView) findViewById(R.id.deviceListView);
|
||||||
mGBDeviceAdapter = new GBDeviceAdapter(this, deviceList);
|
mGBDeviceAdapter = new GBDeviceAdapter(this, deviceList);
|
||||||
deviceListView.setAdapter(this.mGBDeviceAdapter);
|
deviceListView.setAdapter(this.mGBDeviceAdapter);
|
||||||
deviceListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
deviceListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
public class DeviceSupportFactory {
|
public class DeviceSupportFactory {
|
||||||
|
@ -74,18 +75,23 @@ public class DeviceSupportFactory {
|
||||||
|
|
||||||
private DeviceSupport createBTDeviceSupport(String deviceAddress) throws GBException {
|
private DeviceSupport createBTDeviceSupport(String deviceAddress) throws GBException {
|
||||||
if (mBtAdapter != null && mBtAdapter.isEnabled()) {
|
if (mBtAdapter != null && mBtAdapter.isEnabled()) {
|
||||||
GBDevice gbDevice = null;
|
GBDevice gbDevice;
|
||||||
DeviceSupport deviceSupport = null;
|
DeviceSupport deviceSupport = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(deviceAddress);
|
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(deviceAddress);
|
||||||
if (btDevice.getName() == null || btDevice.getName().startsWith("MI")) { //FIXME: workaround for Miband not being paired
|
gbDevice = DeviceHelper.getInstance().toSupportedDevice(btDevice);
|
||||||
gbDevice = new GBDevice(deviceAddress, "MI", DeviceType.MIBAND);
|
if (gbDevice != null) {
|
||||||
deviceSupport = new ServiceDeviceSupport(new MiBandSupport(), EnumSet.of(ServiceDeviceSupport.Flags.THROTTLING, ServiceDeviceSupport.Flags.BUSY_CHECKING));
|
switch (gbDevice.getType()) {
|
||||||
} else if (btDevice.getName().indexOf("Pebble") == 0) {
|
case PEBBLE:
|
||||||
gbDevice = new GBDevice(deviceAddress, btDevice.getName(), DeviceType.PEBBLE);
|
deviceSupport = new ServiceDeviceSupport(new PebbleSupport(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
|
||||||
deviceSupport = new ServiceDeviceSupport(new PebbleSupport(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
|
break;
|
||||||
|
case MIBAND:
|
||||||
|
deviceSupport = new ServiceDeviceSupport(new MiBandSupport(), EnumSet.of(ServiceDeviceSupport.Flags.THROTTLING, ServiceDeviceSupport.Flags.BUSY_CHECKING));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceSupport != null) {
|
if (deviceSupport != null) {
|
||||||
deviceSupport.setContext(gbDevice, mBtAdapter, mContext);
|
deviceSupport.setContext(gbDevice, mBtAdapter, mContext);
|
||||||
return deviceSupport;
|
return deviceSupport;
|
||||||
|
|
Loading…
Reference in New Issue