mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Fix: Device selection lags (#2086)
This commit is contained in:
parent
faf9f7b0e1
commit
4de1b1516f
3 changed files with 20 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue