Fix: Device selection lags (#2086)

This commit is contained in:
Jeremiah K 2025-06-13 06:34:44 -05:00 committed by GitHub
parent faf9f7b0e1
commit 4de1b1516f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View file

@ -47,7 +47,10 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject
@HiltViewModel
@ -158,7 +161,15 @@ class BTScanModel @Inject constructor(
val selectedBluetooth: Boolean get() = selectedAddress?.getOrNull(0) == 'x'
// / Use the string for the NopInterface
val selectedNotNull: String get() = selectedAddress ?: NO_DEVICE_SELECTED
val selectedAddressFlow: StateFlow<String?> = radioInterfaceService.currentDeviceAddressFlow
val selectedNotNullFlow: StateFlow<String> = selectedAddressFlow
.map { it ?: NO_DEVICE_SELECTED }
.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(SHARING_STARTED_TIMEOUT_MS),
selectedAddressFlow.value ?: NO_DEVICE_SELECTED
)
val scanResult = MutableLiveData<MutableMap<String, DeviceListEntry>>(mutableMapOf())
@ -282,3 +293,4 @@ class BTScanModel @Inject constructor(
}
const val NO_DEVICE_SELECTED = "n"
private const val SHARING_STARTED_TIMEOUT_MS = 5000L