mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-15 14:39:26 +01:00
Remove hardcoded equals("MI") in favor of DeviceCoordintator #136
This commit is contained in:
parent
2c29384ee8
commit
1e56e540fa
@ -26,6 +26,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -297,17 +298,13 @@ public class ControlCenter extends Activity {
|
|||||||
Toast.makeText(this, R.string.bluetooth_is_disabled_, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.bluetooth_is_disabled_, Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
|
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
|
||||||
|
DeviceHelper deviceHelper = DeviceHelper.getInstance();
|
||||||
for (BluetoothDevice pairedDevice : pairedDevices) {
|
for (BluetoothDevice pairedDevice : pairedDevices) {
|
||||||
DeviceType deviceDeviceType;
|
if (isDeviceContainedIn(pairedDevice, availableDevices)) {
|
||||||
if (pairedDevice.getName().indexOf("Pebble") == 0) {
|
|
||||||
deviceDeviceType = DeviceType.PEBBLE;
|
|
||||||
} else if (pairedDevice.getName().equals("MI")) {
|
|
||||||
deviceDeviceType = DeviceType.MIBAND;
|
|
||||||
} else {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
GBDevice device = new GBDevice(pairedDevice.getAddress(), pairedDevice.getName(), deviceDeviceType);
|
GBDevice device = deviceHelper.toSupportedDevice(pairedDevice);
|
||||||
if (!availableDevices.contains(device)) {
|
if (device != null) {
|
||||||
availableDevices.add(device);
|
availableDevices.add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,4 +342,13 @@ public class ControlCenter extends Activity {
|
|||||||
}
|
}
|
||||||
mGBDeviceAdapter.notifyDataSetChanged();
|
mGBDeviceAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDeviceContainedIn(BluetoothDevice device, List<GBDevice> availableDevices) {
|
||||||
|
for (GBDevice avail : availableDevices) {
|
||||||
|
if (avail.getAddress().equals(device.getAddress())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -34,6 +36,19 @@ public class DeviceHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GBDevice toSupportedDevice(BluetoothDevice device) {
|
||||||
|
GBDeviceCandidate candidate = new GBDeviceCandidate(device, GBDevice.RSSI_UNKNOWN);
|
||||||
|
if (coordinator != null && coordinator.supports(candidate)) {
|
||||||
|
return new GBDevice(device.getAddress(), device.getName(), coordinator.getDeviceType());
|
||||||
|
}
|
||||||
|
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
||||||
|
if (coordinator.supports(candidate)) {
|
||||||
|
return new GBDevice(device.getAddress(), device.getName(), coordinator.getDeviceType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public DeviceCoordinator getCoordinator(GBDeviceCandidate device) {
|
public DeviceCoordinator getCoordinator(GBDeviceCandidate device) {
|
||||||
if (coordinator != null && coordinator.supports(device)) {
|
if (coordinator != null && coordinator.supports(device)) {
|
||||||
return coordinator;
|
return coordinator;
|
||||||
|
Loading…
Reference in New Issue
Block a user