From 410ca2033b1587ebe3e56b2e01445fcec6d11709 Mon Sep 17 00:00:00 2001 From: Grzegorz Miszewski Date: Fri, 13 Oct 2023 14:41:14 +0200 Subject: [PATCH] feat: added is connectable from scan result object --- .../main/java/com/bleplx/adapter/Device.java | 1 - .../RxScanResultToScanResultMapper.java | 24 ++++++++++--------- .../ScanResultToJsObjectConverter.java | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/android/src/main/java/com/bleplx/adapter/Device.java b/android/src/main/java/com/bleplx/adapter/Device.java index 05335267..29d8780a 100755 --- a/android/src/main/java/com/bleplx/adapter/Device.java +++ b/android/src/main/java/com/bleplx/adapter/Device.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.UUID; -/** @noinspection unused*/ public class Device { private String id; diff --git a/android/src/main/java/com/bleplx/adapter/utils/mapper/RxScanResultToScanResultMapper.java b/android/src/main/java/com/bleplx/adapter/utils/mapper/RxScanResultToScanResultMapper.java index 3417b63a..2cf44175 100644 --- a/android/src/main/java/com/bleplx/adapter/utils/mapper/RxScanResultToScanResultMapper.java +++ b/android/src/main/java/com/bleplx/adapter/utils/mapper/RxScanResultToScanResultMapper.java @@ -1,20 +1,22 @@ package com.bleplx.adapter.utils.mapper; +import static com.polidea.rxandroidble2.scan.IsConnectable.CONNECTABLE; + import com.bleplx.adapter.AdvertisementData; import com.bleplx.adapter.ScanResult; import com.bleplx.adapter.utils.Constants; public class RxScanResultToScanResultMapper { - public ScanResult map(com.polidea.rxandroidble2.scan.ScanResult rxScanResult) { - return new ScanResult( - rxScanResult.getBleDevice().getMacAddress(), - rxScanResult.getBleDevice().getName(), - rxScanResult.getRssi(), - Constants.MINIMUM_MTU, - false, //isConnectable flag is not available on Android - null, //overflowServiceUUIDs are not available on Android - AdvertisementData.parseScanResponseData(rxScanResult.getScanRecord().getBytes()) - ); - } + public ScanResult map(com.polidea.rxandroidble2.scan.ScanResult rxScanResult) { + return new ScanResult( + rxScanResult.getBleDevice().getMacAddress(), + rxScanResult.getBleDevice().getName(), + rxScanResult.getRssi(), + Constants.MINIMUM_MTU, + rxScanResult.isConnectable() == CONNECTABLE, + null, //overflowServiceUUIDs are not available on Android + AdvertisementData.parseScanResponseData(rxScanResult.getScanRecord().getBytes()) + ); + } } diff --git a/android/src/main/java/com/bleplx/converter/ScanResultToJsObjectConverter.java b/android/src/main/java/com/bleplx/converter/ScanResultToJsObjectConverter.java index 40cb4ff6..87ed35ea 100644 --- a/android/src/main/java/com/bleplx/converter/ScanResultToJsObjectConverter.java +++ b/android/src/main/java/com/bleplx/converter/ScanResultToJsObjectConverter.java @@ -38,6 +38,7 @@ public WritableMap toJSObject(@NonNull ScanResult scanResult) { result.putString(Metadata.NAME, scanResult.getDeviceName()); result.putInt(Metadata.RSSI, scanResult.getRssi()); result.putInt(Metadata.MTU, scanResult.getMtu()); + result.putBoolean(Metadata.IS_CONNECTABLE, scanResult.isConnectable()); AdvertisementData advData = scanResult.getAdvertisementData(); result.putString(Metadata.MANUFACTURER_DATA, @@ -88,7 +89,6 @@ public WritableMap toJSObject(@NonNull ScanResult scanResult) { } // Attributes which are not accessible on Android - result.putNull(Metadata.IS_CONNECTABLE); result.putNull(Metadata.OVERFLOW_SERVICE_UUIDS); return result; }