diff --git a/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt b/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt index 22d73b3d..f2f0c39e 100644 --- a/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt +++ b/profile_gls/src/main/java/no/nordicsemi/android/gls/main/viewmodel/GLSViewModel.kt @@ -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)!!