Lead the run summary with a width-derived artifact grid
In the run detail summary, artifacts now appear at the top of the page and as a grid rather than a list: - RunDetailScreen emits the "run-artifacts" LazyColumn item before the "run-summary" item, so the captured screenshots are the first thing the operator sees. The rest of the summary and its collapsed-by-default sections are unchanged. - ArtifactGallery derives its geometry from the measured width via the new pure artifactGrid(availableWidth, preferred, spacing): it fits as many preferred-shaped cells as the width allows and stretches them to fill the row, instead of the removed fixed ARTIFACT_GRID_COLUMNS count. A host narrower than one preferred cell falls back to a single narrower cell; a non-positive preferred token never divides by zero. Tiles still open the full-size image on tap; non-image artifacts keep their compact list form. - ArtifactGalleryTest replaces the fixed-column cases with grid cases covering a narrow pane (fewer, larger cells), a wide window (more columns), a very wide window (cells near the preferred shape), the single-cell fallback and degenerate inputs, asserting the row never overflows the host. Verified with assembleDebug (APK 17,863,337 bytes, sha256 32e9081b28f5caa85f5bfa24f7fe7149eeddb919d4e71cf497e9017b80f54ce7) and the unit tests (140 tests, 0 failures/errors/skipped); captured on emulator-5554 at both window widths.
This commit is contained in:
@@ -99,9 +99,10 @@ internal fun ArtifactsSection(
|
||||
* hardcodes a host. The grid is built from non-lazy chunked [Row]s, so it never
|
||||
* nests a scrollable inside the Summary [LazyColumn] or the pane's scroll.
|
||||
*
|
||||
* The tile side is derived from the measured width (one [BoxWithConstraints]):
|
||||
* a fixed tile would overflow a narrow phone pane, so each tile is the widest
|
||||
* that fits the row up to the preferred [ARTIFACT_TILE_DP].
|
||||
* The grid geometry is derived from the measured width (one [BoxWithConstraints],
|
||||
* see [artifactGrid]): as many cells as fit at the preferred [ARTIFACT_TILE_DP]
|
||||
* shape, stretched to fill the row, so a wide window shows several thumbnails per
|
||||
* row and a narrow one shows fewer, larger ones — never a fixed column count.
|
||||
*/
|
||||
@Composable
|
||||
internal fun ArtifactGallery(
|
||||
@@ -113,11 +114,10 @@ internal fun ArtifactGallery(
|
||||
) {
|
||||
val text = pipelinesText()
|
||||
BoxWithConstraints(modifier.fillMaxWidth()) {
|
||||
val tile = artifactTileDp(
|
||||
val grid = artifactGrid(
|
||||
availableWidth = maxWidth,
|
||||
columns = ARTIFACT_GRID_COLUMNS,
|
||||
spacing = ARTIFACT_TILE_SPACING_DP,
|
||||
preferred = ARTIFACT_TILE_DP,
|
||||
spacing = ARTIFACT_TILE_SPACING_DP,
|
||||
)
|
||||
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
groups.forEach { group ->
|
||||
@@ -129,17 +129,17 @@ internal fun ArtifactGallery(
|
||||
}
|
||||
val images = group.artifacts.filter { isImageContentType(it.contentType) }
|
||||
val others = group.artifacts.filterNot { isImageContentType(it.contentType) }
|
||||
images.chunked(ARTIFACT_GRID_COLUMNS).forEach { rowArtifacts ->
|
||||
images.chunked(grid.columns).forEach { rowArtifacts ->
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(ARTIFACT_TILE_SPACING_DP),
|
||||
) {
|
||||
rowArtifacts.forEach { artifact ->
|
||||
ArtifactTile(artifact, configuredServerUrl, fetchArtifactBytes, tile)
|
||||
ArtifactTile(artifact, configuredServerUrl, fetchArtifactBytes, grid.cell)
|
||||
}
|
||||
// Keep a partial last row's tiles aligned to the grid.
|
||||
repeat(ARTIFACT_GRID_COLUMNS - rowArtifacts.size) {
|
||||
Box(Modifier.size(tile))
|
||||
repeat(grid.columns - rowArtifacts.size) {
|
||||
Box(Modifier.size(grid.cell))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,15 +152,23 @@ internal fun ArtifactGallery(
|
||||
}
|
||||
|
||||
/**
|
||||
* The side of one square gallery tile: the widest that fits [columns] tiles and
|
||||
* their gaps in [availableWidth], capped at the preferred [preferred] so a wide
|
||||
* window keeps compact thumbnails and a narrow one keeps every tile fully on
|
||||
* screen. Pure, so the fitting is unit-tested without a device.
|
||||
* One gallery row's geometry: the number of cells that fit the measured width at
|
||||
* the preferred tile shape and the side each cell is stretched to. Pure, so the
|
||||
* fitting is unit-tested without a device.
|
||||
*/
|
||||
internal fun artifactTileDp(availableWidth: Dp, columns: Int, spacing: Dp, preferred: Dp): Dp {
|
||||
if (columns <= 0) return preferred
|
||||
val fit = (availableWidth - spacing * (columns - 1)) / columns
|
||||
return fit.coerceIn(0.dp, preferred)
|
||||
internal data class ArtifactGrid(val columns: Int, val cell: Dp)
|
||||
|
||||
/**
|
||||
* The gallery geometry for [availableWidth]: the most [preferred]-shaped cells
|
||||
* that fit with their [spacing] gaps, and each cell widened to fill the row
|
||||
* exactly. A window narrower than one preferred cell falls back to a single,
|
||||
* narrower cell; a non-positive preferred token never divides by zero. Pure.
|
||||
*/
|
||||
internal fun artifactGrid(availableWidth: Dp, preferred: Dp, spacing: Dp): ArtifactGrid {
|
||||
if (preferred <= 0.dp) return ArtifactGrid(columns = 1, cell = availableWidth.coerceAtLeast(0.dp))
|
||||
val columns = ((availableWidth + spacing) / (preferred + spacing)).toInt().coerceAtLeast(1)
|
||||
val cell = ((availableWidth - spacing * (columns - 1)) / columns).coerceAtLeast(0.dp)
|
||||
return ArtifactGrid(columns = columns, cell = cell)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,6 +343,3 @@ private val ARTIFACT_TILE_DP = 96.dp
|
||||
|
||||
/** Gap between gallery thumbnails; shared by the row arrangement and the fitting. */
|
||||
private val ARTIFACT_TILE_SPACING_DP = 8.dp
|
||||
|
||||
/** Image thumbnails per gallery row. */
|
||||
private const val ARTIFACT_GRID_COLUMNS = 3
|
||||
|
||||
@@ -301,6 +301,26 @@ private fun RunSummaryTab(
|
||||
modifier = columnModifier,
|
||||
contentPadding = PaddingValues(vertical = 16.dp),
|
||||
) {
|
||||
// The artifacts gallery leads the summary: the captured screenshots
|
||||
// are the first thing the operator sees, with the run's own facts
|
||||
// below it.
|
||||
item(key = "run-artifacts") {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text("Artifacts", style = text.sectionHeader)
|
||||
if (artifactGroups.isEmpty()) {
|
||||
Text(artifactsEmptyMessage(run.executing), style = text.meta)
|
||||
} else {
|
||||
ArtifactGallery(
|
||||
groups = artifactGroups,
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
item(key = "run-summary") {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
|
||||
@@ -336,23 +356,6 @@ private fun RunSummaryTab(
|
||||
CodeBlock("Diagnostic", run.diagnostic, Modifier.padding(top = 8.dp))
|
||||
}
|
||||
}
|
||||
item(key = "run-artifacts") {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text("Artifacts", style = text.sectionHeader)
|
||||
if (artifactGroups.isEmpty()) {
|
||||
Text(artifactsEmptyMessage(run.executing), style = text.meta)
|
||||
} else {
|
||||
ArtifactGallery(
|
||||
groups = artifactGroups,
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user