mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-21 00:14:24 +01:00
Fix UI when bonding required
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
package no.nordicsemi.android.gls.main.view
|
package no.nordicsemi.android.gls.main.view
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
@@ -174,6 +175,8 @@ internal class GLSViewModel @Inject constructor(
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.waitForBonding()
|
||||||
|
|
||||||
client.discoverServices()
|
client.discoverServices()
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.onEach { configureGatt(it, device) }
|
.onEach { configureGatt(it, device) }
|
||||||
@@ -187,7 +190,7 @@ internal class GLSViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
private fun unlockUiIfDisconnected(connectionState: GattConnectionStateWithStatus, device: ServerDevice) {
|
||||||
if (connectionState.state == GattConnectionState.STATE_CONNECTED) {
|
if (connectionState.state == GattConnectionState.STATE_DISCONNECTED) {
|
||||||
_state.value = _state.value.copy(deviceName = device.name)
|
_state.value = _state.value.copy(deviceName = device.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user