10 files changed
+502
-10
No files matched your search
+122
@@ -0,0 +1,122 @@
|
||||
package com.m57.hermescontrol.ui.chat.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.m57.hermescontrol.R
|
||||
import com.m57.hermescontrol.data.model.CatalogScanStatus
|
||||
import com.m57.hermescontrol.data.model.ConnectionCatalogInfo
|
||||
import com.m57.hermescontrol.data.model.ConnectionTargetKind
|
||||
import com.m57.hermescontrol.theme.LocalHermesStatusColors
|
||||
|
||||
private const val SHORT_SHA_LENGTH = 12
|
||||
|
||||
/** What a plugin/skill install row would bring in: source, pin, scan and requirements (#1287). */
|
||||
@Composable
|
||||
internal fun ConnectionCatalogDetails(
|
||||
kind: ConnectionTargetKind,
|
||||
catalog: ConnectionCatalogInfo,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val muted = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
Column(
|
||||
modifier = modifier.testTag("connection_catalog_details"),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
val kindLabel =
|
||||
stringResource(
|
||||
if (kind == ConnectionTargetKind.SKILL) {
|
||||
R.string.connection_catalog_kind_skill
|
||||
} else {
|
||||
R.string.connection_catalog_kind_plugin
|
||||
},
|
||||
)
|
||||
val tierLabel =
|
||||
when (catalog.tier) {
|
||||
null -> null
|
||||
"official" -> stringResource(R.string.connection_catalog_tier_official)
|
||||
"community" -> stringResource(R.string.connection_catalog_tier_community)
|
||||
else -> catalog.tier
|
||||
}
|
||||
Text(
|
||||
text = listOfNotNull(kindLabel, tierLabel).joinToString(" · "),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = muted,
|
||||
)
|
||||
catalog.description?.let { Text(it) }
|
||||
catalog.repo?.let { repo ->
|
||||
val source = catalog.subdir?.let { "$repo/$it" } ?: repo
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_source, source),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_source"),
|
||||
)
|
||||
}
|
||||
catalog.sha?.let { sha ->
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_pin, sha.take(SHORT_SHA_LENGTH)),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_pin"),
|
||||
)
|
||||
}
|
||||
if (catalog.platforms.isNotEmpty()) {
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_platforms, catalog.platforms.joinToString(", ")),
|
||||
color = muted,
|
||||
)
|
||||
}
|
||||
CatalogScanLine(catalog)
|
||||
if (catalog.requirements.isNotEmpty()) {
|
||||
Text(
|
||||
text =
|
||||
stringResource(
|
||||
R.string.connection_catalog_requirements,
|
||||
catalog.requirements.joinToString(", "),
|
||||
),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_requirements"),
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_target_profile, catalog.targetProfile),
|
||||
color = muted,
|
||||
modifier = Modifier.testTag("connection_catalog_profile"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CatalogScanLine(catalog: ConnectionCatalogInfo) {
|
||||
val status = LocalHermesStatusColors.current
|
||||
val scan = catalog.scan
|
||||
val (label, color) =
|
||||
when (scan?.status) {
|
||||
CatalogScanStatus.PASSED -> {
|
||||
R.string.connection_catalog_scan_passed to status.success
|
||||
}
|
||||
|
||||
CatalogScanStatus.WARNINGS -> {
|
||||
R.string.connection_catalog_scan_warnings to status.warning
|
||||
}
|
||||
|
||||
CatalogScanStatus.FAILED -> {
|
||||
R.string.connection_catalog_scan_failed to status.error
|
||||
}
|
||||
|
||||
CatalogScanStatus.UNKNOWN, null -> {
|
||||
R.string.connection_catalog_scan_unreported to MaterialTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
}
|
||||
val summary = scan?.summary
|
||||
Text(
|
||||
text = stringResource(label) + if (summary != null) " · $summary" else "",
|
||||
color = color,
|
||||
modifier = Modifier.testTag("connection_catalog_scan"),
|
||||
)
|
||||
}
|
||||
@@ -102,8 +102,14 @@ internal fun ConnectionSetupContent(
|
||||
.padding(horizontal = 20.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
val catalog = target.catalog
|
||||
Text(
|
||||
text = stringResource(R.string.connection_setup_target_title, target.name),
|
||||
text =
|
||||
if (catalog != null) {
|
||||
stringResource(R.string.connection_catalog_title, catalog.display)
|
||||
} else {
|
||||
stringResource(R.string.connection_setup_target_title, target.name)
|
||||
},
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
modifier = Modifier.testTag("connection_setup_title"),
|
||||
)
|
||||
@@ -120,6 +126,7 @@ internal fun ConnectionSetupContent(
|
||||
target.instructions?.takeIf { it.isNotBlank() }?.let { instructions ->
|
||||
Text(instructions, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
catalog?.let { ConnectionCatalogDetails(kind = target.kind, catalog = it) }
|
||||
|
||||
when {
|
||||
target.state == ConnectionTargetState.CONNECTED && !target.discoveryError.isNullOrBlank() -> {
|
||||
@@ -141,6 +148,12 @@ internal fun ConnectionSetupContent(
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
catalog?.skill?.let { skill ->
|
||||
Text(
|
||||
text = stringResource(R.string.connection_catalog_skill_ready, skill),
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
target.detail?.takeIf { it.isNotBlank() }?.let { detail ->
|
||||
Text(detail, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
@@ -167,6 +180,21 @@ internal fun ConnectionSetupContent(
|
||||
}
|
||||
}
|
||||
|
||||
catalog != null && target.state == ConnectionTargetState.INITIATED -> {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.testTag("connection_catalog_installing"),
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
Text(
|
||||
text =
|
||||
target.detail?.takeIf { it.isNotBlank() }
|
||||
?: stringResource(R.string.connection_catalog_installing),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
target.state == ConnectionTargetState.UNKNOWN ||
|
||||
(target.state == ConnectionTargetState.INITIATED && target.connectUrl != null) -> {
|
||||
Text(
|
||||
@@ -220,7 +248,15 @@ internal fun ConnectionSetupContent(
|
||||
.fillMaxWidth()
|
||||
.testTag("connection_setup_connect"),
|
||||
) {
|
||||
Text(stringResource(R.string.connection_setup_connect))
|
||||
Text(
|
||||
stringResource(
|
||||
when {
|
||||
catalog == null -> R.string.connection_setup_connect
|
||||
target.state == ConnectionTargetState.FAILED -> R.string.connection_catalog_retry
|
||||
else -> R.string.connection_catalog_install
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user