Fix UI when device disconnects after bonding failure

This commit is contained in:
Sylwester Zielinski
2023-04-24 17:15:05 +02:00
parent a2e86a819c
commit c623e9f795

View File

@@ -166,6 +166,7 @@ internal class GLSViewModel @Inject constructor(
.filterNotNull()
.onEach { _state.value = _state.value.copyWithNewConnectionState(it) }
.onEach { logAnalytics(it) }
.onEach { unlockUiIfDisconnected(it, device) }
.launchIn(viewModelScope)
if (!client.isConnected) {
@@ -185,6 +186,12 @@ internal class GLSViewModel @Inject constructor(
}
}
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
if (connectionState.state == GattConnectionState.STATE_CONNECTED) {
_state.value = _state.value.copy(deviceName = device.name)
}
}
private suspend fun configureGatt(services: BleGattServices, device: ServerDevice) {
val glsService = services.findService(GLS_SERVICE_UUID)!!
glucoseMeasurementCharacteristic = glsService.findCharacteristic(GM_CHARACTERISTIC)!!