mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 10:56:50 +01:00
Let discovery activity also display device aliases
This commit is contained in:
parent
903890067d
commit
154b7d28bb
@ -179,6 +179,7 @@ public class DiscoveryActivity extends GBActivity implements AdapterView.OnItemC
|
||||
}
|
||||
|
||||
private void handleDeviceFound(BluetoothDevice device, short rssi) {
|
||||
LOG.debug("found device: " + device.getName() + ", " + device.getAddress());
|
||||
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
return; // ignore already bonded devices
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import android.os.Parcelable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -76,14 +78,22 @@ public class GBDeviceCandidate implements Parcelable {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
String name = null;
|
||||
if (device != null) {
|
||||
name = device.getName();
|
||||
String deviceName = null;
|
||||
try {
|
||||
Method method = device.getClass().getMethod("getAliasName");
|
||||
if (method != null) {
|
||||
deviceName = (String) method.invoke(device);
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignore) {
|
||||
LOG.info("Could not get device alias for " + deviceName);
|
||||
}
|
||||
if (name == null || name.length() == 0) {
|
||||
name = GBApplication.getContext().getString(R.string._unknown_);
|
||||
if (deviceName == null || deviceName.length() == 0) {
|
||||
deviceName = device.getName();
|
||||
}
|
||||
return name;
|
||||
if (deviceName == null || deviceName.length() == 0) {
|
||||
deviceName = "(unknown)";
|
||||
}
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public short getRssi() {
|
||||
|
@ -8,8 +8,6 @@ import android.widget.Toast;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@ -18,7 +16,6 @@ import java.util.Set;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.UnknownDeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandCoordinator;
|
||||
@ -115,22 +112,12 @@ public class DeviceHelper {
|
||||
public GBDevice toSupportedDevice(BluetoothDevice device) {
|
||||
GBDeviceCandidate candidate = new GBDeviceCandidate(device, GBDevice.RSSI_UNKNOWN);
|
||||
|
||||
String deviceName = device.getName();
|
||||
try {
|
||||
Method method = device.getClass().getMethod("getAliasName");
|
||||
if (method != null) {
|
||||
deviceName = (String) method.invoke(device);
|
||||
}
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignore) {
|
||||
LOG.info("Could not get device alias for " + deviceName);
|
||||
}
|
||||
|
||||
if (coordinator != null && coordinator.supports(candidate)) {
|
||||
return new GBDevice(device.getAddress(), deviceName, coordinator.getDeviceType());
|
||||
return new GBDevice(device.getAddress(), candidate.getName(), coordinator.getDeviceType());
|
||||
}
|
||||
for (DeviceCoordinator coordinator : getAllCoordinators()) {
|
||||
if (coordinator.supports(candidate)) {
|
||||
return new GBDevice(device.getAddress(), deviceName, coordinator.getDeviceType());
|
||||
return new GBDevice(device.getAddress(), candidate.getName(), coordinator.getDeviceType());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user