Properly consume disconnected state

This commit is contained in:
Sylwester Zielinski
2023-04-27 13:47:57 +02:00
parent 1d8181c968
commit 77c0d057b5
10 changed files with 18 additions and 16 deletions

View File

@@ -83,7 +83,7 @@ fun BPSScreen() {
null,
GattConnectionState.STATE_CONNECTING -> DeviceConnectingView { NavigateUpButton(navigateUp) }
GattConnectionState.STATE_DISCONNECTED,
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(Reason.UNKNOWN) {
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(state.result.connectionState.status) {
NavigateUpButton(navigateUp)
}
GattConnectionState.STATE_CONNECTED -> BPSContentView(state.result) { viewModel.onEvent(it) }

View File

@@ -40,18 +40,13 @@ import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.cgms.R
import no.nordicsemi.android.cgms.data.CGMServiceData
import no.nordicsemi.android.cgms.viewmodel.CGMViewModel
import no.nordicsemi.android.common.ui.scanner.view.DeviceConnectingView
import no.nordicsemi.android.common.ui.scanner.view.DeviceDisconnectedView
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
import no.nordicsemi.android.ui.view.BackIconAppBar
import no.nordicsemi.android.ui.view.LoggerBackIconAppBar
import no.nordicsemi.android.ui.view.LoggerIconAppBar
import no.nordicsemi.android.ui.view.NavigateUpButton
import no.nordicsemi.android.ui.view.ProfileAppBar

View File

@@ -86,7 +86,7 @@ fun CSCScreen() {
null,
GattConnectionState.STATE_CONNECTING -> DeviceConnectingView { NavigateUpButton(navigateUp) }
GattConnectionState.STATE_DISCONNECTED,
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(Reason.UNKNOWN) {
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(state.connectionState.status) {
NavigateUpButton(navigateUp)
}
GattConnectionState.STATE_CONNECTED -> CSCContentView(state) { viewModel.onEvent(it) }

View File

@@ -84,7 +84,7 @@ fun GLSScreen() {
null,
GattConnectionState.STATE_CONNECTING -> DeviceConnectingView { NavigateUpButton(navigateUp) }
GattConnectionState.STATE_DISCONNECTED,
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(Reason.UNKNOWN) {
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(state.glsServiceData.connectionState.status) {
NavigateUpButton(navigateUp)
}
GattConnectionState.STATE_CONNECTED -> GLSContentView(state.glsServiceData) { viewModel.onEvent(it) }

View File

@@ -83,7 +83,7 @@ fun HRSScreen() {
null,
GattConnectionState.STATE_CONNECTING -> DeviceConnectingView { NavigateUpButton(navigateUp) }
GattConnectionState.STATE_DISCONNECTED,
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(Reason.UNKNOWN) {
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(state.connectionState.status) {
NavigateUpButton(navigateUp)
}
GattConnectionState.STATE_CONNECTED -> HRSContentView(state) { viewModel.onEvent(it) }

View File

@@ -94,9 +94,12 @@ class HTSRepository @Inject constructor(
_loggerEvent.tryEmit(OpenLoggerEvent())
}
fun release() {
logger = null
_data.value = HTSServiceData()
fun disconnect() {
_stopEvent.tryEmit(DisconnectAndStopEvent())
}
fun clear() {
logger = null
_data.value = HTSServiceData()
}
}

View File

@@ -144,4 +144,9 @@ internal class HTSService : NotificationService() {
private fun disconnect() {
client.disconnect()
}
override fun onDestroy() {
super.onDestroy()
repository.clear()
}
}

View File

@@ -44,7 +44,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import no.nordicsemi.android.common.ui.scanner.view.DeviceConnectingView
import no.nordicsemi.android.common.ui.scanner.view.DeviceDisconnectedView
import no.nordicsemi.android.common.ui.scanner.view.Reason
import no.nordicsemi.android.hts.R
import no.nordicsemi.android.hts.viewmodel.HTSViewModel
import no.nordicsemi.android.kotlin.ble.core.data.GattConnectionState
@@ -84,7 +83,7 @@ fun HTSScreen() {
null,
GattConnectionState.STATE_CONNECTING -> DeviceConnectingView { NavigateUpButton(navigateUp) }
GattConnectionState.STATE_DISCONNECTED,
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(Reason.UNKNOWN) {
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(state.connectionState.status) {
NavigateUpButton(navigateUp)
}
GattConnectionState.STATE_CONNECTED -> HTSContentView(state) { viewModel.onEvent(it) }

View File

@@ -114,7 +114,7 @@ internal class HTSViewModel @Inject constructor(
}
private fun disconnect() {
repository.release()
repository.disconnect()
navigationManager.navigateUp()
}

View File

@@ -83,7 +83,7 @@ fun RSCSScreen() {
null,
GattConnectionState.STATE_CONNECTING -> DeviceConnectingView { NavigateUpButton(navigateUp) }
GattConnectionState.STATE_DISCONNECTED,
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(Reason.UNKNOWN) {
GattConnectionState.STATE_DISCONNECTING -> DeviceDisconnectedView(state.connectionState.status) {
NavigateUpButton(navigateUp)
}
GattConnectionState.STATE_CONNECTED -> RSCSContentView(state) { viewModel.onEvent(it) }