INTEGRATION.md
D10 — Codex Restore Camera Path — Integration
Section 8 of the remaining-gaps brief. Adds a two-card "choose" surface and a
live camera Aztec-scan path to CodexRestoreScreen. The PDF import path is
unchanged — it just moves behind the new choose surface.
Draft files in this folder:
CodexRestoreChooseAndCamera.kt—CodexRestoreChoose+CodexCameraScancomposables (packagecom.peachpasswords.ui.codex).CodexAztecFrame.kt— per-frame Aztec decode forImageProxy(packagecom.peachpasswords.codex). Already drafted, used unchanged.CodexViewModel.camera.kt— camera members to merge into the realCodexViewModel.
1. Gradle deps — app/build.gradle
CameraX current stable is 1.3.4. ZXing core (com.google.zxing:core:3.5.3)
is already present (line 99) — no ZXing change needed. Add inside dependencies {
(near line 99, next to the existing zxing line):
implementation "androidx.camera:camera-core:1.3.4"
implementation "androidx.camera:camera-camera2:1.3.4"
implementation "androidx.camera:camera-lifecycle:1.3.4"
implementation "androidx.camera:camera-view:1.3.4"
androidx.lifecycle.compose.LocalLifecycleOwner (used by the preview) is provided
by the already-present androidx.lifecycle:lifecycle-runtime-compose:2.8.4.
2. AndroidManifest — CAMERA permission
In app/src/main/AndroidManifest.xml, above <application>:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.any" android:required="false" />
required="false" keeps the app installable on camera-less devices (the denied/
unavailable case already shows the settings card).
3. Merge camera members into CodexViewModel.kt
Copy the commented body inside CodexViewModelCameraMembers (in
CodexViewModel.camera.kt) into the CodexViewModel class, and add the
CameraScanState sealed interface to that file (top level, beside
RestoreState). Drop the draft_d10 package — it goes in
com.peachpasswords.ui.codex.
Add imports to CodexViewModel.kt:
import androidx.camera.core.ImageProxy
import com.peachpasswords.codex.ChunkEnvelope
import com.peachpasswords.codex.CodexAztecFrame
(CodexRestore is already imported.)
New public VM surface after merge:
val camera: StateFlow<CameraScanState>(initialChoosing)fun chooseRestore()— show the two cards, reset restore statefun startCameraScan()— begin/restart scanningfun cameraTimedOut()— record 10s no-detectionfun onCameraFrame(image: ImageProxy): Boolean— analyze one frame; returns true once a payload reconstructs (setsRestoreState.Decoded, same entry point as the PDF path, so the existingDecodedBodypassword/confirm flow works unchanged).
Verified against reality: ChunkEnvelope has s: Int (stripe) and i: Int
(index) — the dedup key "${env.s}:${env.i}" is correct.
CodexRestore.parseEnvelope(text): ChunkEnvelope? and
CodexRestore.reconstructPayload(List<ChunkEnvelope>): CodexPayload are public
and reused unchanged. RestoreState.Decoded(payload, codesFound) matches the
existing constructor.
4. Wire CodexRestoreScreen.kt
The screen currently launches the PDF picker directly from RestoreState.Idle.
Replace that branch so Idle is gated by the camera state.
Add imports:
import androidx.compose.foundation.layout.Box
(plus the new composables are same-package, no import needed).
Collect the camera state — after the existing state collection (around line 36):
val cameraState by vm.camera.collectAsStateWithLifecycle()
Replace the RestoreState.Idle branch. Current anchor (lines 53-54):
is RestoreState.Idle ->
CodexButton("Choose Codex PDF", accent, filled = true) { pickLauncher.launch("application/pdf") }
Replace with:
is RestoreState.Idle -> when (val cs = cameraState) {
is CameraScanState.Choosing -> CodexRestoreChoose(
accent = accent,
onScanCamera = { vm.startCameraScan() },
onImportPdf = { pickLauncher.launch("application/pdf") },
)
is CameraScanState.Scanning -> CodexCameraScan(
accent = accent,
timedOut = false,
codesFound = cs.codesFound,
onFrame = { vm.onCameraFrame(it) },
onTimeout = { vm.cameraTimedOut() },
onRetry = { vm.startCameraScan() },
)
is CameraScanState.Timeout -> CodexCameraScan(
accent = accent,
timedOut = true,
codesFound = cs.codesFound,
onFrame = { vm.onCameraFrame(it) },
onTimeout = { },
onRetry = { vm.startCameraScan() },
)
}
When onCameraFrame reconstructs a payload it sets RestoreState.Decoded, so
the when(state) flips to the existing DecodedBody automatically — the camera
overlay disappears and the password prompt appears. No further wiring needed for
the decode→restore handoff.
Reset on entry: ensure the screen lands on the choose surface each visit. The
VM defaults camera to Choosing and restore to Idle, so a fresh VM is
already correct. If the screen can be revisited with a retained VM, call
vm.chooseRestore() from a LaunchedEffect(Unit) at the top of the screen.
Error branch: the existing RestoreState.Error "Choose another file" button
re-launches the PDF picker. Optionally also call vm.chooseRestore() there so a
failed camera scan returns to the two cards; the brief doesn't require it.
5. Notes / risks
- The intro paragraph (lines 46-49) says "Choose a Codex PDF…". Suggest softening to mention camera too, e.g. "Scan the printed Aztec grid with your camera, or choose the Codex PDF…". Cosmetic; not required.
CodexCameraScanruns its own 10sLaunchedEffecttimer keyed ontimedOut; it also reportsonTimeout. Because the VM'sScanning -> Timeouttransition re-composes withtimedOut = true, the timer self-cancels — no double-fire.- The analyzer closes every
ImageProxyin afinally;onCameraFramemust not close it (it doesn't —CodexAztecFrame.decodeexplicitly does not close). - Reuses
CodexAztecFrame.decode(scene detector, no PURE_BARCODE) for camera frames — distinct fromCodexAztec.decodewhich is for cropped PDF cells. - No
RuneBackgroundusage here; the screen already usesShellBackground. FLAG_SECURE: the restore screen does not currently set it; out of scope for D10. Flag if a security pass wants the live camera+decoded preview protected.