From f0088e3c8e80d0975ef44260be65a9a3d01c8d95 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Fri, 9 Feb 2024 11:35:23 +0100 Subject: [PATCH] chore: Correctly Register DisconnectListener on Orientation Change --- .../kotlin/org/eclipse/kuksa/companion/MainActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt index 74652ed..401acdc 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt @@ -77,6 +77,7 @@ class MainActivity : ComponentActivity() { private lateinit var doorVehicleScene: DoorVehicleScene private val disconnectListener = DisconnectListener { + dataBrokerConnection = null connectionStatusViewModel.connectionState = ConnectionState.DISCONNECTED } @@ -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) @@ -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) {