Render every artifact in the shared gallery, with file-type icons
Standardise the artifacts gallery so the run summary and the stage pane render one tile per artifact instead of images as a grid and everything else as a plain list. - Artifacts.kt: ArtifactTile now covers both shapes - an image/video fills the cell with a thumbnail (a video shows its poster frame with a play badge), anything else shows its file-type icon with the name and size beneath it; the grid, share/copy actions and multi-select are unchanged and the capture wording is untouched. - ArtifactType.kt (new): pure ArtifactKind classification from content type plus name extension fallback, and artifactIcon(kind) mapping each kind to a distinct glyph. - ArtifactImage.kt: ArtifactVideoFrame/rememberArtifactVideoFrame extract a poster frame via MediaMetadataRetriever over an in-memory MediaDataSource; the shared memoized-preview scaffold is factored into rememberArtifactPreview. - ArtifactViewer.kt: full-screen viewer takes a video flag and shows the poster frame. - Format.kt: add isVideoContentType; drop the now-unused artifactMetaLine. - Dimens.kt: ARTIFACT_TYPE_ICON_DP, ARTIFACT_PLAY_BADGE_DP, ARTIFACT_TILE_ACTION_DP tokens. - Tests: new ArtifactTypeTest (type-to-icon mapping, extension fallback, distinct glyphs); FormatTest updated for the removed helper. - android/README.md documents the pass. android/ only; no new dependencies beyond material-icons-extended.
This commit is contained in:
@@ -3441,3 +3441,142 @@ native 2208x1840 @420 at the end.
|
||||
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
|
||||
`Content-Length: 17928873`.
|
||||
|
||||
|
||||
## One artifacts gallery everywhere, with a type icon for non-media (16 Oct 2026)
|
||||
|
||||
The gallery was already a grid, but only for images: non-image artifacts fell
|
||||
through to a plain one-per-row list beneath it, so the same run rendered two
|
||||
different ways. This pass makes `ArtifactGallery` the single rendering path for
|
||||
every artifact (the run summary and the stage pane's per-visit section already
|
||||
both use it) and gives non-media files a tile too. `android/` only; no
|
||||
dependency was added (the new glyphs are `material-icons-extended`), no run was
|
||||
started from the app, and every `adb` command targeted `emulator-5554` (never
|
||||
`emulator-5556` or the attached Pixel).
|
||||
|
||||
- **One tile, two shapes.** `ui/graph/Artifacts.kt`'s `ArtifactTile` replaces the
|
||||
old `ArtifactTile` + `ArtifactRow` split. An image fills the cell with its
|
||||
thumbnail; a video shows its still/poster frame with a centred play marker on
|
||||
top; anything else shows its file-type icon with the artifact's name and
|
||||
human-readable size beneath it, all in the same width-derived grid. The grid is
|
||||
still built from non-lazy chunked `Row`s, so it never nests a scrollable inside
|
||||
the Summary `LazyColumn` or the pane's scroll.
|
||||
- **Type-to-icon mapping.** The new pure `ui/graph/ArtifactType.kt` classifies an
|
||||
artifact from its content type (parameters tolerated) and, when the server's
|
||||
sniff is generic, its name's extension, into `ArtifactKind`
|
||||
(Image/Video/Audio/Pdf/Json/Archive/Spreadsheet/Log/Code/Document/Other), and
|
||||
`artifactIcon(kind)` gives each kind a distinct shape (PDF, JSON, archive,
|
||||
spreadsheet, log, code, document, audio, generic file). `Format.kt` gained the
|
||||
companion `isVideoContentType` predicate beside `isImageContentType`.
|
||||
- **Video poster frame.** `ui/graph/ArtifactImage.kt` gained
|
||||
`ArtifactVideoFrame`/`rememberArtifactVideoFrame`: the artifact's bytes are
|
||||
fetched through the same bounded cache as an image and the representative sync
|
||||
frame is extracted with the platform `MediaMetadataRetriever` over an in-memory
|
||||
`MediaDataSource` (no temp file, no new dependency, no inline playback). The
|
||||
full-screen viewer takes a `video` flag and shows that frame (its open action
|
||||
plays the clip externally); a fetch/extraction failure falls back to the video
|
||||
glyph rather than a fabricated image.
|
||||
- **Actions kept.** Tap opens the viewer for an image/video and the existing
|
||||
external-open action for anything else; every tile keeps its share control, a
|
||||
non-media tile adds the copy-link control, and long-press / multi-select, the
|
||||
contextual bar, bulk copy/share and the selection semantics are unchanged.
|
||||
The capture summary and partial-capture notes are byte-for-byte unchanged.
|
||||
- **Geometry from tokens, not literals.** `ui/theme/Dimens.kt` gains
|
||||
`ARTIFACT_TYPE_ICON_DP` (28dp), `ARTIFACT_PLAY_BADGE_DP` (32dp) and
|
||||
`ARTIFACT_TILE_ACTION_DP` (32dp); the tile still stretches `ARTIFACT_TILE_DP`
|
||||
cells across the measured width via the unchanged pure `artifactGrid`.
|
||||
|
||||
Review follow-up (same pass, no UI change): the two preview state-holders
|
||||
duplicated the whole memoize-through-caches scaffold, so it is now one private
|
||||
`rememberArtifactPreview(url, maxDim, keyTag, fetchBytes, derive)` that both
|
||||
`rememberArtifactBitmap` and `rememberArtifactVideoFrame` delegate to (the
|
||||
`keyTag` keeps the two cache entries apart); the video fallback draws
|
||||
`artifactIcon(ArtifactKind.Video)` instead of a hardcoded `Icons.Filled.Movie`;
|
||||
and the now-unused `Format.kt` `artifactMetaLine` helper (its last caller was the
|
||||
deleted non-image row) was removed with its `FormatTest` cases.
|
||||
|
||||
Verified on this tree (macOS, Homebrew `openjdk@25`,
|
||||
`JAVA_HOME=/opt/homebrew/opt/openjdk@25/libexec/openjdk.jdk/Contents/Home`,
|
||||
Gradle 9.7.1, `ANDROID_HOME=/Users/alan/Library/Android/sdk`, `--offline`):
|
||||
|
||||
- `gradle --offline :app:testDebugUnitTest --rerun-tasks` → `BUILD SUCCESSFUL`;
|
||||
the 31 test-result XMLs aggregate to **265 tests, 0 failures, 0 errors, 0
|
||||
skipped** (the new `ui/graph/ArtifactTypeTest` has 6 cases: the media kinds
|
||||
from the content type, the named kinds, the extension fallback for a generic
|
||||
sniff, the never-crash `Other` fallback, the explicit type-to-icon mapping, and
|
||||
that no two kinds share a glyph). `ArtifactGalleryTest` still covers the grid
|
||||
sizing (narrow → fewer, larger cells; wider → more preferred-shaped columns;
|
||||
degenerate inputs). `compileDebugKotlin` emits no warnings.
|
||||
- `gradle --offline :app:assembleDebug --rerun-tasks --no-build-cache` succeeded
|
||||
→ `app-debug.apk` **18,011,393 bytes**, sha256
|
||||
`faa9df077c960b23eef4afbac1b7effa1a50180eabcee2d638cabb232974cfa8`.
|
||||
- On `emulator-5554` (native 2076x2152 @390; `wm size`/`wm density` used for the
|
||||
narrow pass and reset afterwards) against the live server
|
||||
`ws://10.0.2.2:8080/connect`, driven with `adb shell input` and `uiautomator
|
||||
dump`; every capture was written with
|
||||
`android/scripts/capture_png.sh -s emulator-5554` (validated PNG, named display
|
||||
id) into `…/artifacts/140/1/`. Run 136's `implementer` visit 1 is a real mixed
|
||||
set: five `image/png` screenshots plus `chat_stub_approval.py`
|
||||
(`text/plain`, code glyph) and `stub.log` (`text/plain`, log glyph).
|
||||
- **Wide** (2076x2152 ≈ 532dp): `evidence_wide_run136_summary_gallery.png`
|
||||
shows the five thumbnails with their share controls and, in the same grid,
|
||||
the `.py` tile with the `<>` code glyph and the `.log` tile with the log
|
||||
glyph, each with its name and `9.3 KiB` / `220 B` beneath it and the copy +
|
||||
share actions; `evidence_wide_run136_stage_pane.png` shows the same gallery in
|
||||
the stage pane under the unchanged `Artifacts · 7 recorded · partial capture`
|
||||
wording and the `1 files excluded from artifact capture.` note.
|
||||
- **Narrow** (1080x2340 @480 ≈ 360dp):
|
||||
`evidence_narrow_run136_summary_gallery.png` and
|
||||
`evidence_narrow_run136_stage_pane.png` show three cells per row with the
|
||||
thumbnails and the code/log type tiles still legible.
|
||||
- Tapping a thumbnail opened the full-screen viewer
|
||||
(`evidence_wide_run136_image_viewer.png`; `uiautomator dump` reported the
|
||||
`01_approval_pending.png` image plus `Open … externally`, `Copy link …` and
|
||||
`Close viewer`), and the non-media tiles' `Copy link to …` / `Share …`
|
||||
controls are present in the accessibility tree.
|
||||
- `adb -s emulator-5554 logcat -d | grep -cE 'FATAL EXCEPTION|E
|
||||
AndroidRuntime'` returned 0; the emulator display was reset to native
|
||||
2076x2152 @390 afterwards.
|
||||
- **APK publish.** `app-debug.apk` copied to
|
||||
`…/artifacts/140/1/pipelines-debug-wip-c700b28.apk` (`c700b28` = short
|
||||
`HEAD`); `shasum -a 256` matched. `curl -I
|
||||
http://10.0.0.249:8080/artifacts/140/1/pipelines-debug-wip-c700b28.apk`
|
||||
returned `HTTP/1.1 200 OK`, `Content-Type:
|
||||
application/vnd.android.package-archive`, `Content-Length: 18011393`, and a
|
||||
streamed `GET | shasum -a 256` returned the same `faa9df07…` as the local file.
|
||||
At ~17.2 MiB it exceeds the server's 8 MiB per-file inventory cap, so it is
|
||||
served by direct URL only.
|
||||
|
||||
Not verified in this pass: a **video** artifact does not exist on the live server
|
||||
and starting a run is forbidden, so the play-marker/poster-frame render is
|
||||
covered only by the `artifactKind` unit test (`video/mp4 → Video`) and the code
|
||||
path, not by a device capture; the non-media external-open tap was not driven
|
||||
(no handler is guaranteed on the emulator); multi-select/bulk share were not
|
||||
re-exercised on device (their code is unchanged from the previous pass); the
|
||||
light theme and `:app:lintDebug` were not run (the only known lint issues are the
|
||||
two pre-existing `NewApi` errors for `android:windowLightNavigationBar`).
|
||||
|
||||
### Review fixes (same pass)
|
||||
|
||||
The review's three findings were addressed with no intended UI change, and the
|
||||
two build checks were re-run on the resulting tree:
|
||||
|
||||
- `gradle --offline :app:testDebugUnitTest --rerun-tasks` → `BUILD SUCCESSFUL`;
|
||||
the 31 result XMLs again aggregate to **265 tests, 0 failures, 0 errors, 0
|
||||
skipped** (the removed `artifactMetaLine` assertions were replaced by
|
||||
`isVideoContentType` coverage in the same `FormatTest` method).
|
||||
- `gradle --offline :app:assembleDebug --rerun-tasks --no-build-cache` succeeded
|
||||
→ `app-debug.apk` **18,011,393 bytes**, sha256
|
||||
`2adaf03e5ac0bdb29b012d1487a0e10917f8ebabda973ddc63c7315b6df25dda`; it was
|
||||
published to `…/artifacts/140/3/pipelines-debug-wip-c700b28.apk` and
|
||||
`curl -I http://10.0.0.249:8080/artifacts/140/3/pipelines-debug-wip-c700b28.apk`
|
||||
returned `HTTP/1.1 200 OK`, `Content-Length: 18011393`, with a streamed
|
||||
`GET | shasum -a 256` matching the local `2adaf03e…`.
|
||||
|
||||
The device render was **not** re-captured: `emulator-5554` is shared and, while
|
||||
this pass ran, another lane replaced the installed app with a build whose dex has
|
||||
no `ArtifactType` class (`dumpsys package … lastUpdateTime` moved from this pass's
|
||||
`16:24:02` install to `16:24:20`, and the installed `base.apk` sha no longer
|
||||
matched `2adaf03e…`), so any capture could not be attributed to this build. The
|
||||
wide/narrow captures above predate the refactor; the refactor changes no UI
|
||||
pixels, so they remain representative of the gallery this code renders.
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import kotlinx.serialization.json.JsonPrimitive
|
||||
import net.awan.pipelines.data.protocol.FileChange
|
||||
import net.awan.pipelines.data.protocol.NotificationReceipt
|
||||
import net.awan.pipelines.data.protocol.RunStep
|
||||
import net.awan.pipelines.data.protocol.StageArtifact
|
||||
import net.awan.pipelines.data.protocol.StageFileChanges
|
||||
|
||||
/**
|
||||
@@ -138,6 +137,12 @@ fun humanBytes(size: Long): String {
|
||||
/** Whether an artifact's content type is an image the sheet can preview. */
|
||||
fun isImageContentType(contentType: String): Boolean = contentType.startsWith("image/")
|
||||
|
||||
/**
|
||||
* Whether an artifact's content type is a video. Videos are shown in the gallery
|
||||
* as a still/poster frame with a play marker; they are never decoded inline.
|
||||
*/
|
||||
fun isVideoContentType(contentType: String): Boolean = contentType.startsWith("video/")
|
||||
|
||||
/**
|
||||
* The "capture pending" wording shared by a running visit's summary and the
|
||||
* run-level empty state, so the two never spell it differently.
|
||||
@@ -176,10 +181,3 @@ fun artifactCaptureNotes(step: RunStep): List<String> = buildList {
|
||||
if (step.artifactsSkipped > 0) add("${step.artifactsSkipped} files excluded from artifact capture.")
|
||||
if (step.artifactsTruncated > 0) add("${step.artifactsTruncated} files omitted by artifact capture limits.")
|
||||
}
|
||||
|
||||
/**
|
||||
* One artifact's meta line: its human-readable size and content type. A blank or
|
||||
* missing content type never renders as a dangling separator.
|
||||
*/
|
||||
fun artifactMetaLine(artifact: StageArtifact): String =
|
||||
"${humanBytes(artifact.sizeBytes)} · ${artifact.contentType.ifBlank { "unknown type" }}"
|
||||
|
||||
@@ -2,6 +2,8 @@ package net.awan.pipelines.ui.graph
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.media.MediaDataSource
|
||||
import android.media.MediaMetadataRetriever
|
||||
import android.util.LruCache
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -28,6 +30,7 @@ import kotlinx.coroutines.withContext
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_PROGRESS_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_PROGRESS_STROKE_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_THUMB_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_TYPE_ICON_DP
|
||||
|
||||
/**
|
||||
* Encoded artifact bytes, fetched at most once per url and kept in memory so a
|
||||
@@ -126,9 +129,25 @@ internal fun rememberArtifactBitmap(
|
||||
url: String?,
|
||||
maxDim: Int,
|
||||
fetchBytes: suspend (String) -> ByteArray?,
|
||||
): ArtifactImageState = rememberArtifactPreview(url, maxDim, "", fetchBytes, ::decodeSampled)
|
||||
|
||||
/**
|
||||
* The shared memoized-preview scaffold behind [rememberArtifactBitmap] and
|
||||
* [rememberArtifactVideoFrame]: a null [url] is [ArtifactImageState.Unavailable]
|
||||
* with no request attempted, otherwise the bytes are fetched once through
|
||||
* [ArtifactBytesCache] and [derive] runs off the main thread, its bitmap cached
|
||||
* under a [keyTag]-tagged key (so an image and a video of one url never collide).
|
||||
*/
|
||||
@Composable
|
||||
private fun rememberArtifactPreview(
|
||||
url: String?,
|
||||
maxDim: Int,
|
||||
keyTag: String,
|
||||
fetchBytes: suspend (String) -> ByteArray?,
|
||||
derive: (ByteArray, Int) -> Bitmap?,
|
||||
): ArtifactImageState {
|
||||
if (url == null) return ArtifactImageState.Unavailable
|
||||
val key = "$url@$maxDim"
|
||||
val key = "$url@$keyTag$maxDim"
|
||||
var state by remember(key) { mutableStateOf<ArtifactImageState>(ArtifactImageState.Loading) }
|
||||
LaunchedEffect(key) {
|
||||
artifactBitmapCache.get(key)?.let {
|
||||
@@ -142,7 +161,7 @@ internal fun rememberArtifactBitmap(
|
||||
return@LaunchedEffect
|
||||
}
|
||||
ArtifactBytesCache.put(url, bytes)
|
||||
val bitmap = withContext(Dispatchers.IO) { decodeSampled(bytes, maxDim) }
|
||||
val bitmap = withContext(Dispatchers.IO) { derive(bytes, maxDim) }
|
||||
if (bitmap == null) {
|
||||
state = ArtifactImageState.Error
|
||||
} else {
|
||||
@@ -153,6 +172,106 @@ internal fun rememberArtifactBitmap(
|
||||
return state
|
||||
}
|
||||
|
||||
/**
|
||||
* A video tile's still/poster frame: the artifact's bytes are fetched through the
|
||||
* same bounded, off-main-thread path as an image ([rememberArtifactBitmap]'s
|
||||
* cache), then the first sync frame is extracted with the platform
|
||||
* [MediaMetadataRetriever] and cached. [url] null (no configured server) shows
|
||||
* [ArtifactImageState.Unavailable] and issues no request; a fetch or extraction
|
||||
* failure shows [ArtifactImageState.Error]. Unlike an image there is no honest
|
||||
* "still" without a decodable frame, so both non-`Ready` states fall back to the
|
||||
* video glyph the gallery would otherwise use.
|
||||
*/
|
||||
@Composable
|
||||
internal fun ArtifactVideoFrame(
|
||||
url: String?,
|
||||
contentDescription: String?,
|
||||
fetchBytes: suspend (String) -> ByteArray?,
|
||||
modifier: Modifier = Modifier,
|
||||
size: Dp = ARTIFACT_THUMB_DP,
|
||||
) {
|
||||
val state = rememberArtifactVideoFrame(url, VIDEO_FRAME_MAX_DIM, fetchBytes)
|
||||
Box(modifier.size(size), contentAlignment = Alignment.Center) {
|
||||
when (val current = state) {
|
||||
is ArtifactImageState.Ready -> Image(
|
||||
bitmap = current.bitmap.asImageBitmap(),
|
||||
contentDescription = contentDescription,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.size(size),
|
||||
)
|
||||
ArtifactImageState.Loading -> CircularProgressIndicator(
|
||||
modifier = Modifier.size(ARTIFACT_PROGRESS_DP),
|
||||
strokeWidth = ARTIFACT_PROGRESS_STROKE_DP,
|
||||
)
|
||||
ArtifactImageState.Unavailable, ArtifactImageState.Error -> Icon(
|
||||
imageVector = artifactIcon(ArtifactKind.Video),
|
||||
contentDescription = contentDescription,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.size(ARTIFACT_TYPE_ICON_DP),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The state of a video's poster frame at up to [maxDim] on its longest edge (0
|
||||
* for the platform's native resolution). Same caching and off-main-thread
|
||||
* behaviour as [rememberArtifactBitmap]; the full-size viewer shares it so a
|
||||
* video's still is extracted once.
|
||||
*/
|
||||
@Composable
|
||||
internal fun rememberArtifactVideoFrame(
|
||||
url: String?,
|
||||
maxDim: Int,
|
||||
fetchBytes: suspend (String) -> ByteArray?,
|
||||
): ArtifactImageState = rememberArtifactPreview(url, maxDim, "video", fetchBytes, ::extractVideoFrame)
|
||||
|
||||
/**
|
||||
* The representative sync frame of [bytes] as a [maxDim]-bounded bitmap (native
|
||||
* when [maxDim] <= 0), or null when the bytes are not a decodable video (or the
|
||||
* platform retriever fails). Runs off the main thread; the bytes are handed over
|
||||
* through an in-memory [MediaDataSource], so no temporary file is written.
|
||||
*/
|
||||
private fun extractVideoFrame(bytes: ByteArray, maxDim: Int): Bitmap? = runCatching {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
try {
|
||||
retriever.setDataSource(ByteArrayMediaDataSource(bytes))
|
||||
retriever.getFrameAtTime(-1L, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
|
||||
} finally {
|
||||
runCatching { retriever.release() }
|
||||
}
|
||||
}.getOrNull()?.let { scaleToMaxDim(it, maxDim) }
|
||||
|
||||
/** The in-memory [MediaDataSource] over fetched video [data] (no temp file). */
|
||||
private class ByteArrayMediaDataSource(private val data: ByteArray) : MediaDataSource() {
|
||||
override fun readAt(position: Long, buffer: ByteArray, offset: Int, size: Int): Int {
|
||||
if (position < 0 || position >= data.size) return -1
|
||||
val count = minOf(size.toLong(), data.size - position).toInt()
|
||||
System.arraycopy(data, position.toInt(), buffer, offset, count)
|
||||
return count
|
||||
}
|
||||
|
||||
override fun getSize(): Long = data.size.toLong()
|
||||
|
||||
override fun close() = Unit
|
||||
}
|
||||
|
||||
/** [bitmap] scaled so its longest edge is at most [maxDim] (native when <= 0). */
|
||||
private fun scaleToMaxDim(bitmap: Bitmap, maxDim: Int): Bitmap {
|
||||
val longest = maxOf(bitmap.width, bitmap.height)
|
||||
if (maxDim <= 0 || longest <= maxDim || longest == 0) return bitmap
|
||||
val scale = maxDim.toFloat() / longest
|
||||
return Bitmap.createScaledBitmap(
|
||||
bitmap,
|
||||
(bitmap.width * scale).toInt().coerceAtLeast(1),
|
||||
(bitmap.height * scale).toInt().coerceAtLeast(1),
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
/** Longest edge of a video poster-frame decode (the same shape as an image thumbnail). */
|
||||
private const val VIDEO_FRAME_MAX_DIM = 320
|
||||
|
||||
/**
|
||||
* Decodes [bytes], downsampling to roughly [maxDim] on the longest edge when
|
||||
* [maxDim] > 0 (so the list never holds full-resolution bitmaps), or at full
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package net.awan.pipelines.ui.graph
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
|
||||
import androidx.compose.material.icons.filled.AudioFile
|
||||
import androidx.compose.material.icons.filled.Code
|
||||
import androidx.compose.material.icons.filled.DataObject
|
||||
import androidx.compose.material.icons.filled.Description
|
||||
import androidx.compose.material.icons.filled.FolderZip
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.Movie
|
||||
import androidx.compose.material.icons.filled.PictureAsPdf
|
||||
import androidx.compose.material.icons.automirrored.filled.ReceiptLong
|
||||
import androidx.compose.material.icons.filled.TableChart
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import net.awan.pipelines.ui.isImageContentType
|
||||
import net.awan.pipelines.ui.isVideoContentType
|
||||
|
||||
/**
|
||||
* What an artifact's file type is, from the app's point of view: the two media
|
||||
* kinds the gallery previews (image, video) and the file kinds it labels with a
|
||||
* type icon (everything else). It is the one classification the gallery branches
|
||||
* on, so the grid, the tile and the icon can never disagree about a file.
|
||||
*/
|
||||
internal enum class ArtifactKind {
|
||||
Image,
|
||||
Video,
|
||||
Audio,
|
||||
Pdf,
|
||||
Json,
|
||||
Archive,
|
||||
Spreadsheet,
|
||||
Log,
|
||||
Code,
|
||||
Document,
|
||||
Other,
|
||||
}
|
||||
|
||||
/**
|
||||
* The gallery kind of an artifact from its [contentType] (server-sniffed, may
|
||||
* carry parameters) and its [name] (the extension is the fallback when the sniff
|
||||
* is generic `text/plain`/`application/octet-stream`). Image and video are
|
||||
* recognised straight from the content type; the rest are matched by the
|
||||
* normalised mime first, then by the name's extension. Pure and total, so the
|
||||
* type-to-icon mapping is unit-tested without a device.
|
||||
*/
|
||||
internal fun artifactKind(contentType: String, name: String): ArtifactKind {
|
||||
if (isImageContentType(contentType)) return ArtifactKind.Image
|
||||
if (isVideoContentType(contentType)) return ArtifactKind.Video
|
||||
val mime = contentType.substringBefore(';').trim().lowercase()
|
||||
val ext = name.substringAfterLast('.', "").lowercase()
|
||||
return when {
|
||||
mime.startsWith("audio/") -> ArtifactKind.Audio
|
||||
mime == "application/pdf" || ext == "pdf" -> ArtifactKind.Pdf
|
||||
mime.contains("json") || ext == "json" -> ArtifactKind.Json
|
||||
mime in ARCHIVE_MIMES || ext in ARCHIVE_EXTENSIONS -> ArtifactKind.Archive
|
||||
mime in SPREADSHEET_MIMES || ext in SPREADSHEET_EXTENSIONS -> ArtifactKind.Spreadsheet
|
||||
ext == "log" -> ArtifactKind.Log
|
||||
mime == "text/html" -> ArtifactKind.Document
|
||||
mime in CODE_MIMES || ext in CODE_EXTENSIONS -> ArtifactKind.Code
|
||||
mime.startsWith("text/") || mime in DOCUMENT_MIMES || ext in DOCUMENT_EXTENSIONS -> ArtifactKind.Document
|
||||
else -> ArtifactKind.Other
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The glyph that names [kind] in the gallery: a distinct [ImageVector] per kind
|
||||
* (its own shape, not colour alone), so a document, archive, log, code file, JSON
|
||||
* payload and PDF are told apart at a glance. Pure, so the mapping is unit-tested.
|
||||
*/
|
||||
internal fun artifactIcon(kind: ArtifactKind): ImageVector = when (kind) {
|
||||
ArtifactKind.Image -> Icons.Filled.Image
|
||||
ArtifactKind.Video -> Icons.Filled.Movie
|
||||
ArtifactKind.Audio -> Icons.Filled.AudioFile
|
||||
ArtifactKind.Pdf -> Icons.Filled.PictureAsPdf
|
||||
ArtifactKind.Json -> Icons.Filled.DataObject
|
||||
ArtifactKind.Archive -> Icons.Filled.FolderZip
|
||||
ArtifactKind.Spreadsheet -> Icons.Filled.TableChart
|
||||
ArtifactKind.Log -> Icons.AutoMirrored.Filled.ReceiptLong
|
||||
ArtifactKind.Code -> Icons.Filled.Code
|
||||
ArtifactKind.Document -> Icons.Filled.Description
|
||||
ArtifactKind.Other -> Icons.AutoMirrored.Filled.InsertDriveFile
|
||||
}
|
||||
|
||||
private val ARCHIVE_EXTENSIONS =
|
||||
setOf("zip", "tar", "gz", "tgz", "bz2", "xz", "rar", "7z", "jar", "war")
|
||||
|
||||
private val ARCHIVE_MIMES = setOf(
|
||||
"application/zip",
|
||||
"application/gzip",
|
||||
"application/x-tar",
|
||||
"application/x-7z-compressed",
|
||||
"application/x-rar-compressed",
|
||||
"application/java-archive",
|
||||
)
|
||||
|
||||
private val SPREADSHEET_EXTENSIONS = setOf("csv", "tsv", "xls", "xlsx", "ods")
|
||||
|
||||
private val SPREADSHEET_MIMES = setOf(
|
||||
"text/csv",
|
||||
"text/tab-separated-values",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
)
|
||||
|
||||
private val CODE_EXTENSIONS = setOf(
|
||||
"kt", "kts", "java", "go", "py", "rb", "php", "rs", "c", "h", "cc", "cpp",
|
||||
"hpp", "cs", "js", "jsx", "ts", "tsx", "mjs", "cjs", "swift", "scala", "sh",
|
||||
"bash", "zsh", "fish", "ps1", "sql", "yaml", "yml", "toml", "ini", "xml",
|
||||
"gradle", "properties", "proto",
|
||||
)
|
||||
|
||||
private val CODE_MIMES = setOf(
|
||||
"application/xml",
|
||||
"application/x-yaml",
|
||||
"application/javascript",
|
||||
"text/javascript",
|
||||
"text/x-python",
|
||||
"text/x-java-source",
|
||||
"text/x-kotlin",
|
||||
"application/x-sh",
|
||||
"application/x-httpd-php",
|
||||
"application/sql",
|
||||
)
|
||||
|
||||
private val DOCUMENT_EXTENSIONS =
|
||||
setOf("txt", "md", "markdown", "rst", "doc", "docx", "odt", "rtf", "html", "htm")
|
||||
|
||||
private val DOCUMENT_MIMES = setOf(
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/rtf",
|
||||
)
|
||||
@@ -61,10 +61,12 @@ import net.awan.pipelines.ui.theme.pipelinesText
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* The full-screen image viewer opened by tapping a gallery thumbnail (the run
|
||||
* summary grid, the per-visit artifacts list and the stage pane all render
|
||||
* through [ArtifactGallery], so they all open this). It replaces the former
|
||||
* small centred dialog rather than stacking on top of it.
|
||||
* The full-screen media viewer opened by tapping a gallery tile (the run summary
|
||||
* grid, the per-visit artifacts section and the stage pane all render through
|
||||
* [ArtifactGallery], so they all open this): an image at full size, or a video's
|
||||
* poster frame (the platform retriever extracts it, [video] = true) with the
|
||||
* external-open action to actually play it. It replaces the former small centred
|
||||
* dialog rather than stacking on top of it.
|
||||
*
|
||||
* It is a [Dialog] whose window is laid out edge to edge (`decorFitsSystemWindows
|
||||
* = false`): the dark [MaterialTheme.colorScheme.scrim] backdrop fills the whole
|
||||
@@ -87,6 +89,7 @@ internal fun ArtifactViewer(
|
||||
name: String,
|
||||
fetchBytes: suspend (String) -> ByteArray?,
|
||||
onDismiss: () -> Unit,
|
||||
video: Boolean = false,
|
||||
) {
|
||||
Dialog(
|
||||
onDismissRequest = onDismiss,
|
||||
@@ -131,11 +134,23 @@ internal fun ArtifactViewer(
|
||||
.background(MaterialTheme.colorScheme.scrim)
|
||||
.windowInsetsPadding(paneSafeArea()),
|
||||
) {
|
||||
when (val state = rememberArtifactBitmap(url, FULL_RESOLUTION, fetchBytes)) {
|
||||
val state = if (video) {
|
||||
rememberArtifactVideoFrame(url, FULL_RESOLUTION, fetchBytes)
|
||||
} else {
|
||||
rememberArtifactBitmap(url, FULL_RESOLUTION, fetchBytes)
|
||||
}
|
||||
when (state) {
|
||||
is ArtifactImageState.Ready -> ZoomableArtifact(state.bitmap, name, url, onDismiss)
|
||||
ArtifactImageState.Loading -> ViewerMessage("Loading image…", spinner = true)
|
||||
ArtifactImageState.Error -> ViewerMessage("Couldn't load image.")
|
||||
ArtifactImageState.Unavailable -> ViewerMessage("Image unavailable.")
|
||||
ArtifactImageState.Loading -> ViewerMessage(
|
||||
if (video) "Loading video frame…" else "Loading image…",
|
||||
spinner = true,
|
||||
)
|
||||
ArtifactImageState.Error -> ViewerMessage(
|
||||
if (video) "Couldn't load the video frame." else "Couldn't load image.",
|
||||
)
|
||||
ArtifactImageState.Unavailable -> ViewerMessage(
|
||||
if (video) "Video unavailable." else "Image unavailable.",
|
||||
)
|
||||
}
|
||||
ArtifactViewerActions(
|
||||
name = name,
|
||||
|
||||
@@ -9,24 +9,24 @@ import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
|
||||
import androidx.compose.material.icons.automirrored.filled.OpenInNew
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.ContentCopy
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.filled.Share
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -41,6 +41,7 @@ import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.semantics.selected
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -50,13 +51,14 @@ import net.awan.pipelines.data.protocol.StageArtifact
|
||||
import net.awan.pipelines.data.transport.ServerUrl
|
||||
import net.awan.pipelines.ui.ArtifactGroup
|
||||
import net.awan.pipelines.ui.artifactCaptureNotes
|
||||
import net.awan.pipelines.ui.artifactMetaLine
|
||||
import net.awan.pipelines.ui.artifactsSummary
|
||||
import net.awan.pipelines.ui.components.copyText
|
||||
import net.awan.pipelines.ui.isImageContentType
|
||||
import net.awan.pipelines.ui.humanBytes
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_BADGE_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_THUMB_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_PLAY_BADGE_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_TILE_ACTION_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_TILE_DP
|
||||
import net.awan.pipelines.ui.theme.ARTIFACT_TYPE_ICON_DP
|
||||
import net.awan.pipelines.ui.theme.SPACING_M
|
||||
import net.awan.pipelines.ui.theme.SPACING_S
|
||||
import net.awan.pipelines.ui.theme.SPACING_XS
|
||||
@@ -70,7 +72,7 @@ import net.awan.pipelines.ui.theme.pipelinesText
|
||||
* rendering path; it resolves each url against the configured server URL and
|
||||
* never hardcodes a host.
|
||||
*
|
||||
* When no server URL is configured the rows still show (name/size/type) but the
|
||||
* When no server URL is configured the tiles still show (name/size/type) but the
|
||||
* open/copy actions are disabled and a hint is shown.
|
||||
*/
|
||||
@Composable
|
||||
@@ -112,17 +114,18 @@ internal fun ArtifactsSection(
|
||||
}
|
||||
|
||||
/**
|
||||
* The artifacts gallery: one group per (stage, visit) with a header, the group's
|
||||
* image artifacts as a grid of thumbnails (a tap opens the full-size view) and
|
||||
* its non-image artifacts as rows with name, size, content type and open/copy.
|
||||
* Every url is resolved with [ServerUrl.resolveArtifactUrl], so nothing here
|
||||
* 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 artifacts gallery: one group per (stage, visit) with a header and every
|
||||
* artifact as a tile in a grid. An image shows its thumbnail, a video its
|
||||
* still/poster frame with a play marker on top, and anything else its file-type
|
||||
* icon with the name and size beneath it. Every url is resolved with
|
||||
* [ServerUrl.resolveArtifactUrl], so nothing here 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 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.
|
||||
* shape, stretched to fill the row, so a wide window shows several tiles per row
|
||||
* and a narrow one shows fewer, larger ones — never a fixed column count.
|
||||
*/
|
||||
@Composable
|
||||
internal fun ArtifactGallery(
|
||||
@@ -149,9 +152,7 @@ internal fun ArtifactGallery(
|
||||
style = text.sectionHeader,
|
||||
)
|
||||
}
|
||||
val images = group.artifacts.filter { isImageContentType(it.contentType) }
|
||||
val others = group.artifacts.filterNot { isImageContentType(it.contentType) }
|
||||
images.chunked(grid.columns).forEach { rowArtifacts ->
|
||||
group.artifacts.chunked(grid.columns).forEach { rowArtifacts ->
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(ARTIFACT_TILE_SPACING_DP),
|
||||
@@ -172,15 +173,6 @@ internal fun ArtifactGallery(
|
||||
}
|
||||
}
|
||||
}
|
||||
others.forEach { artifact ->
|
||||
ArtifactRow(
|
||||
artifact = artifact,
|
||||
configuredServerUrl = configuredServerUrl,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
selection = selection,
|
||||
onSelectionChange = onSelectionChange,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,22 +201,24 @@ internal fun artifactGrid(availableWidth: Dp, preferred: Dp, spacing: Dp): Artif
|
||||
/**
|
||||
* The absolute url a gallery artifact is previewed/opened at, or null when it
|
||||
* cannot be resolved against the configured server (blank or invalid). The one
|
||||
* place a gallery artifact url is resolved, shared by the image tile and the
|
||||
* non-image row so the two can never disagree. A null must never reach a fetch:
|
||||
* a server-relative url has no scheme and can never load, so the tile renders the
|
||||
* distinct "unavailable" state instead of the failure mark.
|
||||
* place a gallery artifact url is resolved, shared by every tile so they can
|
||||
* never disagree. A null must never reach a fetch: a server-relative url has no
|
||||
* scheme and can never load, so the tile renders the distinct "unavailable"
|
||||
* state instead of the failure mark.
|
||||
*/
|
||||
internal fun resolvedArtifactUrl(artifact: StageArtifact, configuredServerUrl: String): String? =
|
||||
ServerUrl.resolveArtifactUrl(configuredServerUrl, artifact.url)
|
||||
|
||||
/**
|
||||
* One image artifact as a square thumbnail that opens the full-size view. A
|
||||
* long-press enters artifact selection on this item; while selection mode is
|
||||
* active a tap toggles it instead of opening, and the selected cell gets the
|
||||
* app's selected treatment (a tonal ring + check badge in the shared
|
||||
* secondaryContainer/onSecondaryContainer roles, and the `selected` semantics
|
||||
* state). The per-item share control is hidden while selecting so the whole cell
|
||||
* is the toggle target.
|
||||
* One gallery tile. An image or video fills the cell with its thumbnail (a video
|
||||
* with a play marker on top) and opens the full-screen viewer on tap; any other
|
||||
* type shows its file-type icon with the name and size beneath it and opens
|
||||
* externally on tap. A long-press enters artifact selection on this item; while
|
||||
* selection mode is active a tap toggles it instead of opening, and the selected
|
||||
* cell gets the app's selected treatment (a tonal ring + check badge in the
|
||||
* shared secondaryContainer/onSecondaryContainer roles, and the `selected`
|
||||
* semantics state). The per-item actions are hidden while selecting so the whole
|
||||
* cell is the toggle target.
|
||||
*/
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
@@ -236,10 +230,15 @@ private fun ArtifactTile(
|
||||
selection: ArtifactSelection,
|
||||
onSelectionChange: (ArtifactSelection) -> Unit,
|
||||
) {
|
||||
// Resolve once per (url, configuration), not on every recomposition.
|
||||
val context = LocalContext.current
|
||||
// Resolve and classify once per data change, not on every recomposition.
|
||||
val resolved = remember(artifact.url, configuredServerUrl) {
|
||||
resolvedArtifactUrl(artifact, configuredServerUrl)
|
||||
}
|
||||
val kind = remember(artifact.contentType, artifact.name) {
|
||||
artifactKind(artifact.contentType, artifact.name)
|
||||
}
|
||||
val media = kind == ArtifactKind.Image || kind == ArtifactKind.Video
|
||||
var showFull by remember(artifact.url) { mutableStateOf(false) }
|
||||
val selected = selection.contains(artifact.url)
|
||||
|
||||
@@ -247,6 +246,13 @@ private fun ArtifactTile(
|
||||
Modifier
|
||||
.size(tile)
|
||||
.clip(MaterialTheme.shapes.medium)
|
||||
.background(
|
||||
if (selected) {
|
||||
MaterialTheme.colorScheme.secondaryContainer
|
||||
} else {
|
||||
MaterialTheme.colorScheme.surfaceContainerHigh
|
||||
},
|
||||
)
|
||||
.then(
|
||||
if (selected) {
|
||||
Modifier.border(3.dp, MaterialTheme.colorScheme.secondary, MaterialTheme.shapes.medium)
|
||||
@@ -256,10 +262,12 @@ private fun ArtifactTile(
|
||||
)
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (selection.active) {
|
||||
onSelectionChange(selection.toggle(artifact.url))
|
||||
} else if (resolved != null) {
|
||||
showFull = true
|
||||
when {
|
||||
selection.active -> onSelectionChange(selection.toggle(artifact.url))
|
||||
// An image or video opens the full-screen viewer; any
|
||||
// other type uses the existing open action.
|
||||
media -> if (resolved != null) showFull = true
|
||||
else -> openArtifact(context, resolved)
|
||||
}
|
||||
},
|
||||
onLongClick = { onSelectionChange(selection.enter(artifact.url)) },
|
||||
@@ -267,20 +275,20 @@ private fun ArtifactTile(
|
||||
)
|
||||
.semantics { this.selected = selected },
|
||||
) {
|
||||
// Pass the resolved url (null when there is no configured server): a
|
||||
// null never triggers a relative-url fetch, it shows the distinct
|
||||
// "unavailable" state instead of the failure mark.
|
||||
ArtifactImage(
|
||||
url = resolved,
|
||||
contentDescription = "Preview of ${artifact.name}",
|
||||
maxDim = THUMBNAIL_MAX_DIM,
|
||||
fetchBytes = fetchArtifactBytes,
|
||||
size = tile,
|
||||
)
|
||||
if (media) {
|
||||
ArtifactMediaPreview(
|
||||
kind = kind,
|
||||
name = artifact.name,
|
||||
resolved = resolved,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
tile = tile,
|
||||
)
|
||||
} else {
|
||||
ArtifactTypeLabel(kind = kind, artifact = artifact)
|
||||
}
|
||||
if (selection.active) {
|
||||
// While the gallery is selecting, no item exposes its own share
|
||||
// control: every tap toggles, so only the selected cells carry the
|
||||
// check badge and the whole tile stays a toggle target.
|
||||
// While the gallery is selecting, no item exposes its own actions:
|
||||
// every tap toggles, so only the selected cells carry the check badge.
|
||||
if (selected) {
|
||||
Box(
|
||||
Modifier
|
||||
@@ -298,21 +306,20 @@ private fun ArtifactTile(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// The share control is its own hit area over the thumbnail: it
|
||||
// consumes the tap, so sharing never falls through to open the
|
||||
// full-size view.
|
||||
ArtifactShareButton(
|
||||
// The per-item share (and, for a non-media tile, copy) controls are
|
||||
// their own hit areas over the tile: they consume the tap, so an
|
||||
// action never falls through to open the artifact.
|
||||
ArtifactTileActions(
|
||||
artifact = artifact,
|
||||
resolved = resolved,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
modifier = Modifier.align(Alignment.TopEnd),
|
||||
scrim = true,
|
||||
media = media,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// The tap opens the full-screen viewer (one shared instance across the run
|
||||
// summary grid, the per-visit list and the stage pane, so they never
|
||||
// summary grid, the per-visit section and the stage pane, so they never
|
||||
// disagree); there is no separate smaller preview to stack on top of it.
|
||||
if (showFull && resolved != null) {
|
||||
ArtifactViewer(
|
||||
@@ -320,135 +327,155 @@ private fun ArtifactTile(
|
||||
name = artifact.name,
|
||||
fetchBytes = fetchArtifactBytes,
|
||||
onDismiss = { showFull = false },
|
||||
video = kind == ArtifactKind.Video,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One non-image artifact: a file glyph, name, size/type and open/share/copy
|
||||
* actions. A long-press enters artifact selection on this item; while selection
|
||||
* mode is active a tap toggles it and the row wears the app's selected treatment
|
||||
* (the secondaryContainer/onSecondaryContainer roles the list rows use, plus the
|
||||
* `selected` semantics state), with the per-item actions swapped for a check.
|
||||
* When not selecting, a tap opens the artifact.
|
||||
* A media tile's content: the image thumbnail, or a video's still/poster frame
|
||||
* with a centred play marker on top of it. Both load through the same bounded,
|
||||
* off-main-thread cache, so a media tile never re-hits the network on a
|
||||
* recomposition.
|
||||
*/
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
private fun ArtifactRow(
|
||||
artifact: StageArtifact,
|
||||
configuredServerUrl: String,
|
||||
private fun BoxScope.ArtifactMediaPreview(
|
||||
kind: ArtifactKind,
|
||||
name: String,
|
||||
resolved: String?,
|
||||
fetchArtifactBytes: suspend (String) -> ByteArray?,
|
||||
selection: ArtifactSelection,
|
||||
onSelectionChange: (ArtifactSelection) -> Unit,
|
||||
tile: Dp,
|
||||
) {
|
||||
val text = pipelinesText()
|
||||
val context = LocalContext.current
|
||||
val clipboard = LocalClipboardManager.current
|
||||
// Resolve/format once per (url, configuration), not on every recomposition.
|
||||
val resolved = remember(artifact.url, configuredServerUrl) {
|
||||
resolvedArtifactUrl(artifact, configuredServerUrl)
|
||||
}
|
||||
val metaLine = remember(artifact) { artifactMetaLine(artifact) }
|
||||
val selected = selection.contains(artifact.url)
|
||||
|
||||
Surface(
|
||||
shape = MaterialTheme.shapes.medium,
|
||||
color = if (selected) {
|
||||
MaterialTheme.colorScheme.secondaryContainer
|
||||
} else {
|
||||
MaterialTheme.colorScheme.surfaceContainerHigh
|
||||
},
|
||||
contentColor = if (selected) {
|
||||
MaterialTheme.colorScheme.onSecondaryContainer
|
||||
} else {
|
||||
LocalContentColor.current
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.combinedClickable(
|
||||
onClick = {
|
||||
if (selection.active) {
|
||||
onSelectionChange(selection.toggle(artifact.url))
|
||||
} else {
|
||||
openArtifact(context, resolved)
|
||||
}
|
||||
},
|
||||
onLongClick = { onSelectionChange(selection.enter(artifact.url)) },
|
||||
onLongClickLabel = "Select ${artifact.name}",
|
||||
)
|
||||
.semantics { this.selected = selected },
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = SPACING_S, vertical = SPACING_S),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(SPACING_M),
|
||||
if (kind == ArtifactKind.Video) {
|
||||
ArtifactVideoFrame(
|
||||
url = resolved,
|
||||
contentDescription = "Poster frame of $name",
|
||||
fetchBytes = fetchArtifactBytes,
|
||||
size = tile,
|
||||
)
|
||||
Box(
|
||||
Modifier
|
||||
.align(Alignment.Center)
|
||||
.size(ARTIFACT_PLAY_BADGE_DP)
|
||||
.background(
|
||||
MaterialTheme.colorScheme.scrim.copy(alpha = ARTIFACT_ACTION_SCRIM_ALPHA),
|
||||
CircleShape,
|
||||
),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Box(
|
||||
Modifier.size(ARTIFACT_THUMB_DP).clip(MaterialTheme.shapes.small),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.InsertDriveFile,
|
||||
contentDescription = null,
|
||||
tint = LocalContentColor.current,
|
||||
)
|
||||
}
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(SPACING_XXS)) {
|
||||
Text(
|
||||
artifact.name.ifBlank { "(unnamed artifact)" },
|
||||
style = text.cardTitle,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
Text(
|
||||
metaLine,
|
||||
style = text.meta,
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
if (selection.active) {
|
||||
// While selecting, the row's own open/copy/share controls are
|
||||
// hidden so a tap anywhere on it toggles the selection instead
|
||||
// of acting on the single item; only the selected row shows the
|
||||
// check.
|
||||
if (selected) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Check,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(horizontal = SPACING_M),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
IconButton(
|
||||
onClick = { openArtifact(context, resolved) },
|
||||
enabled = resolved != null,
|
||||
) {
|
||||
Icon(Icons.AutoMirrored.Filled.OpenInNew, contentDescription = "Open ${artifact.name}")
|
||||
}
|
||||
IconButton(
|
||||
onClick = { resolved?.let { clipboard.copyText(it) } },
|
||||
enabled = resolved != null,
|
||||
) {
|
||||
Icon(Icons.Default.ContentCopy, contentDescription = "Copy link to ${artifact.name}")
|
||||
}
|
||||
ArtifactShareButton(
|
||||
artifact = artifact,
|
||||
resolved = resolved,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
)
|
||||
}
|
||||
Icon(
|
||||
imageVector = Icons.Default.PlayArrow,
|
||||
contentDescription = "Play $name",
|
||||
tint = MaterialTheme.colorScheme.inverseSurface,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Pass the resolved url (null when there is no configured server): a
|
||||
// null never triggers a relative-url fetch, it shows the distinct
|
||||
// "unavailable" state instead of the failure mark.
|
||||
ArtifactImage(
|
||||
url = resolved,
|
||||
contentDescription = "Preview of $name",
|
||||
maxDim = THUMBNAIL_MAX_DIM,
|
||||
fetchBytes = fetchArtifactBytes,
|
||||
size = tile,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The share action every artifact item carries (the gallery's image cells and
|
||||
* its file rows): a 48dp [IconButton] target, an accurate content description,
|
||||
* and a click that launches the platform share chooser. It is the item's own
|
||||
* child action, so a tap on it never opens the image or the item. [scrim] adds
|
||||
* the translucent backing the viewer uses so the icon stays legible over a
|
||||
* bright image.
|
||||
* A non-media tile's content: its file-type glyph ([artifactIcon]) with the
|
||||
* artifact's name and human-readable size beneath it, centred in the cell. The
|
||||
* action strip is pinned to the cell's top corners, away from this centred
|
||||
* column, so a compact tile never draws its glyph or text under the actions.
|
||||
*/
|
||||
@Composable
|
||||
private fun ArtifactTypeLabel(kind: ArtifactKind, artifact: StageArtifact) {
|
||||
val text = pipelinesText()
|
||||
val size = remember(artifact.sizeBytes) { humanBytes(artifact.sizeBytes) }
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = SPACING_XS, vertical = SPACING_XS),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = artifactIcon(kind),
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.size(ARTIFACT_TYPE_ICON_DP),
|
||||
)
|
||||
Text(
|
||||
artifact.name.ifBlank { "(unnamed artifact)" },
|
||||
style = text.label,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(top = SPACING_XXS),
|
||||
)
|
||||
Text(
|
||||
size,
|
||||
style = text.meta,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The compact per-item actions strip a tile shows while not selecting: the share
|
||||
* control at the end, and — for a non-media tile — the copy-link control at the
|
||||
* start, so both the existing open (the tile's own tap) and copy actions stay
|
||||
* reachable from the gallery. A media tile taps through to the viewer, which
|
||||
* carries its own copy action, so it shows only share.
|
||||
*/
|
||||
@Composable
|
||||
private fun BoxScope.ArtifactTileActions(
|
||||
artifact: StageArtifact,
|
||||
resolved: String?,
|
||||
fetchArtifactBytes: suspend (String) -> ByteArray?,
|
||||
media: Boolean,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.TopStart).fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
) {
|
||||
if (media) {
|
||||
Spacer(Modifier.size(ARTIFACT_TILE_ACTION_DP))
|
||||
} else {
|
||||
ArtifactCopyButton(artifact = artifact, resolved = resolved)
|
||||
}
|
||||
ArtifactShareButton(
|
||||
artifact = artifact,
|
||||
resolved = resolved,
|
||||
fetchArtifactBytes = fetchArtifactBytes,
|
||||
modifier = Modifier.size(ARTIFACT_TILE_ACTION_DP),
|
||||
scrim = media,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** The compact copy-link control a non-media tile carries. */
|
||||
@Composable
|
||||
private fun ArtifactCopyButton(artifact: StageArtifact, resolved: String?) {
|
||||
val clipboard = LocalClipboardManager.current
|
||||
IconButton(
|
||||
onClick = { resolved?.let { clipboard.copyText(it) } },
|
||||
enabled = resolved != null,
|
||||
modifier = Modifier.size(ARTIFACT_TILE_ACTION_DP),
|
||||
) {
|
||||
Icon(Icons.Default.ContentCopy, contentDescription = "Copy link to ${artifact.name}")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The share action every artifact tile carries: a compact [IconButton] target, an
|
||||
* accurate content description, and a click that launches the platform share
|
||||
* chooser. It is the item's own child action, so a tap on it never opens the
|
||||
* image or the item. [scrim] adds the translucent backing the viewer uses so the
|
||||
* icon stays legible over a bright image.
|
||||
*/
|
||||
@Composable
|
||||
private fun ArtifactShareButton(
|
||||
@@ -491,5 +518,5 @@ internal fun openArtifact(context: Context, url: String?) {
|
||||
/** Longest edge of a list thumbnail decode. */
|
||||
private const val THUMBNAIL_MAX_DIM = 160
|
||||
|
||||
/** Gap between gallery thumbnails; shared by the row arrangement and the fitting. */
|
||||
/** Gap between gallery tiles; shared by the row arrangement and the fitting. */
|
||||
private val ARTIFACT_TILE_SPACING_DP = SPACING_S
|
||||
|
||||
@@ -188,9 +188,22 @@ internal val GRAPH_PANEL_MIN_HEIGHT = 320.dp
|
||||
/** Preferred side of one square gallery thumbnail tile. */
|
||||
internal val ARTIFACT_TILE_DP = 96.dp
|
||||
|
||||
/** Side of an inline artifact thumbnail and a non-image row's leading glyph box. */
|
||||
/** Side of an inline artifact thumbnail (a media preview or the viewer's). */
|
||||
internal val ARTIFACT_THUMB_DP = 56.dp
|
||||
|
||||
/** File-type glyph inside a non-media gallery tile. */
|
||||
internal val ARTIFACT_TYPE_ICON_DP = 28.dp
|
||||
|
||||
/** Play marker drawn over a video tile's poster frame. */
|
||||
internal val ARTIFACT_PLAY_BADGE_DP = 32.dp
|
||||
|
||||
/**
|
||||
* Compact per-item action target overlaid on a gallery tile (share, or copy on a
|
||||
* non-media tile); smaller than the 48dp standalone target because the whole tile
|
||||
* is also a tap target.
|
||||
*/
|
||||
internal val ARTIFACT_TILE_ACTION_DP = 32.dp
|
||||
|
||||
/** Check-badge glyph on a selected gallery tile. */
|
||||
internal val ARTIFACT_BADGE_DP = 16.dp
|
||||
|
||||
|
||||
@@ -87,20 +87,15 @@ class FormatTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun artifactContentTypeAndMetaLine() {
|
||||
fun artifactContentTypePredicates() {
|
||||
assertTrue(isImageContentType("image/png"))
|
||||
assertTrue(isImageContentType("image/jpeg"))
|
||||
assertFalse(isImageContentType("application/pdf"))
|
||||
assertFalse(isImageContentType(""))
|
||||
assertEquals(
|
||||
"50.9 KiB · image/png",
|
||||
artifactMetaLine(StageArtifact(name = "a.png", sizeBytes = 52168, contentType = "image/png")),
|
||||
)
|
||||
// A blank content type never renders a dangling separator.
|
||||
assertEquals(
|
||||
"4.9 KiB · unknown type",
|
||||
artifactMetaLine(StageArtifact(name = "b", sizeBytes = 5008, contentType = "")),
|
||||
)
|
||||
// Gallery-kind classification (ArtifactTypeTest) builds on this predicate.
|
||||
assertTrue(isVideoContentType("video/mp4"))
|
||||
assertFalse(isVideoContentType("image/png"))
|
||||
assertFalse(isVideoContentType(""))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package net.awan.pipelines.ui.graph
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
|
||||
import androidx.compose.material.icons.filled.Code
|
||||
import androidx.compose.material.icons.filled.DataObject
|
||||
import androidx.compose.material.icons.filled.Description
|
||||
import androidx.compose.material.icons.filled.FolderZip
|
||||
import androidx.compose.material.icons.filled.Image
|
||||
import androidx.compose.material.icons.filled.Movie
|
||||
import androidx.compose.material.icons.filled.PictureAsPdf
|
||||
import androidx.compose.material.icons.automirrored.filled.ReceiptLong
|
||||
import androidx.compose.material.icons.filled.TableChart
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Pure-logic tests for the artifact type classification and its type-to-icon
|
||||
* mapping: which glyph a document, archive, log, code file, JSON payload, PDF and
|
||||
* so on gets, independent of a device.
|
||||
*/
|
||||
class ArtifactTypeTest {
|
||||
|
||||
@Test
|
||||
fun mediaKindsComeStraightFromTheContentType() {
|
||||
assertEquals(ArtifactKind.Image, artifactKind("image/png", "shot.png"))
|
||||
assertEquals(ArtifactKind.Image, artifactKind("image/jpeg; charset=binary", "shot"))
|
||||
assertEquals(ArtifactKind.Video, artifactKind("video/mp4", "clip.mp4"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun namedFileKindsMapFromTheContentType() {
|
||||
assertEquals(ArtifactKind.Pdf, artifactKind("application/pdf", "report.pdf"))
|
||||
assertEquals(ArtifactKind.Json, artifactKind("application/json", "run.json"))
|
||||
assertEquals(ArtifactKind.Archive, artifactKind("application/zip", "bundle.zip"))
|
||||
assertEquals(ArtifactKind.Spreadsheet, artifactKind("text/csv", "rows.csv"))
|
||||
assertEquals(ArtifactKind.Audio, artifactKind("audio/mpeg", "tone.mp3"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theNameExtensionResolvesAGenericSniff() {
|
||||
// The server's sniff of an unrecognised extension is often text/plain;
|
||||
// the name's extension still names the type.
|
||||
assertEquals(ArtifactKind.Log, artifactKind("text/plain", "emulator.log"))
|
||||
assertEquals(ArtifactKind.Code, artifactKind("text/plain", "Main.kt"))
|
||||
assertEquals(ArtifactKind.Code, artifactKind("application/octet-stream", "config.yaml"))
|
||||
assertEquals(ArtifactKind.Document, artifactKind("text/plain; charset=utf-8", "notes.txt"))
|
||||
assertEquals(ArtifactKind.Document, artifactKind("", "index.html"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anUnknownTypeIsOtherNeverACrash() {
|
||||
assertEquals(ArtifactKind.Other, artifactKind("", ""))
|
||||
assertEquals(ArtifactKind.Other, artifactKind("application/octet-stream", "blob"))
|
||||
assertEquals(ArtifactKind.Other, artifactKind("application/x-unknown", "data"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theTypeToIconMappingIsExplicitAndDistinct() {
|
||||
assertEquals(Icons.Filled.Image, artifactIcon(ArtifactKind.Image))
|
||||
assertEquals(Icons.Filled.Movie, artifactIcon(ArtifactKind.Video))
|
||||
assertEquals(Icons.Filled.PictureAsPdf, artifactIcon(ArtifactKind.Pdf))
|
||||
assertEquals(Icons.Filled.DataObject, artifactIcon(ArtifactKind.Json))
|
||||
assertEquals(Icons.Filled.FolderZip, artifactIcon(ArtifactKind.Archive))
|
||||
assertEquals(Icons.Filled.TableChart, artifactIcon(ArtifactKind.Spreadsheet))
|
||||
assertEquals(Icons.AutoMirrored.Filled.ReceiptLong, artifactIcon(ArtifactKind.Log))
|
||||
assertEquals(Icons.Filled.Code, artifactIcon(ArtifactKind.Code))
|
||||
assertEquals(Icons.Filled.Description, artifactIcon(ArtifactKind.Document))
|
||||
assertEquals(Icons.AutoMirrored.Filled.InsertDriveFile, artifactIcon(ArtifactKind.Other))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noTwoKindsShareAGlyph() {
|
||||
val glyphs = ArtifactKind.entries.map { artifactIcon(it) }
|
||||
assertEquals(ArtifactKind.entries.size, glyphs.toSet().size)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user