From c8be9c21395252b2a0b4e9f096db0a63e7015ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Hu=CC=88sers?= Date: Thu, 21 Mar 2024 16:20:10 +0100 Subject: [PATCH] chore: Force update value on GET - Remove redundant DataBroker prefix from compose view files --- .../kuksa/testapp/KuksaDataBrokerActivity.kt | 1 + ...kerConnectionView.kt => ConnectionView.kt} | 6 ++-- .../testapp/databroker/view/DataBrokerView.kt | 12 +++---- ...aBrokerVssNodesView.kt => VssNodesView.kt} | 33 ++++++++++--------- .../vssnodes/viewmodel/VssNodesViewModel.kt | 4 +++ ...aBrokerVssPathsView.kt => VssPathsView.kt} | 4 +-- 6 files changed, 34 insertions(+), 26 deletions(-) rename app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/connection/view/connection/{DataBrokerConnectionView.kt => ConnectionView.kt} (98%) rename app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/view/{DataBrokerVssNodesView.kt => VssNodesView.kt} (90%) rename app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vsspaths/view/{DataBrokerVssPathsView.kt => VssPathsView.kt} (98%) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt index 0bf81aa4..614d4e15 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/KuksaDataBrokerActivity.kt @@ -371,6 +371,7 @@ class KuksaDataBrokerActivity : ComponentActivity() { if (result == null) return vssNodesViewModel.updateNode(result) + outputViewModel.addOutputEntry("Fetched node: $result") } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/connection/view/connection/DataBrokerConnectionView.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/connection/view/connection/ConnectionView.kt similarity index 98% rename from app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/connection/view/connection/DataBrokerConnectionView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/connection/view/connection/ConnectionView.kt index 515d568b..3ece7805 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/connection/view/connection/DataBrokerConnectionView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/connection/view/connection/ConnectionView.kt @@ -58,7 +58,7 @@ import org.eclipse.kuksa.testapp.extension.compose.RememberCountdown import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository @Composable -fun DataBrokerConnectionView(viewModel: ConnectionViewModel) { +fun ConnectionView(viewModel: ConnectionViewModel) { val keyboardController = LocalSoftwareKeyboardController.current val repositoryConnectionInfoState = @@ -221,7 +221,7 @@ private fun ConnectedPreview() { val connectionInfoRepository = ConnectionInfoRepository(LocalContext.current) val viewModel = ConnectionViewModel(connectionInfoRepository) Surface { - DataBrokerConnectionView(viewModel = viewModel) + ConnectionView(viewModel = viewModel) } } @@ -232,6 +232,6 @@ private fun DisconnectedPreview() { val viewModel = ConnectionViewModel(connectionInfoRepository) viewModel.updateConnectionState(ConnectionViewState.CONNECTING) Surface { - DataBrokerConnectionView(viewModel = viewModel) + ConnectionView(viewModel = viewModel) } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt index 07c244d4..e6a07299 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/view/DataBrokerView.kt @@ -58,14 +58,14 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import org.eclipse.kuksa.testapp.R -import org.eclipse.kuksa.testapp.databroker.connection.view.connection.DataBrokerConnectionView +import org.eclipse.kuksa.testapp.databroker.connection.view.connection.ConnectionView import org.eclipse.kuksa.testapp.databroker.connection.viewmodel.ConnectionViewModel import org.eclipse.kuksa.testapp.databroker.viewmodel.OutputViewModel import org.eclipse.kuksa.testapp.databroker.viewmodel.TopAppBarViewModel import org.eclipse.kuksa.testapp.databroker.viewmodel.TopAppBarViewModel.DataBrokerMode -import org.eclipse.kuksa.testapp.databroker.vssnodes.view.DataBrokerVssNodesView +import org.eclipse.kuksa.testapp.databroker.vssnodes.view.VssNodesView import org.eclipse.kuksa.testapp.databroker.vssnodes.viewmodel.VssNodesViewModel -import org.eclipse.kuksa.testapp.databroker.vsspaths.view.DataBrokerVssPathsView +import org.eclipse.kuksa.testapp.databroker.vsspaths.view.VssPathsView import org.eclipse.kuksa.testapp.databroker.vsspaths.viewmodel.VSSPathsViewModel import org.eclipse.kuksa.testapp.extension.compose.Headline import org.eclipse.kuksa.testapp.extension.compose.OverflowMenu @@ -100,13 +100,13 @@ fun DataBrokerView( ) { Column { if (!connectionViewModel.isConnected) { - DataBrokerConnectionView(connectionViewModel) + ConnectionView(connectionViewModel) } val dataBrokerMode = topAppBarViewModel.dataBrokerMode if (connectionViewModel.isConnected) { when (dataBrokerMode) { - DataBrokerMode.VSS_PATH -> DataBrokerVssPathsView(vssPathsViewModel) - DataBrokerMode.VSS_FILE -> DataBrokerVssNodesView(vssNodesViewModel) + DataBrokerMode.VSS_PATH -> VssPathsView(vssPathsViewModel) + DataBrokerMode.VSS_FILE -> VssNodesView(vssNodesViewModel) } } Spacer(modifier = Modifier.padding(top = DefaultElementPadding)) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/view/DataBrokerVssNodesView.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/view/VssNodesView.kt similarity index 90% rename from app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/view/DataBrokerVssNodesView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/view/VssNodesView.kt index 39b96407..f09c5715 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/view/DataBrokerVssNodesView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/view/VssNodesView.kt @@ -65,13 +65,12 @@ import org.eclipse.kuksa.vsscore.model.VssSignal private const val Tag = "DataBrokerVssNodesView" @Composable -fun DataBrokerVssNodesView(viewModel: VssNodesViewModel) { +fun VssNodesView(viewModel: VssNodesViewModel) { Column { Headline(name = "Generated VSS Nodes") - var currentVssSignal: VssSignal<*>? = null + var currentNode = viewModel.node - val currentNode = viewModel.node val isUpdatePossible = currentNode is VssSignal<*> val adapter = object : SuggestionAdapter { override fun toString(item: VssNode): String { @@ -93,12 +92,12 @@ fun DataBrokerVssNodesView(viewModel: VssNodesViewModel) { ) Spacer(modifier = Modifier.padding(top = DefaultElementPadding)) VssNodeInformation( - currentNode, + viewModel, modifier = Modifier .fillMaxWidth() .padding(start = DefaultEdgePadding, end = DefaultEdgePadding), onSignalChanged = { updatedSignal -> - currentVssSignal = updatedSignal + currentNode = updatedSignal }, ) Spacer(modifier = Modifier.padding(top = DefaultElementPadding)) @@ -116,8 +115,8 @@ fun DataBrokerVssNodesView(viewModel: VssNodesViewModel) { } Button( onClick = { - currentVssSignal?.let { - viewModel.onUpdateSignal(it) + (currentNode as VssSignal<*>?)?.let { vssSignal -> + viewModel.onUpdateSignal(vssSignal) } }, enabled = isUpdatePossible, @@ -146,11 +145,12 @@ fun DataBrokerVssNodesView(viewModel: VssNodesViewModel) { @Composable private fun VssNodeInformation( - vssNode: VssNode, + viewModel: VssNodesViewModel, modifier: Modifier = Modifier, isShowingInformation: Boolean = false, onSignalChanged: (VssSignal<*>) -> Unit = {}, ) { + val vssNode = viewModel.node val isVssSignal = vssNode is VssSignal<*> var isShowingNodeInformation by remember { mutableStateOf(isShowingInformation) } @@ -213,8 +213,7 @@ private fun VssNodeInformation( overflow = TextOverflow.Ellipsis, ) if (isVssSignal) { - val vssSignal = vssNode as VssSignal<*> - VssSignalInformation(vssSignal, onSignalChanged = onSignalChanged) + VssSignalInformation(viewModel, onSignalChanged = onSignalChanged) } } } @@ -230,13 +229,14 @@ private fun VssNodeInformation( @Composable private fun VssSignalInformation( - vssSignal: VssSignal<*>, + viewModel: VssNodesViewModel, modifier: Modifier = Modifier, onSignalChanged: (VssSignal<*>) -> Unit = {}, ) { val boldSpanStyle = SpanStyle(fontWeight = FontWeight.Bold) + val vssSignal = viewModel.node as VssSignal<*> - var inputValue: String by remember(vssSignal) { + var inputValue: String by remember(vssSignal, viewModel.updateCounter) { mutableStateOf(vssSignal.value.toString()) } @@ -254,6 +254,7 @@ private fun VssSignalInformation( onValueChange = { newValue -> inputValue = newValue + // Try and forget approach: Try to brute force the random input string into the VssSignal. @Suppress("TooGenericExceptionCaught") try { val datapoint = vssSignal.valueCase.createDatapoint(newValue.trim()) @@ -277,7 +278,7 @@ private fun VssSignalInformation( @Composable private fun Preview() { KuksaAppAndroidTheme { - DataBrokerVssNodesView(VssNodesViewModel()) + VssNodesView(VssNodesViewModel()) } } @@ -285,7 +286,7 @@ private fun Preview() { @Composable private fun NodeInformationPreview() { KuksaAppAndroidTheme { - VssNodeInformation(VssVehicle(), isShowingInformation = true) + VssNodeInformation(VssNodesViewModel(), isShowingInformation = true) } } @@ -293,6 +294,8 @@ private fun NodeInformationPreview() { @Composable private fun SignalInformationPreview() { KuksaAppAndroidTheme { - VssNodeInformation(VssHeartRate(), isShowingInformation = true) + val vssNodesViewModel = VssNodesViewModel() + vssNodesViewModel.updateNode(VssHeartRate()) + VssNodeInformation(vssNodesViewModel, isShowingInformation = true) } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/viewmodel/VssNodesViewModel.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/viewmodel/VssNodesViewModel.kt index 13afff7d..133b204c 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/viewmodel/VssNodesViewModel.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vssnodes/viewmodel/VssNodesViewModel.kt @@ -47,7 +47,11 @@ class VssNodesViewModel : ViewModel() { var node: VssNode by mutableStateOf(vssVehicle) private set + var updateCounter: Int by mutableStateOf(0) + private set + fun updateNode(node: VssNode) { this.node = node + updateCounter++ } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vsspaths/view/DataBrokerVssPathsView.kt b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vsspaths/view/VssPathsView.kt similarity index 98% rename from app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vsspaths/view/DataBrokerVssPathsView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vsspaths/view/VssPathsView.kt index f5717737..3e6f9df9 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vsspaths/view/DataBrokerVssPathsView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/testapp/databroker/vsspaths/view/VssPathsView.kt @@ -59,7 +59,7 @@ import org.eclipse.kuksa.testapp.extension.compose.SimpleExposedDropdownMenuBox import org.eclipse.kuksa.testapp.ui.theme.KuksaAppAndroidTheme @Composable -fun DataBrokerVssPathsView(viewModel: VSSPathsViewModel) { +fun VssPathsView(viewModel: VSSPathsViewModel) { val dataBrokerProperty = viewModel.dataBrokerProperty var expanded by remember { mutableStateOf(false) } @@ -210,6 +210,6 @@ fun DataBrokerVssPathsView(viewModel: VSSPathsViewModel) { @Composable fun Preview() { KuksaAppAndroidTheme { - DataBrokerVssPathsView(VSSPathsViewModel()) + VssPathsView(VSSPathsViewModel()) } }