mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
refactor: optimize Bluetooth enabled state handling
This commit is contained in:
parent
f5dff210b0
commit
b792217f2b
1 changed files with 4 additions and 8 deletions
|
|
@ -96,17 +96,13 @@ class BluetoothRepository @Inject constructor(
|
|||
|
||||
@SuppressLint("MissingPermission")
|
||||
internal suspend fun updateBluetoothState() {
|
||||
val newState: BluetoothState = bluetoothAdapterLazy.get()?.takeIf {
|
||||
application.hasBluetoothPermission().also { hasPerms ->
|
||||
if (!hasPerms) errormsg("Still missing needed bluetooth permissions")
|
||||
}
|
||||
}?.let { adapter ->
|
||||
/// ask the adapter if we have access
|
||||
val hasPerms = application.hasBluetoothPermission()
|
||||
val newState: BluetoothState = bluetoothAdapterLazy.get()?.let { adapter ->
|
||||
val enabled = adapter.isEnabled
|
||||
val bondedDevices = adapter.bondedDevices ?: emptySet()
|
||||
val bondedDevices = adapter.takeIf { hasPerms }?.bondedDevices ?: emptySet()
|
||||
|
||||
BluetoothState(
|
||||
hasPermissions = true,
|
||||
hasPermissions = hasPerms,
|
||||
enabled = enabled,
|
||||
bondedDevices = if (!enabled) emptyList()
|
||||
else bondedDevices.filter { it.name?.matches(Regex(BLE_NAME_PATTERN)) == true },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue