Skip to content

Commit

Permalink
chore: Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrylo committed Oct 16, 2023
1 parent c9765aa commit 2f411f8
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 301 deletions.
8 changes: 1 addition & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,9 @@ tasks.withType<Test>().configureEach {
}
}

plugins {
id("com.android.application")
kotlin("plugin.serialization") version "1.9.0"
kotlin("android")
}

dependencies {
implementation(project(":kuksa-sdk"))
ksp(project(":vss-processor"))
ksp(project(":vss-processor"))
testImplementation(project(":test"))

implementation(libs.androidx.appcompat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.eclipse.kuksa.proto.v1.Types.Datapoint;
import org.eclipse.kuksa.testapp.databroker.model.Certificate;
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo;
import org.eclipse.kuksa.testapp.extension.AssetManagerExtensionKt;
import org.eclipse.kuksa.vsscore.model.VssSpecification;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -103,14 +102,18 @@ private void connectSecure(
) {
Certificate certificate = connectInfo.getCertificate();

ChannelCredentials tlsCredentials = null;
ChannelCredentials tlsCredentials;
try {
InputStream rootCertFile = context.getContentResolver().openInputStream(certificate.getUri());
if (rootCertFile == null) return;

tlsCredentials = TlsChannelCredentials.newBuilder()
.trustManager(rootCertFile)
.build();
} catch (IOException e) {
Log.w(TAG, "Could not find file for certificate: " + certificate);

return;
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import org.eclipse.kuksa.testapp.databroker.viewmodel.TopAppBarViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.VSSPropertiesViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.VssSpecificationsViewModel
import org.eclipse.kuksa.testapp.extension.TAG
import org.eclipse.kuksa.testapp.extension.valueType
import org.eclipse.kuksa.testapp.model.ConnectionInfo
import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository
import org.eclipse.kuksa.testapp.ui.theme.KuksaAppAndroidTheme
import org.eclipse.kuksa.vsscore.annotation.VssDefinition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ interface DataBrokerEngine {
callback: CoroutineCallback<GetResponse>,
)

fun <T : VssSpecification> fetch(specification: T, callback: CoroutineCallback<T>)

fun update(
property: Property,
datapoint: Datapoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ import org.eclipse.kuksa.proto.v1.KuksaValV1.GetResponse
import org.eclipse.kuksa.proto.v1.KuksaValV1.SetResponse
import org.eclipse.kuksa.proto.v1.Types.Datapoint
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.extension.open
import org.eclipse.kuksa.vsscore.model.VssSpecification
import org.eclipse.kuksa.testapp.model.ConnectionInfo
import java.io.IOException

@Suppress("complexity:TooManyFunctions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
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.extension.compose.Headline
import org.eclipse.kuksa.testapp.extension.compose.rememberCountdown
import org.eclipse.kuksa.testapp.extension.fetchFileName
import org.eclipse.kuksa.testapp.model.ConnectionInfo
import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository

@OptIn(ExperimentalComposeUiApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

package org.eclipse.kuksa.testapp.databroker.view

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -73,12 +71,8 @@ import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import kotlinx.coroutines.launch
import org.eclipse.kuksa.proto.v1.Types.Datapoint.ValueCase
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.OutputViewModel
Expand All @@ -90,7 +84,6 @@ import org.eclipse.kuksa.testapp.extension.compose.Headline
import org.eclipse.kuksa.testapp.extension.compose.LazyDropdownMenu
import org.eclipse.kuksa.testapp.extension.compose.OverflowMenu
import org.eclipse.kuksa.testapp.extension.compose.SimpleExposedDropdownMenuBox
import org.eclipse.kuksa.testapp.extension.compose.rememberCountdown
import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository
import org.eclipse.kuksa.testapp.ui.theme.KuksaAppAndroidTheme

Expand Down Expand Up @@ -196,211 +189,6 @@ private fun TopBar(
)
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun DataBrokerConnection(viewModel: ConnectionViewModel) {
val keyboardController = LocalSoftwareKeyboardController.current

val connectionInfoState by viewModel.connectionInfoFlow.collectAsStateWithLifecycle(initialValue = ConnectionInfo())

var connectionInfo by remember(connectionInfoState) {
mutableStateOf(connectionInfoState)
}

Headline("Connection")
Column {
AnimatedVisibility(visible = viewModel.isDisconnected) {
Column {
Row(
Modifier
.fillMaxWidth()
.padding(start = DefaultEdgePadding, end = DefaultEdgePadding),
horizontalArrangement = Arrangement.SpaceEvenly,
) {
TextField(
value = connectionInfo.host,
onValueChange = {
val newConnectionInfo = connectionInfoState.copy(host = it)
connectionInfo = newConnectionInfo
},
keyboardActions = KeyboardActions(
onDone = {
viewModel.updateConnectionInfo(connectionInfo)
keyboardController?.hide()
},
),
modifier = Modifier
.weight(2f),
singleLine = true,
label = {
Text(text = "Host")
},
)
Text(
text = ":",
modifier = Modifier
.padding(start = 5.dp, end = 5.dp)
.align(Alignment.CenterVertically),
)
TextField(
value = connectionInfo.port.toString(),
onValueChange = { value ->
try {
val port = value.toInt()
val newConnectionInfo = connectionInfo.copy(port = port)
connectionInfo = newConnectionInfo
} catch (e: NumberFormatException) {
// ignore gracefully
}
},
keyboardActions = KeyboardActions(
onDone = {
viewModel.updateConnectionInfo(connectionInfo)
keyboardController?.hide()
},
),
modifier = Modifier
.weight(1f),
singleLine = true,
label = {
Text(text = "Port")
},
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
)
}
Spacer(modifier = Modifier.padding(top = DefaultElementPadding))
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = DefaultEdgePadding, end = DefaultEdgePadding),
) {
Text(text = "TLS:")
Checkbox(checked = connectionInfo.isTlsEnabled, onCheckedChange = { isChecked ->
val newConnectionInfo = connectionInfo.copy(isTlsEnabled = isChecked)
viewModel.updateConnectionInfo(newConnectionInfo)
})
TextField(
value = connectionInfo.certificate.overrideAuthority,
onValueChange = {
val certificate = connectionInfo.certificate.copy(overrideAuthority = it)
val newConnectionInfo = connectionInfo.copy(certificate = certificate)
connectionInfo = newConnectionInfo
},
keyboardActions = KeyboardActions(
onDone = {
viewModel.updateConnectionInfo(connectionInfo)
keyboardController?.hide()
},
),
modifier = Modifier.weight(2f),
singleLine = true,
enabled = connectionInfo.isTlsEnabled,
label = {
Text(text = "Authority override")
},
)
}
Spacer(modifier = Modifier.padding(top = DefaultElementPadding))
}
}
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly,
) {
AnimatedContent(
targetState = viewModel.connectionViewState,
label = "ConnectAnimation",
) { connectionViewState ->
when (connectionViewState) {
ConnectionViewState.DISCONNECTED ->
Button(
onClick = {
viewModel.onConnect(connectionInfo)

keyboardController?.hide()
},
modifier = Modifier.width(MinimumButtonWidth),
) {
Text(text = "Connect", textAlign = TextAlign.Center)
}

ConnectionViewState.CONNECTING ->
Button(
onClick = { },
modifier = Modifier.requiredWidth(MinimumButtonWidth),
) {
val timeout by rememberCountdown(initialMillis = viewModel.connectionTimeoutMillis)

@Suppress("MagicNumber") // To seconds
val timeoutSeconds = timeout / 1000
Text(text = "Connecting... ($timeoutSeconds)", textAlign = TextAlign.Center)
}

ConnectionViewState.CONNECTED ->
Button(
onClick = { viewModel.onDisconnect() },
modifier = Modifier.requiredWidth(MinimumButtonWidth),
) {
Text(text = "Disconnect")
}
}
}
}
}
}

@Composable
fun OverflowMenu(content: @Composable () -> Unit) {
var showMenu by remember { mutableStateOf(false) }

IconButton(onClick = {
showMenu = !showMenu
}) {
Icon(
imageVector = Icons.Outlined.MoreVert,
contentDescription = "Options",
)
}
DropdownMenu(
expanded = showMenu,
onDismissRequest = { showMenu = false },
) {
content()
}
}

@Composable
fun Headline(name: String, modifier: Modifier = Modifier, color: Color = Color.Black) {
Text(
text = name,
modifier = modifier
.fillMaxWidth()
.padding(top = 15.dp, bottom = 15.dp),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge,
color = color,
)
}

@Composable
fun rememberCountdown(
initialMillis: Long,
step: Long = 1000,
): MutableState<Long> {
val timeLeft = remember { mutableStateOf(initialMillis) }

LaunchedEffect(initialMillis, step) {
while (isActive && timeLeft.value > 0) {
val newTimeLeft = (timeLeft.value - step).coerceAtLeast(0)
timeLeft.value = newTimeLeft

val maximumDelay = step.coerceAtMost(newTimeLeft)
delay(maximumDelay)
}
}

return timeLeft
}

@Composable
fun DataBrokerSpecifications(viewModel: VssSpecificationsViewModel) {
Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@

package org.eclipse.kuksa.testapp.databroker.viewmodel

import android.app.Application
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
Expand Down Expand Up @@ -76,6 +73,7 @@ class ConnectionViewModel(private val connectionInfoRepository: ConnectionInfoRe
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return ConnectionViewModel(connectionInfoRepository) as T
}
}

companion object {
private const val TIMEOUT_DEFAULT = 5_000L
Expand Down

This file was deleted.

Loading

0 comments on commit 2f411f8

Please sign in to comment.