Skip to content

Commit

Permalink
chore: Correctly Register DisconnectListener on Orientation Change
Browse files Browse the repository at this point in the history
  • Loading branch information
wba2hi committed Feb 9, 2024
1 parent 2142677 commit f0088e3
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class MainActivity : ComponentActivity() {
private lateinit var doorVehicleScene: DoorVehicleScene

private val disconnectListener = DisconnectListener {
dataBrokerConnection = null
connectionStatusViewModel.connectionState = ConnectionState.DISCONNECTED
}

Expand Down Expand Up @@ -264,6 +265,8 @@ class MainActivity : ComponentActivity() {

private fun subscribe() {
dataBrokerConnection?.apply {
disconnectListeners.register(disconnectListener)

subscribe(VssDoor(), listener = vssDoorListener)
subscribe(VssTrunk(), listener = vssTrunkListener)
subscribe(VssHvac(), listener = vssTemperatureListener)
Expand Down Expand Up @@ -313,9 +316,7 @@ class MainActivity : ComponentActivity() {
connectionStatusViewModel.connectionState = ConnectionState.CONNECTING
val context = this@MainActivity
val dataBrokerConnector = dataBrokerConnectorFactory.create(context, connectionInfo)
dataBrokerConnection = dataBrokerConnector.connect().apply {
disconnectListeners.register(disconnectListener)
}
dataBrokerConnection = dataBrokerConnector.connect()
connectionStatusViewModel.connectionState = ConnectionState.CONNECTED
onConnected()
} catch (e: DataBrokerException) {
Expand Down

0 comments on commit f0088e3

Please sign in to comment.