Skip to content

Commit

Permalink
applied patch by Florin9doi, see #1088 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliexdev committed Nov 29, 2024
1 parent c17fff3 commit b232995
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,18 @@ private void onDeviceFound(final ScanResult bleScanResult) {
return;
}

BluetoothDeviceView deviceView = new BluetoothDeviceView(context);
deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice()));

String deviceName = device.getName();
if (deviceName == null) {
deviceName = BluetoothFactory.convertNoNameToDeviceName(bleScanResult.getScanRecord().getManufacturerSpecificData());
}
if (deviceName == null) {
return;
}

BluetoothDeviceView deviceView = new BluetoothDeviceView(context);
deviceView.setDeviceName(formatDeviceName(deviceName, device.getAddress()));
deviceView.setAlias(deviceName);

BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, deviceName);
if (btDevice != null) {
Timber.d("Found supported device %s (driver: %s)",
Expand Down Expand Up @@ -398,6 +402,7 @@ private class BluetoothDeviceView extends LinearLayout implements View.OnClickLi
private TextView deviceName;
private ImageView deviceIcon;
private String deviceAddress;
private String deviceAlias;

public BluetoothDeviceView(Context context) {
super(context);
Expand Down Expand Up @@ -427,6 +432,14 @@ public BluetoothDeviceView(Context context) {
addView(deviceName);
}

public void setAlias(String alias) {
deviceAlias = alias;
}

public String getAlias() {
return deviceAlias;
}

public void setDeviceAddress(String address) {
deviceAddress = address;
}
Expand Down Expand Up @@ -485,10 +498,10 @@ public void onClick(View view) {

prefs.edit()
.putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress())
.putString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, device.getName())
.putString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, getAlias())
.apply();

Timber.d("Saved Bluetooth device " + device.getName() + " with address " + device.getAddress());
Timber.d("Saved Bluetooth device " + getAlias() + " with address " + device.getAddress());

stopBluetoothDiscovery();

Expand Down

0 comments on commit b232995

Please sign in to comment.