feat: create BLEDeviceListEntry class

This commit is contained in:
andrekir 2023-04-01 08:03:32 -03:00
parent d4c125b962
commit effc450af8
2 changed files with 9 additions and 6 deletions

View file

@ -114,6 +114,13 @@ class BTScanModel @Inject constructor(
val isTCP: Boolean get() = prefix == 't'
}
@SuppressLint("MissingPermission")
class BLEDeviceListEntry(device: BluetoothDevice) : DeviceListEntry(
device.name,
"x${device.address}",
device.bondState == BluetoothDevice.BOND_BONDED
)
class USBDeviceListEntry(usbManager: UsbManager, val usb: UsbSerialDriver) : DeviceListEntry(
usb.device.deviceName,
SerialInterface.toInterfaceName(usb.device.deviceName),
@ -332,7 +339,7 @@ class BTScanModel @Inject constructor(
bluetoothRepository.getBondedDevices()
?.filter { it.name != null && it.name.matches(Regex(BLE_NAME_PATTERN)) }
?.forEach {
addDevice(DeviceListEntry(it.name, "x${it.address}", true))
addDevice(BLEDeviceListEntry(it))
}
}

View file

@ -252,11 +252,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
?.let { device ->
scanModel.onSelected(
myActivity,
BTScanModel.DeviceListEntry(
device.name,
"x${device.address}",
device.bondState == BluetoothDevice.BOND_BONDED
)
BTScanModel.BLEDeviceListEntry(device)
)
}
}