mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 12:56:49 +01:00
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";
|
||||
|
||||
private TextView hintTextView;
|
||||
private ListView deviceListView;
|
||||
private SwipeRefreshLayout swipeLayout;
|
||||
private GBDeviceAdapter mGBDeviceAdapter;
|
||||
private GBDevice selectedDevice = null;
|
||||
@ -124,7 +123,7 @@ public class ControlCenter extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_controlcenter);
|
||||
hintTextView = (TextView) findViewById(R.id.hintTextView);
|
||||
deviceListView = (ListView) findViewById(R.id.deviceListView);
|
||||
ListView deviceListView = (ListView) findViewById(R.id.deviceListView);
|
||||
mGBDeviceAdapter = new GBDeviceAdapter(this, deviceList);
|
||||
deviceListView.setAdapter(this.mGBDeviceAdapter);
|
||||
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.service.devices.miband.MiBandSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class DeviceSupportFactory {
|
||||
@ -74,18 +75,23 @@ public class DeviceSupportFactory {
|
||||
|
||||
private DeviceSupport createBTDeviceSupport(String deviceAddress) throws GBException {
|
||||
if (mBtAdapter != null && mBtAdapter.isEnabled()) {
|
||||
GBDevice gbDevice = null;
|
||||
GBDevice gbDevice;
|
||||
DeviceSupport deviceSupport = null;
|
||||
|
||||
try {
|
||||
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(deviceAddress);
|
||||
if (btDevice.getName() == null || btDevice.getName().startsWith("MI")) { //FIXME: workaround for Miband not being paired
|
||||
gbDevice = new GBDevice(deviceAddress, "MI", DeviceType.MIBAND);
|
||||
deviceSupport = new ServiceDeviceSupport(new MiBandSupport(), EnumSet.of(ServiceDeviceSupport.Flags.THROTTLING, ServiceDeviceSupport.Flags.BUSY_CHECKING));
|
||||
} else if (btDevice.getName().indexOf("Pebble") == 0) {
|
||||
gbDevice = new GBDevice(deviceAddress, btDevice.getName(), DeviceType.PEBBLE);
|
||||
deviceSupport = new ServiceDeviceSupport(new PebbleSupport(), EnumSet.of(ServiceDeviceSupport.Flags.BUSY_CHECKING));
|
||||
gbDevice = DeviceHelper.getInstance().toSupportedDevice(btDevice);
|
||||
if (gbDevice != null) {
|
||||
switch (gbDevice.getType()) {
|
||||
case PEBBLE:
|
||||
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) {
|
||||
deviceSupport.setContext(gbDevice, mBtAdapter, mContext);
|
||||
return deviceSupport;
|
||||
|
Loading…
Reference in New Issue
Block a user