Skip to content

Commit

Permalink
Merge pull request #58 from boschglobal/feature-16
Browse files Browse the repository at this point in the history
Add SuggestionSearch for Specification
  • Loading branch information
Chrylo authored Jan 30, 2024
2 parents 47004e0 + e4568aa commit 79e7a19
Show file tree
Hide file tree
Showing 10 changed files with 539 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class KuksaDataBrokerActivity : ComponentActivity() {
override fun onSuccess(result: DataBrokerConnection?) {
outputViewModel.addOutputEntry("Connection to DataBroker successful established")
connectionViewModel.updateConnectionState(ConnectionViewState.CONNECTED)

loadVssPathSuggestions()
}

override fun onError(error: Throwable) {
Expand Down Expand Up @@ -313,4 +315,24 @@ class KuksaDataBrokerActivity : ComponentActivity() {
},
)
}

private fun loadVssPathSuggestions() {
val property = Property("Vehicle", listOf(Field.FIELD_VALUE))

dataBrokerEngine.fetch(
property,
object : CoroutineCallback<GetResponse>() {
override fun onSuccess(result: GetResponse?) {
val entriesList = result?.entriesList
val vssPaths = entriesList?.map { it.path } ?: emptyList()

vssPropertiesViewModel.updateSuggestions(vssPaths)
}

override fun onError(error: Throwable) {
outputViewModel.addOutputEntry(error.toString())
}
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
Expand All @@ -52,7 +53,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel.*
import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel.ConnectionViewState
import org.eclipse.kuksa.testapp.extension.compose.Headline
import org.eclipse.kuksa.testapp.extension.compose.RememberCountdown
import org.eclipse.kuksa.testapp.extension.fetchFileName
Expand All @@ -71,8 +72,9 @@ fun DataBrokerConnection(viewModel: ConnectionViewModel) {
mutableStateOf(connectionInfoState.value)
}

Headline("Connection")
Column {
Headline("Connection")

AnimatedVisibility(visible = viewModel.isDisconnected) {
Column {
Row(
Expand Down Expand Up @@ -223,13 +225,9 @@ fun DataBrokerConnection(viewModel: ConnectionViewModel) {
Text(text = "Connecting... ($timeoutSeconds)", textAlign = TextAlign.Center)
}

ConnectionViewState.CONNECTED ->
Button(
onClick = { viewModel.onDisconnect() },
modifier = Modifier.requiredWidth(MinimumButtonWidth),
) {
Text(text = "Disconnect")
}
ConnectionViewState.CONNECTED -> {
// intentionally left empty
}
}
}
}
Expand All @@ -238,7 +236,21 @@ fun DataBrokerConnection(viewModel: ConnectionViewModel) {

@Preview
@Composable
fun DataBrokerConnectionPreview() {
private fun ConnectedPreview() {
val connectionInfoRepository = ConnectionInfoRepository(LocalContext.current)
DataBrokerConnection(viewModel = ConnectionViewModel(connectionInfoRepository))
val viewModel = ConnectionViewModel(connectionInfoRepository)
Surface {
DataBrokerConnection(viewModel = viewModel)
}
}

@Preview
@Composable
private fun DisconnectedPreview() {
val connectionInfoRepository = ConnectionInfoRepository(LocalContext.current)
val viewModel = ConnectionViewModel(connectionInfoRepository)
viewModel.updateConnectionState(ConnectionViewState.CONNECTING)
Surface {
DataBrokerConnection(viewModel = viewModel)
}
}
Loading

0 comments on commit 79e7a19

Please sign in to comment.