feat(android): cast viewport crop mirror (spec 061 T010) #1231
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/061-cast-crop-android"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Spec 061 T010, client-side only (the API crop endpoint is built in a parallel lane against the same fixed contract). While casting a PHOTO, pinching/panning in the viewer mirrors the crop onto the TV; zooming back to 1x returns the TV to the full preview. No backend changes, no web changes, no new strings, no new dependencies.
How it talks to the API crop endpoint (the fixed contract)
POST /api/media/tokenwith rendition"crop"(same client method, new rendition string) and LOADs{serverUrl}/api/media/{id}/crop?sx=&sy=&sw=&sh=&maxW=1280&st=<token>— sx/sy/sw/sh are normalized floats in [0,1] (5 decimals, Locale.US) describing the source rect within the FULL image; the token rides as
?st=via the existingwithSignedToken, exactly like every other cast URL. Response is consumed by the Default Receiver asimage/jpeg; the client assumes nothing beyond that.width/height), so the phone's preview-rendition geometry and the server's full-image geometry always agree.Pieces
cast/ViewportCrop.kt(new, pure, JVM-tested):visibleSourceRect(...)inverts exactly the transform the viewer draws with (scale about the viewport centre + pan translate, documented onViewerZoomState) and re-uses that transform's ownfitContentSizeso the two can never drift; clamped into [0,1]² with the endpoint's 0.01 minimum; returns null at ~1x or when dimensions are unknown (→ no crop, normal rendition).CastController: the mint+sign+load tail ofloadItemwas extracted intoperformTokenedLoad(behaviour-identical, now shared); newshowCrop(item, rect)is latest-wins on the sameshowJobasshow()(a rapid gesture's in-flight load is cancelled by the next one);cropItemIdtracks whether the TV shows a crop (set on crop-load success, cleared by any full-rendition load success, disconnect and session loss) andisCropShowing(item)guards the restore.MediaViewerScreen: a thirdsnapshotFlowover zoom scale/offset combined with connection + settledPage feedscropDecisions(debounce(500).map(::cropAction)); viewport size comes fromonSizeChanged. While disconnected nothing is ever LOADed — the viewer behaves exactly as before. Zoom reset →cast.show(item)(the full preview) only when the TV actually shows a crop, so the settle-sync swipe load never double-LOADs.Edge cases
showCrop, and incropMediaRequest).cast_error_tokensnackbar pattern asshow(); structural skips (no server url) are silent.showJob) — the TV can never land behind the phone.Verification
From
apps/android:./gradlew :app:testDebugUnitTest :app:assembleDebug→ BUILD SUCCESSFUL, 495 tests, 0 failures (new:ViewportCropTest11 — zoom=1→null, centred zoom portrait/landscape, corner pans clamped, extreme 8:1 aspect, 0.01 floor, unit-square invariant;CropMirrorTest8 — decision matrix + gesture-burst/quiet debounce on the virtual clock, latest-transform-wins;CastMediaTest+4 — crop URL/rendition/token appending and structural skips).Merge note: the crop endpoint does not need to exist for this to merge —
showCropmints its token and LOADs exactly per contract, and while the endpoint 404s the receiver just keeps the previous media (mint failure already surfaces as the existing snackbar).While casting a photo, a pinch/pan in the viewer now LOADs the same crop on the TV: after the gesture has been idle for 500ms the phone mints a 'crop' rendition token and casts GET /api/media/{id}/crop?sx&sy&sw&sh&maxW=1280 (normalized source rect of the full image, spec 061 contract); zooming back to 1x hands the TV the full preview again — but only when a crop is actually showing there, so a plain swipe never double-LOADs. - cast/ViewportCrop.kt (new, pure): visibleSourceRect inverts exactly the viewer's transform (scale about centre + pan translate, via the shared fitContentSize), clamps into [0,1] with the endpoint's 0.01 floor, and returns null at 1x / unknown dimensions; CropSignal/cropAction decision matrix; cropDecisions = debounce(500ms) + decide, the pipeline the screen uses and the JVM suite drives on the virtual clock - CastController: mint+sign+load tail of loadItem extracted into performTokenedLoad (behaviour-identical); showCrop is latest-wins on the same showJob; cropItemId tracks what the TV shows (cleared by any full load success, disconnect and session loss); isCropShowing guards the full-preview restore - CastMedia: CastRendition.CROP + cropUrl/cropMediaRequest (Locale.US %.5f, maxW=1280); the token rides via the existing withSignedToken - MediaViewerScreen: third snapshotFlow over zoom scale/offset combined with connection + settledPage, viewport size from onSizeChanged; videos never crop; disconnected sessions never produce an action Tests: ViewportCropTest (11, rect math incl. corner pans, extreme aspect mismatch, API-minimum floor), CropMirrorTest (8, decision matrix + burst/quiet debounce on the virtual clock), CastMediaTest +4 (crop URL, rendition, token appending, structural skips). 495 tests green. No backend changes, no new strings, no new dependencies.