pdf: add Route navigation host for viewer, capture and cut-glue (#nav)
- Commit
8493b346a77da6319bea889f541af78dd00b51f3- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 19:58 UTC (19 days ago)
- Parents
d0e6a0a
The PDF app had no Route or MainNavigation at all: which screen was showing lived in three rememberSaveable flags in MainActivity.Content (data: Uri?, isCapturing, isCutGlue) chosen by an if/else chain over the whole Surface, and inside capture a second pair of flags (selectedIndex, isCropping in CapturePdfScreen) swapped the capture list, the page preview and the crop editor. That is exactly the implicit screen state machine the owner directive bans: selection decided the screen, and none of it was visible to the back stack. Add Route (Home / Viewer(uri) / Capture / CapturePage(index) / Crop(index) / CutGlue) and a Navigation.kt host over a rememberNavBackStack, following the notes and screentime hosts. Viewer carries the document URI as a string so the route serializes. CapturePage and Crop are real destinations over Capture: selecting a thumbnail pushes or replaces CapturePage, capturing or picking a page pushes CapturePage then Crop, and back is a plain stack pop in each case (the hand-rolled BackHandler chain in CapturePdfScreen is gone). Entry behaviour is preserved. The manifest already names the single MainActivity, so it is unchanged: VIEW intents (content/file application/pdf, launcher) still land on the host, MainActivity. routeFor turns an intent data URI into Route.Viewer, onNewIntent re-routes a running host, and a viewer started from an external intent still finishes on back while an in-app viewer pops home. The SAF OpenDocument picker now lives in the Home entry and pushes Viewer; a finished capture clears the page list and resets to Home + Viewer, as the old data/isCapturing flag pair did. Clearing the captured pages on exit moved from CapturePdfScreen's DisposableEffect (which would now fire when CapturePage covers Capture) to the explicit leave-capture and pdf-created paths in Navigation. The capture write result still flows through PdfViewModel.pdfWriteResults to AppMessages and onPdfCreated; routing that through NavigationResults was considered and rejected because the created document is a new destination carrying its URI, not a result delivered back to a destination underneath. Tests: existing CapturePdfScreen call sites pass the new selectedIndex/navigation callbacks, the gallery-pick test now asserts the select + crop route pushes instead of an in-screen crop swap, MainActivityTest exercises home to capture/cut-glue through the real host, and RouteTest pins routeFor. Verified: ./gradlew :pdf:compileDevKotlin :pdf:testDevUnitTest green (279 tests).
Diff
pdf/AGENTS.md
diff --git a/pdf/AGENTS.md b/pdf/AGENTS.mdindex ead0c5f42e..cafdf5b9ea 100644--- a/pdf/AGENTS.md+++ b/pdf/AGENTS.md@@ -6,7 +6,7 @@ _Install: ./install pdf (dev by default)._ <!-- last-reviewed: 2026-10-16 --> - Gradle: :pdf / dir: pdf/ - Package roots present: ui-- Entry files: MainActivity.kt (no Route.kt — mode flags, not nav destinations)+- Entry files: MainActivity.kt, Route.kt, Navigation.kt (Route host; see Navigation.kt) - Deps: :library:image, :library:ocr - Metadata: metadata_data/pdf.md (present) - Rust: yes / screenshotTest: yes@@ -17,17 +17,18 @@ _Install: ./install pdf (dev by default)._ - Full viewer: text search, text selection, form fields, outlines, zoom state, print via share menu; several documents open as separate Recents entries - Capture mode: photograph pages with auto-framing, crop, and compose them into a PDF; cut-and-glue screen for assembling pages - Native Rust PDF engine (`PdfNative`) for parsing, rendering, and export-**Architecture / data-flow:** `MainActivity` mode-flags (`data` / `isCapturing` / `isCutGlue`) over a single `util/PdfViewModel` + `util/PdfStateStore`, with `SafePdf*` utils wrapping the Rust engine for document access, page rendering, and edits; capture flows through `model/CapturedImage` → `AutoFrameDetector` → `ComposePdfDocument` → `PdfExporter`. `onCreateBeforeContent` only captures the launch intent's data URI; `Content()` picks viewer vs capture vs cut-glue vs picker.-**Entry points + reading order:** `MainActivity.kt` (`InitialScreen` → viewer/capture/cut-glue) → `ui/SafePdfViewerScreen.kt` → `util/PdfViewModel.kt` → `util/SafePdfDocument.kt` → `util/SafePdfParser.kt`.+**Architecture / data-flow:** `MainActivity` hosts `Navigation.kt` (`Route.Home/Viewer/Capture/CapturePage/Crop/CutGlue`) over a single `util/PdfViewModel` + `util/PdfStateStore`, with `SafePdf*` utils wrapping the Rust engine for document access, page rendering, and edits; capture flows through `model/CapturedImage` → `AutoFrameDetector` → `ComposePdfDocument` → `PdfExporter`. `onCreateBeforeContent` only captures the launch intent's data URI; `Content()` picks viewer vs capture vs cut-glue vs picker.+**Entry points + reading order:** `MainActivity.kt` + `Route.kt` + `Navigation.kt` (`InitialScreen` → viewer/capture/cut-glue) → `ui/SafePdfViewerScreen.kt` → `util/PdfViewModel.kt` → `util/SafePdfDocument.kt` → `util/SafePdfParser.kt`. **Gotchas:**-- No navigation graph at all — the three modes are `rememberSaveable` flags in `Content()`, so don't add a `Route.kt` here - Started-with-intent launches `finish()` on back instead of returning to the picker; in-app launches reset to the picker - Card drift fixed: `util/` gained `FrameGeometry`, `FrameImageOps`, `SafePdfDocumentEdits`, `SafePdfPrimitives`; `ui/` is `SafePdf*` + capture/crop/cut-glue screens (no separate `domain/` or `platform/`) - Extra non-conforming dirs (`model/`, `util/`) hold real code — closed-roots migration pending ## Key files-### Root — entry (mode flags, no Route.kt)-- com/vayunmathur/pdf/MainActivity.kt — InitialScreen, viewer/capture/cut-glue switch+### Root — entry + navigation+- com/vayunmathur/pdf/MainActivity.kt — host, intent → Route.Viewer routing+- com/vayunmathur/pdf/Route.kt — Home/Viewer(uri)/Capture/CapturePage(index)/Crop(index)/CutGlue+- com/vayunmathur/pdf/Navigation.kt — MainNavigation host ### model/ — capture model - com/vayunmathur/pdf/model/CapturedImage.kt ### ui/ — viewer chrome + state
pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt b/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.ktindex 09a27e37f9..8c27e4669c 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/MainActivity.kt@@ -1,8 +1,7 @@ package com.vayunmathur.pdf +import android.content.Intent import android.net.Uri-import androidx.activity.compose.rememberLauncherForActivityResult-import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box@@ -12,75 +11,66 @@ import androidx.compose.foundation.layout.padding import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Scaffold-import com.vayunmathur.library.ui.Surface import com.vayunmathur.library.ui.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.vayunmathur.pdf.R import androidx.compose.ui.unit.dp-import com.vayunmathur.pdf.ui.CapturePdfScreen-import com.vayunmathur.pdf.ui.CutGlueScreen-import com.vayunmathur.pdf.ui.SafePdfViewerScreen import com.vayunmathur.pdf.util.PdfViewModel -/** Main Activity: a ma activity implementation for main activity. */+/**+ * The single PDF host.+ *+ * External VIEW intents arrive as a [Route.Viewer] start destination (see+ * [routeFor]); leaving that viewer finishes the host because the caller+ * owns the document task, while documents opened in-app return to home.+ * Intents that arrive while the host is running are re-routed through+ * [pendingRoute] instead of stacking a second activity.+ */ class MainActivity : MaActivity() { private val pdfViewModel: PdfViewModel by viewModels() private var intentData: Uri? = null + private var initialRoute: Route = Route.Home+ private var pendingRoute by mutableStateOf<Route?>(null)+ private var startedWithIntent = false+ override fun onCreateBeforeContent() { intentData = intent.data+ startedWithIntent = intentData != null+ initialRoute = routeFor(intent) } @Composable override fun Content() {- val startedWithIntent = remember { intentData != null }- var data: Uri? by rememberSaveable { mutableStateOf(intentData) }- var isCapturing by rememberSaveable { mutableStateOf(false) }- var isCutGlue by rememberSaveable { mutableStateOf(false) }+ Navigation(+ viewModel = pdfViewModel,+ initialRoute = initialRoute,+ externalRoute = pendingRoute,+ onExternalRouteConsumed = { pendingRoute = null },+ startedWithIntent = startedWithIntent,+ onFinish = { finish() },+ )+ } - val filePickerLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->- uri?.let { data = it }+ override fun onNewIntent(intent: Intent) {+ super.onNewIntent(intent)+ setIntent(intent)+ intent.data?.let {+ startedWithIntent = true+ pendingRoute = routeFor(intent) }+ } - Surface(- modifier = Modifier.fillMaxSize(),- color = MaterialTheme.colorScheme.background- ) {- if (isCutGlue) {- CutGlueScreen(onBack = { isCutGlue = false })- } else if (isCapturing) {- CapturePdfScreen(- viewModel = pdfViewModel,- onBack = { isCapturing = false },- onPdfCreated = { uri ->- data = uri- isCapturing = false- }- )- } else if (data != null) {- SafePdfViewerScreen(- uri = data!!,- onBack = {- if (startedWithIntent) finish() else data = null- }- )- } else {- InitialScreen(- onOpenPdf = { filePickerLauncher.launch(arrayOf("application/pdf")) },- onCapturePdf = { isCapturing = true },- onCutGlue = { isCutGlue = true }- )- }- }+ companion object {+ /** The route an entry intent names; home is the default landing. */+ fun routeFor(intent: Intent?): Route =+ intent?.data?.let { Route.Viewer(it.toString()) } ?: Route.Home } }
pdf/src/main/java/com/vayunmathur/pdf/Navigation.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/Navigation.kt b/pdf/src/main/java/com/vayunmathur/pdf/Navigation.ktnew file mode 100644index 0000000000..133d313881--- /dev/null+++ b/pdf/src/main/java/com/vayunmathur/pdf/Navigation.kt@@ -0,0 +1,136 @@+package com.vayunmathur.pdf++import android.net.Uri+import androidx.activity.compose.rememberLauncherForActivityResult+import androidx.activity.result.contract.ActivityResultContracts+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import com.vayunmathur.library.util.DetailPage+import com.vayunmathur.library.util.FullscreenPage+import com.vayunmathur.library.util.ListPage+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.rememberNavBackStack+import com.vayunmathur.pdf.ui.CapturePdfScreen+import com.vayunmathur.pdf.ui.CropScreen+import com.vayunmathur.pdf.ui.CutGlueScreen+import com.vayunmathur.pdf.ui.SafePdfViewerScreen+import com.vayunmathur.pdf.util.PdfViewModel++/**+ * Navigation host for the PDF app: home, the viewer, capture (with its+ * page-preview and crop destinations) and cut-and-glue.+ *+ * A document handed in by an external intent starts as the sole viewer+ * destination over home, and leaving it finishes the host (the caller owns+ * the document task); a document opened or captured in-app returns to home.+ */+@Composable+fun Navigation(+ viewModel: PdfViewModel,+ initialRoute: Route = Route.Home,+ externalRoute: Route? = null,+ onExternalRouteConsumed: () -> Unit = {},+ startedWithIntent: Boolean = false,+ onFinish: () -> Unit = {},+) {+ val backStack = if (initialRoute == Route.Home) {+ rememberNavBackStack<Route>(Route.Home)+ } else {+ rememberNavBackStack<Route>(Route.Home, initialRoute)+ }++ LaunchedEffect(externalRoute) {+ val route = externalRoute ?: return@LaunchedEffect+ when (route) {+ is Route.Viewer -> backStack.reset(Route.Home, route)+ else -> backStack.reset(Route.Home, route)+ }+ onExternalRouteConsumed()+ }++ // Leaving capture for home (or for the finished document) drops the+ // in-memory page list, as the old CapturePdfScreen dispose did.+ fun leaveCapture() {+ viewModel.clearCapturedImages()+ backStack.pop()+ }++ MainNavigation(backStack) {+ entry<Route.Home>(metadata = ListPage()) {+ val filePickerLauncher = rememberLauncherForActivityResult(+ ActivityResultContracts.OpenDocument(),+ ) { uri ->+ uri?.let { backStack.add(Route.Viewer(it.toString())) }+ }+ InitialScreen(+ onOpenPdf = { filePickerLauncher.launch(arrayOf("application/pdf")) },+ onCapturePdf = { backStack.add(Route.Capture) },+ onCutGlue = { backStack.add(Route.CutGlue) },+ )+ }+ entry<Route.Viewer>(metadata = DetailPage()) { route ->+ SafePdfViewerScreen(+ uri = Uri.parse(route.uri),+ onBack = {+ if (startedWithIntent) onFinish() else backStack.pop()+ },+ )+ }+ entry<Route.Capture>(metadata = DetailPage()) {+ CapturePdfScreen(+ viewModel = viewModel,+ selectedIndex = null,+ onBack = { leaveCapture() },+ onPdfCreated = { uri ->+ viewModel.clearCapturedImages()+ backStack.reset(Route.Home, Route.Viewer(uri.toString()))+ },+ onSelectPage = { index ->+ if (index != null) backStack.add(Route.CapturePage(index))+ },+ onOpenCrop = { index -> backStack.add(Route.Crop(index)) },+ )+ }+ entry<Route.CapturePage>(metadata = DetailPage()) { route ->+ CapturePdfScreen(+ viewModel = viewModel,+ selectedIndex = route.index,+ onBack = { backStack.pop() },+ onPdfCreated = { uri ->+ viewModel.clearCapturedImages()+ backStack.reset(Route.Home, Route.Viewer(uri.toString()))+ },+ onSelectPage = { index ->+ if (index == null) {+ backStack.pop()+ } else if (index != route.index) {+ backStack.setLast(Route.CapturePage(index))+ }+ },+ onOpenCrop = { index -> backStack.add(Route.Crop(index)) },+ )+ }+ entry<Route.Crop>(metadata = FullscreenPage()) { route ->+ val images by viewModel.capturedImages.collectAsState()+ val image = images.getOrNull(route.index)+ if (image != null) {+ CropScreen(+ uri = image.uri,+ initialQuadrilateral = image.quadrilateral,+ onCropDone = { newQuadrilateral ->+ viewModel.updateQuadrilateral(route.index, newQuadrilateral)+ backStack.pop()+ },+ onBack = { backStack.pop() },+ )+ } else {+ LaunchedEffect(route.index) { backStack.pop() }+ }+ }+ entry<Route.CutGlue>(metadata = DetailPage()) {+ CutGlueScreen(onBack = { backStack.pop() })+ }+ }+}
pdf/src/main/java/com/vayunmathur/pdf/Route.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/Route.kt b/pdf/src/main/java/com/vayunmathur/pdf/Route.ktnew file mode 100644index 0000000000..55d69324aa--- /dev/null+++ b/pdf/src/main/java/com/vayunmathur/pdf/Route.kt@@ -0,0 +1,32 @@+package com.vayunmathur.pdf++import com.vayunmathur.library.util.NavKey+import kotlinx.serialization.Serializable++@Serializable+/** Navigation destinations for the PDF viewer, capture and cut-and-glue flows. */+sealed interface Route : NavKey {+ @Serializable+ /** The start screen: open a document, capture one, or cut-and-glue. */+ data object Home : Route++ @Serializable+ /** The document viewer; the URI is the document identity (a string so the route serializes). */+ data class Viewer(val uri: String) : Route++ @Serializable+ /** Camera capture with no page selected yet. */+ data object Capture : Route++ @Serializable+ /** One captured page, previewed inside capture. */+ data class CapturePage(val index: Int) : Route++ @Serializable+ /** The crop editor for one captured page, over its preview. */+ data class Crop(val index: Int) : Route++ @Serializable+ /** Cut-and-glue assembly of PDFs and images into a new document. */+ data object CutGlue : Route+}
pdf/src/main/java/com/vayunmathur/pdf/ui/CapturePdfScreen.kt
diff --git a/pdf/src/main/java/com/vayunmathur/pdf/ui/CapturePdfScreen.kt b/pdf/src/main/java/com/vayunmathur/pdf/ui/CapturePdfScreen.ktindex 2f831e0b39..c256793f54 100644--- a/pdf/src/main/java/com/vayunmathur/pdf/ui/CapturePdfScreen.kt+++ b/pdf/src/main/java/com/vayunmathur/pdf/ui/CapturePdfScreen.kt@@ -3,7 +3,6 @@ package com.vayunmathur.pdf.ui import android.Manifest import android.content.pm.PackageManager import android.net.Uri-import androidx.activity.compose.BackHandler import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.background@@ -32,13 +31,11 @@ import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.rememberPermissionRequest import androidx.compose.ui.res.painterResource import androidx.compose.runtime.Composable-import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember-import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier@@ -67,15 +64,16 @@ import com.vayunmathur.library.ui.appBarScrollBehavior @Composable fun CapturePdfScreen( viewModel: PdfViewModel,+ selectedIndex: Int?, onBack: () -> Unit, onPdfCreated: (Uri) -> Unit,+ onSelectPage: (Int?) -> Unit,+ onOpenCrop: (Int) -> Unit, ) { val context = LocalContext.current val pdfSavedMsg = stringResource(R.string.pdf_saved) val pdfSaveFailedMsg = stringResource(R.string.failed_to_save_pdf) val images by viewModel.capturedImages.collectAsState()- var selectedIndex by rememberSaveable { mutableStateOf<Int?>(null) }- var isCropping by rememberSaveable { mutableStateOf(false) } var hasCameraPermission by remember { mutableStateOf(@@ -92,8 +90,8 @@ fun CapturePdfScreen( val galleryLauncher = rememberLauncherForActivityResult(ActivityResultContracts.GetContent()) { uri -> uri?.let { val newIndex = viewModel.addCapturedImage(it)- selectedIndex = newIndex- isCropping = true+ onSelectPage(newIndex)+ onOpenCrop(newIndex) } } @@ -124,47 +122,19 @@ fun CapturePdfScreen( } } - // Reset the in-memory captured-images list when leaving this screen so the- // VM doesn't retain it for the entire process lifetime.- DisposableEffect(Unit) {- onDispose { viewModel.clearCapturedImages() }- }-- BackHandler {- if (isCropping) {- isCropping = false- } else if (selectedIndex != null) {- selectedIndex = null- } else {- onBack()- }- }-- val currentSelected = selectedIndex- if (isCropping && currentSelected != null && currentSelected in images.indices) {- val currentImage = images[currentSelected]- CropScreen(- uri = currentImage.uri,- initialQuadrilateral = currentImage.quadrilateral,- onCropDone = { newQuadrilateral ->- viewModel.updateQuadrilateral(currentSelected, newQuadrilateral)- isCropping = false- },- onBack = { isCropping = false }- )- } else {+ run { AppScaffold( title = stringResource(R.string.capture_pdf_title), onNavigateBack = onBack, actions = { val sel = selectedIndex if (sel != null) {- IconButton(onClick = { isCropping = true }) {+ IconButton(onClick = { onOpenCrop(sel) }) { IconCrop() } IconButton(onClick = { viewModel.removeCapturedImage(sel)- selectedIndex = null+ onSelectPage(null) }) { IconDelete() }@@ -238,7 +208,7 @@ fun CapturePdfScreen( color = if (selectedIndex == index) MaterialTheme.colorScheme.primary else Color.Transparent, shape = RoundedCornerShape(8.dp) )- .clickable { selectedIndex = index },+ .clickable { onSelectPage(index) }, contentAlignment = Alignment.Center ) { SubcroppedImage(@@ -253,7 +223,7 @@ fun CapturePdfScreen( .size(80.dp) .clip(RoundedCornerShape(8.dp)) .background(MaterialTheme.colorScheme.surfaceVariant)- .clickable { selectedIndex = null },+ .clickable { onSelectPage(null) }, contentAlignment = Alignment.Center ) { IconAdd()@@ -278,8 +248,8 @@ fun CapturePdfScreen( CameraPreview( onImageCaptured = { uri -> val newIndex = viewModel.addCapturedImage(uri)- selectedIndex = newIndex- isCropping = true+ onSelectPage(newIndex)+ onOpenCrop(newIndex) } ) } else {
pdf/src/test/java/com/vayunmathur/pdf/RouteTest.kt
diff --git a/pdf/src/test/java/com/vayunmathur/pdf/RouteTest.kt b/pdf/src/test/java/com/vayunmathur/pdf/RouteTest.ktnew file mode 100644index 0000000000..aeeea681ea--- /dev/null+++ b/pdf/src/test/java/com/vayunmathur/pdf/RouteTest.kt@@ -0,0 +1,26 @@+package com.vayunmathur.pdf++import android.content.Intent+import android.net.Uri+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals++@RunWith(RobolectricTestRunner::class)+class RouteTest {++ @Test+ fun `view intent routes to viewer and plain launch routes home`() {+ val view = Intent(Intent.ACTION_VIEW, Uri.parse("content://docs/report.pdf"))+ assertEquals(Route.Viewer("content://docs/report.pdf"), MainActivity.routeFor(view))+ assertEquals(Route.Home, MainActivity.routeFor(Intent(Intent.ACTION_MAIN)))+ assertEquals(Route.Home, MainActivity.routeFor(null))+ }++ @Test+ fun `capture destinations carry the page index`() {+ assertEquals(3, Route.CapturePage(3).index)+ assertEquals(3, Route.Crop(3).index)+ }+}
pdf/src/test/java/com/vayunmathur/pdf/ui/CaptureCropComposeTest.kt
diff --git a/pdf/src/test/java/com/vayunmathur/pdf/ui/CaptureCropComposeTest.kt b/pdf/src/test/java/com/vayunmathur/pdf/ui/CaptureCropComposeTest.ktindex 3ea8f4b87c..f544b01e65 100644--- a/pdf/src/test/java/com/vayunmathur/pdf/ui/CaptureCropComposeTest.kt+++ b/pdf/src/test/java/com/vayunmathur/pdf/ui/CaptureCropComposeTest.kt@@ -50,7 +50,7 @@ class CaptureCropComposeTest { @Test fun captureScreenWithoutPermissionShowsRequestAndUpload() { val vm = PdfViewModel(app)- rule.setContent { DynamicTheme { CapturePdfScreen(vm, onBack = {}, onPdfCreated = {}) } }+ rule.setContent { DynamicTheme { CapturePdfScreen(vm, selectedIndex = null, onBack = {}, onPdfCreated = {}, onSelectPage = {}, onOpenCrop = {}) } } rule.onNodeWithText("Capture PDF").assertIsDisplayed() rule.onNodeWithText("Request Camera Permission").assertIsDisplayed() rule.onNodeWithText("Upload Image").assertIsDisplayed()@@ -59,7 +59,7 @@ class CaptureCropComposeTest { @Test fun captureScreenWithImagesShowsThumbnails() { val vm = PdfViewModel(app) vm.addCapturedImage(pngUri("cap1.png")); vm.addCapturedImage(pngUri("cap2.png"))- rule.setContent { DynamicTheme { CapturePdfScreen(vm, onBack = {}, onPdfCreated = {}) } }+ rule.setContent { DynamicTheme { CapturePdfScreen(vm, selectedIndex = null, onBack = {}, onPdfCreated = {}, onSelectPage = {}, onOpenCrop = {}) } } rule.waitForIdle() rule.onNodeWithText("Capture PDF").assertIsDisplayed() }
pdf/src/test/java/com/vayunmathur/pdf/ui/LauncherFlowsTest.kt
diff --git a/pdf/src/test/java/com/vayunmathur/pdf/ui/LauncherFlowsTest.kt b/pdf/src/test/java/com/vayunmathur/pdf/ui/LauncherFlowsTest.ktindex 6ee8eb562a..80e003c140 100644--- a/pdf/src/test/java/com/vayunmathur/pdf/ui/LauncherFlowsTest.kt+++ b/pdf/src/test/java/com/vayunmathur/pdf/ui/LauncherFlowsTest.kt@@ -146,9 +146,14 @@ class LauncherFlowsTest { @Test fun captureGalleryPickOpensCrop() { val png = pngFile("gallery.png") val vm = PdfViewModel(ctx as Application)+ var selected: Int? = null+ var cropped: Int? = null rule.setContent { CompositionLocalProvider(LocalActivityResultRegistryOwner provides fakeOwner(Uri.fromFile(png))) {- DynamicTheme { CapturePdfScreen(vm, onBack = {}, onPdfCreated = {}) }+ DynamicTheme {+ CapturePdfScreen(vm, selectedIndex = null, onBack = {}, onPdfCreated = {},+ onSelectPage = { selected = it }, onOpenCrop = { cropped = it })+ } } } rule.onNodeWithText("Upload Image").assertIsDisplayed().performClick()@@ -157,8 +162,10 @@ class LauncherFlowsTest { } assertEquals(1, vm.capturedImages.value.size) rule.waitForIdle()- // Picking enters crop mode for the new image- rule.onNodeWithText("Crop Image").assertIsDisplayed()+ // Picking selects the new page and pushes its Crop route (rendered by+ // Navigation, not inside this screen any more).+ assertEquals(0, selected)+ assertEquals(0, cropped) } @Test fun captureSaveViaCreateDocument() {@@ -169,7 +176,7 @@ class LauncherFlowsTest { var created: Uri? = null rule.setContent { CompositionLocalProvider(LocalActivityResultRegistryOwner provides fakeOwner(Uri.fromFile(out))) {- DynamicTheme { CapturePdfScreen(vm, onBack = {}, onPdfCreated = { created = it }) }+ DynamicTheme { CapturePdfScreen(vm, selectedIndex = null, onBack = {}, onPdfCreated = { created = it }, onSelectPage = {}, onOpenCrop = {}) } } } rule.waitForIdle()