Add unlockUiIfDisconnected to BPS

This commit is contained in:
Sylwester Zielinski
2023-04-25 16:02:33 +02:00
parent 0d6035514d
commit 43c04fc79a

View File

@@ -128,6 +128,7 @@ internal class BPSViewModel @Inject constructor(
.onEach { onDataUpdate(it) }
.onEach { stopIfDisconnected(it.state) }
.onEach { logAnalytics(it.state) }
.onEach { unlockUiIfDisconnected(it, device) }
.launchIn(viewModelScope)
if (!client.isConnected) {
@@ -141,6 +142,12 @@ internal class BPSViewModel @Inject constructor(
.launchIn(viewModelScope)
}
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
_state.value = _state.value.copy(deviceName = device.name)
}
}
private suspend fun configureGatt(services: BleGattServices) {
val bpsService = services.findService(BPS_SERVICE_UUID)!!
val bpmCharacteristic = bpsService.findCharacteristic(BPM_CHARACTERISTIC_UUID)!!