From b232995d47e83cc7ad61bfcddd60d5955afaa9a2 Mon Sep 17 00:00:00 2001 From: oliexdev Date: Fri, 29 Nov 2024 10:56:23 +0100 Subject: [PATCH] applied patch by Florin9doi, see https://github.com/oliexdev/openScale/pull/1088#issuecomment-2496265764 --- .../BluetoothSettingsFragment.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java index 7bea7c1cb..8a4ee30aa 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java @@ -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)", @@ -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); @@ -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; } @@ -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();