Skip to content

Commit b232995

Browse files
committed
applied patch by Florin9doi, see #1088 (comment)
1 parent c17fff3 commit b232995

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,18 @@ private void onDeviceFound(final ScanResult bleScanResult) {
322322
return;
323323
}
324324

325-
BluetoothDeviceView deviceView = new BluetoothDeviceView(context);
326-
deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice()));
327-
328325
String deviceName = device.getName();
329326
if (deviceName == null) {
330327
deviceName = BluetoothFactory.convertNoNameToDeviceName(bleScanResult.getScanRecord().getManufacturerSpecificData());
328+
}
329+
if (deviceName == null) {
330+
return;
331331
}
332332

333+
BluetoothDeviceView deviceView = new BluetoothDeviceView(context);
334+
deviceView.setDeviceName(formatDeviceName(deviceName, device.getAddress()));
335+
deviceView.setAlias(deviceName);
336+
333337
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, deviceName);
334338
if (btDevice != null) {
335339
Timber.d("Found supported device %s (driver: %s)",
@@ -398,6 +402,7 @@ private class BluetoothDeviceView extends LinearLayout implements View.OnClickLi
398402
private TextView deviceName;
399403
private ImageView deviceIcon;
400404
private String deviceAddress;
405+
private String deviceAlias;
401406

402407
public BluetoothDeviceView(Context context) {
403408
super(context);
@@ -427,6 +432,14 @@ public BluetoothDeviceView(Context context) {
427432
addView(deviceName);
428433
}
429434

435+
public void setAlias(String alias) {
436+
deviceAlias = alias;
437+
}
438+
439+
public String getAlias() {
440+
return deviceAlias;
441+
}
442+
430443
public void setDeviceAddress(String address) {
431444
deviceAddress = address;
432445
}
@@ -485,10 +498,10 @@ public void onClick(View view) {
485498

486499
prefs.edit()
487500
.putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress())
488-
.putString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, device.getName())
501+
.putString(PREFERENCE_KEY_BLUETOOTH_DEVICE_NAME, getAlias())
489502
.apply();
490503

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

493506
stopBluetoothDiscovery();
494507

0 commit comments

Comments
 (0)