Fix connection details screen
This commit is contained in:
@@ -92,6 +92,7 @@ import io.nekohasekai.sfa.compose.base.UiEvent
|
||||
import io.nekohasekai.sfa.compose.component.ServiceStatusBar
|
||||
import io.nekohasekai.sfa.compose.component.UpdateAvailableDialog
|
||||
import io.nekohasekai.sfa.compose.component.UptimeText
|
||||
import io.nekohasekai.sfa.compose.model.Connection
|
||||
import io.nekohasekai.sfa.compose.navigation.NewProfileArgs
|
||||
import io.nekohasekai.sfa.compose.navigation.ProfileRoutes
|
||||
import io.nekohasekai.sfa.compose.navigation.SFANavHost
|
||||
@@ -979,6 +980,13 @@ class MainActivity :
|
||||
val connectionsUiState by connectionsViewModel.uiState.collectAsState()
|
||||
var selectedConnectionId by remember { mutableStateOf<String?>(null) }
|
||||
val selectedConnection = connectionsUiState.allConnections.find { it.id == selectedConnectionId }
|
||||
var cachedConnection by remember { mutableStateOf<Connection?>(null) }
|
||||
if (selectedConnection != null) {
|
||||
cachedConnection = selectedConnection
|
||||
} else if (selectedConnectionId != null && cachedConnection?.isActive == true) {
|
||||
cachedConnection = cachedConnection?.copy(closedAt = System.currentTimeMillis())
|
||||
}
|
||||
val displayConnection = if (selectedConnectionId != null) cachedConnection else null
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
connectionsViewModel.setVisible(true)
|
||||
@@ -1004,13 +1012,12 @@ class MainActivity :
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight(0.9f),
|
||||
) {
|
||||
if (selectedConnection != null) {
|
||||
if (displayConnection != null) {
|
||||
ConnectionDetailsScreen(
|
||||
connection = selectedConnection,
|
||||
connection = displayConnection,
|
||||
onBack = { selectedConnectionId = null },
|
||||
onClose = {
|
||||
selectedConnectionId?.let { connectionsViewModel.closeConnection(it) }
|
||||
selectedConnectionId = null
|
||||
},
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.nekohasekai.sfa.compose.screen.connections
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.text.selection.SelectionContainer
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
@@ -39,6 +40,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.Velocity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.nekohasekai.libbox.Libbox
|
||||
@@ -324,16 +326,21 @@ private fun DetailRow(label: String, value: String, monospace: Boolean = false,
|
||||
text = label,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(end = 16.dp),
|
||||
)
|
||||
Text(
|
||||
text = value,
|
||||
style = if (monospace) {
|
||||
MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace)
|
||||
} else {
|
||||
MaterialTheme.typography.bodyMedium
|
||||
},
|
||||
color = valueColor,
|
||||
)
|
||||
SelectionContainer(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = value,
|
||||
style = if (monospace) {
|
||||
MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace)
|
||||
} else {
|
||||
MaterialTheme.typography.bodyMedium
|
||||
},
|
||||
color = valueColor,
|
||||
textAlign = TextAlign.End,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -281,6 +281,12 @@ fun ConnectionDetailsRoute(
|
||||
val connection =
|
||||
uiState.allConnections.find { it.id == connectionId }
|
||||
?: uiState.connections.find { it.id == connectionId }
|
||||
var cachedConnection by remember { mutableStateOf(connection) }
|
||||
if (connection != null) {
|
||||
cachedConnection = connection
|
||||
} else if (cachedConnection?.isActive == true) {
|
||||
cachedConnection = cachedConnection?.copy(closedAt = System.currentTimeMillis())
|
||||
}
|
||||
|
||||
OverrideTopBar {
|
||||
TopAppBar(
|
||||
@@ -294,7 +300,7 @@ fun ConnectionDetailsRoute(
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
if (connection?.isActive == true) {
|
||||
if (cachedConnection?.isActive == true) {
|
||||
IconButton(onClick = { viewModel.closeConnection(connectionId) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Close,
|
||||
@@ -320,14 +326,14 @@ fun ConnectionDetailsRoute(
|
||||
viewModel.updateServiceStatus(serviceStatus)
|
||||
}
|
||||
|
||||
if (connection == null) {
|
||||
if (cachedConnection == null) {
|
||||
LaunchedEffect(connectionId) {
|
||||
onBack()
|
||||
}
|
||||
Box(modifier = modifier.fillMaxSize())
|
||||
} else {
|
||||
ConnectionDetailsScreen(
|
||||
connection = connection,
|
||||
connection = cachedConnection!!,
|
||||
onBack = onBack,
|
||||
onClose = { viewModel.closeConnection(connectionId) },
|
||||
modifier = modifier,
|
||||
|
||||
Reference in New Issue
Block a user