Modern Apps git

← Modern-Apps.git

office: tabs are sibling routes (#nav)

Commit
b3f3c95271080de9f17c98f2104b635627eb5135
Author
Vayun Mathur <[email protected]>
When
2026-11-16 20:04 UTC (19 days ago)
Parents
13bdb25
Replace OfficeRoute.Main with OfficeRoute.OfflineHome and
OfficeRoute.OnlineHome sibling destinations. The app now starts on
OfflineHome (or OfflineEditor for an intent document, as before).

OfficeTabs is now the full route-backed host: it takes the back
stack, renders the route-backed TabbedPagerScaffold (RouteTab with
the same Offline/Online labels, icons and order), and hosts
MainNavigation in the content slot with OfflineHome/OnlineHome
entries registered with SiblingPage() plus the OfflineEditor and
OnlineEditor entries rendering the editor content supplied by
OfficeNavGraph. Switching tabs resets the stack; opening a local or
online document still pushes its editor route over the current home
tab. AGENTS route reading order is updated to the new names.

Tests: officeTabsShowsOfflineHomeAndOnlineTab now seeds OfficeTabs
with a NavBackStack on OfflineHome and clicks the Online tab; the
route serialization and route-type checks name OfflineHome instead
of Main.

Verified on devvm21958 (no push):
- ./gradlew :office:compileDevKotlin :office:testDevUnitTest — green

Diff

office/AGENTS.md
diff --git a/office/AGENTS.md b/office/AGENTS.mdindex 79d5a274c0..bdaa1d2d23 100644--- a/office/AGENTS.md+++ b/office/AGENTS.md@@ -21,8 +21,8 @@ Host: `api.maproj.org` (Cloudflare FIRST_PARTY pins). Server checkout: `../locat - Editing across text, spreadsheets, and presentations with comments, change tracking, footnotes, headers/footers, and export/print menus - Native Rust formula engine + document CRDT (`OfficeNative`); online collaboration is E2EE with no accounts — the relay only forwards ciphertext - Opens files shared from other apps or `office://join` collaboration links-**Architecture / data-flow:** Root-level document chrome + `ui/` type-specific views over the `util/OfficeViewModel*` family (split per surface: documents, text, sheet, slides, tables, sync A/B/C, export) backed by `:library:ui`'s `OdfDocument` model; sync goes through `util/OfficeSync` + `util/DocumentTreeCrdt` to the E2EE relay. `onCreateBeforeContent`: `NetworkClient.init(FIRST_PARTY)` → load settings → split join-links from document URIs; `Content()` roots the `OfficeRoute` (`Main` / `OfflineEditor` / `OnlineEditor`) graph and fires `initSync`.-**Entry points + reading order:** `OfficeRoute` (`Main` / `OfflineEditor(uri)` / `OnlineEditor(docId)`, inline) → `MainActivity.kt` (`OfficeRoot`, `OfficeNavGraph`) → `OfficeDocumentPane.kt` → `util/OfficeViewModel.kt` → `odf/DocumentImporter.kt`.+**Architecture / data-flow:** Root-level document chrome + `ui/` type-specific views over the `util/OfficeViewModel*` family (split per surface: documents, text, sheet, slides, tables, sync A/B/C, export) backed by `:library:ui`'s `OdfDocument` model; sync goes through `util/OfficeSync` + `util/DocumentTreeCrdt` to the E2EE relay. `onCreateBeforeContent`: `NetworkClient.init(FIRST_PARTY)` → load settings → split join-links from document URIs; `Content()` roots the `OfficeRoute` (`OfflineHome` / `OnlineHome` / `OfflineEditor` / `OnlineEditor`) graph and fires `initSync`.+**Entry points + reading order:** `OfficeRoute` (`OfflineHome` / `OnlineHome` / `OfflineEditor(uri)` / `OnlineEditor(docId)`, inline) → `MainActivity.kt` (`OfficeRoot`, `OfficeNavGraph`) → `OfficeDocumentPane.kt` → `util/OfficeViewModel.kt` → `odf/DocumentImporter.kt`. **Gotchas:** - Display names must come from `OpenableColumns.DISPLAY_NAME`, not the URI path — `DocumentImporter` routes by extension and content URIs often have extensionless ids - The document "paper" stays light in dark mode by design (`OfficeLightTheme`); dark mode inverts luminance via a color matrix, never the model colors
office/src/main/java/com/vayunmathur/office/MainActivity.kt
diff --git a/office/src/main/java/com/vayunmathur/office/MainActivity.kt b/office/src/main/java/com/vayunmathur/office/MainActivity.ktindex a6ac40aba1..d8fb88acd5 100644--- a/office/src/main/java/com/vayunmathur/office/MainActivity.kt+++ b/office/src/main/java/com/vayunmathur/office/MainActivity.kt@@ -122,8 +122,10 @@ private fun OfficeAppTheme(content: @Composable () -> Unit) { /** Top-level navigation routes for the Office app (shared nav framework). */ @Serializable sealed interface OfficeRoute : NavKey {-    /** Singleton holding main state and operations. */-    @Serializable data object Main : OfficeRoute+    /** Offline home tab (sibling route, the start destination). */+    @Serializable data object OfflineHome : OfficeRoute+    /** Online cloud-docs home tab (sibling route). */+    @Serializable data object OnlineHome : OfficeRoute     /** Editing a local/offline document (optionally identified by its source uri). */     @Serializable data class OfflineEditor(val uri: String? = null) : OfficeRoute     /** Editing a cloud-synced document, identified by its document id. */@@ -164,7 +166,7 @@ class MainActivity : MaActivity() {         var documentUri by rememberSaveable { mutableStateOf(intentUri) }         val state by viewModel.state.collectAsState()         val backStack = rememberNavBackStack<OfficeRoute>(-            if (intentUri != null) OfficeRoute.OfflineEditor(intentUri.toString()) else OfficeRoute.Main+            if (intentUri != null) OfficeRoute.OfflineEditor(intentUri.toString()) else OfficeRoute.OfflineHome         )          LaunchedEffect(Unit) { viewModel.initSync() }@@ -241,21 +243,17 @@ class MainActivity : MaActivity() {                     contentAlignment = Alignment.Center) { CircularProgressIndicator() }             }         }-        MainNavigation(backStack) {-            entry<OfficeRoute.Main> {-                OfficeTabs(-                    viewModel = viewModel,-                    onOpenDocument = { filePickerLauncher.launch(odfMimeTypes) },-                    onNavigateEditor = { backStack.add(OfficeRoute.OfflineEditor()) },-                    onOpenOnlineDoc = { meta ->-                        viewModel.openOnlineDocument(meta)-                        backStack.add(OfficeRoute.OnlineEditor(meta.docId))-                    }-                )-            }-            entry<OfficeRoute.OfflineEditor> { editorContent() }-            entry<OfficeRoute.OnlineEditor> { editorContent() }-        }+        OfficeTabs(+            backStack = backStack,+            viewModel = viewModel,+            onOpenDocument = { filePickerLauncher.launch(odfMimeTypes) },+            onNavigateEditor = { backStack.add(OfficeRoute.OfflineEditor()) },+            onOpenOnlineDoc = { meta ->+                viewModel.openOnlineDocument(meta)+                backStack.add(OfficeRoute.OnlineEditor(meta.docId))+            },+            editorContent = editorContent,+        )     }      /** MIME types accepted by the document picker. */
office/src/main/java/com/vayunmathur/office/OfficeHomeScreens.kt
diff --git a/office/src/main/java/com/vayunmathur/office/OfficeHomeScreens.kt b/office/src/main/java/com/vayunmathur/office/OfficeHomeScreens.ktindex 2c9a0af2f5..01d096e5eb 100644--- a/office/src/main/java/com/vayunmathur/office/OfficeHomeScreens.kt+++ b/office/src/main/java/com/vayunmathur/office/OfficeHomeScreens.kt@@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier@@ -22,41 +21,55 @@ import com.vayunmathur.library.ui.IconDownload import com.vayunmathur.library.ui.IconHome import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton-import com.vayunmathur.library.ui.PagerTab-import com.vayunmathur.library.ui.TabStyle+import com.vayunmathur.library.ui.RouteTab import com.vayunmathur.library.ui.TabbedPagerScaffold import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.office.util.OfficeViewModel import com.vayunmathur.office.util.createNewPresentation import com.vayunmathur.office.util.createNewSpreadsheet import com.vayunmathur.office.util.createNewTextDocument  /**- * The two bottom-nav tabs, hosted in a swipeable pager (see [TabbedPagerScaffold]).- * OfflineEditor and OnlineEditor are pushed on top of this host as ordinary routes.+ * The two bottom-nav home tabs as sibling [OfficeRoute] destinations:+ * route-backed [TabbedPagerScaffold] chrome with [MainNavigation] hosted+ * in its content slot, so the editor routes pushed over a home tab render+ * with no tab selected. Switching tabs resets the stack.  */ @Composable internal fun OfficeTabs(+    backStack: NavBackStack<OfficeRoute>,     viewModel: OfficeViewModel,     onOpenDocument: () -> Unit,     onNavigateEditor: () -> Unit,     onOpenOnlineDoc: (com.vayunmathur.office.util.OfficeDocMeta) -> Unit,+    editorContent: @Composable () -> Unit = {}, ) {-    val pagerState = rememberPagerState(pageCount = { 2 })-    val tabs = listOf(-        PagerTab("Offline", { IconHome() }) {-            InitialScreen(-                viewModel = viewModel,-                onOpenDocument = onOpenDocument,-                onNavigateEditor = onNavigateEditor-            )-        },-        PagerTab("Online", { IconDownload() }) {-            OnlineTab(viewModel = viewModel, onOpenDoc = onOpenOnlineDoc)-        },-    )-    TabbedPagerScaffold(tabs = tabs, pagerState = pagerState, tabStyle = TabStyle.BottomNav)+    TabbedPagerScaffold(+        backStack = backStack,+        tabs = listOf<RouteTab<OfficeRoute>>(+            RouteTab(OfficeRoute.OfflineHome, "Offline") { IconHome() },+            RouteTab(OfficeRoute.OnlineHome, "Online") { IconDownload() },+        ),+    ) {+        MainNavigation(backStack) {+            entry<OfficeRoute.OfflineHome>(metadata = SiblingPage()) {+                InitialScreen(+                    viewModel = viewModel,+                    onOpenDocument = onOpenDocument,+                    onNavigateEditor = onNavigateEditor+                )+            }+            entry<OfficeRoute.OnlineHome>(metadata = SiblingPage()) {+                OnlineTab(viewModel = viewModel, onOpenDoc = onOpenOnlineDoc)+            }+            entry<OfficeRoute.OfflineEditor> { editorContent() }+            entry<OfficeRoute.OnlineEditor> { editorContent() }+        }+    } }  @Composable
office/src/test/java/com/vayunmathur/office/Slice4Pass2OnlineHomeTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/Slice4Pass2OnlineHomeTest.kt b/office/src/test/java/com/vayunmathur/office/Slice4Pass2OnlineHomeTest.ktindex 579b874121..36533e1949 100644--- a/office/src/test/java/com/vayunmathur/office/Slice4Pass2OnlineHomeTest.kt+++ b/office/src/test/java/com/vayunmathur/office/Slice4Pass2OnlineHomeTest.kt@@ -134,6 +134,7 @@ class Slice4Pass2OnlineHomeTest {         var editorNavs = 0         rule.setContent {             OfficeTabs(+                backStack = com.vayunmathur.library.util.NavBackStack(arrayOf(OfficeRoute.OfflineHome)),                 viewModel = viewModel,                 onOpenDocument = {},                 onNavigateEditor = { editorNavs++ },@@ -144,6 +145,8 @@ class Slice4Pass2OnlineHomeTest {         rule.onNodeWithText(str(R.string.open_document)).assertExists()         rule.onNodeWithText("Online").assertExists()         rule.onNodeWithText("Offline").assertExists()+        rule.onNodeWithText("Online").performClick()+        rule.waitForIdle()         assertEquals(0, editorNavs)     } @@ -195,8 +198,8 @@ class Slice4Pass2OnlineHomeTest {             Json.decodeFromString(OfficeRoute.serializer(), Json.encodeToString(OfficeRoute.serializer(), OfficeRoute.OnlineEditor("doc9"))),         )         assertEquals(-            OfficeRoute.Main,-            Json.decodeFromString(OfficeRoute.serializer(), Json.encodeToString(OfficeRoute.serializer(), OfficeRoute.Main)),+            OfficeRoute.OfflineHome,+            Json.decodeFromString(OfficeRoute.serializer(), Json.encodeToString(OfficeRoute.serializer(), OfficeRoute.OfflineHome)),         )         assertEquals(null, OfficeRoute.OfflineEditor().uri)     }
office/src/test/java/com/vayunmathur/office/Slice4ScreenTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/Slice4ScreenTest.kt b/office/src/test/java/com/vayunmathur/office/Slice4ScreenTest.ktindex 334513e42f..facba3c398 100644--- a/office/src/test/java/com/vayunmathur/office/Slice4ScreenTest.kt+++ b/office/src/test/java/com/vayunmathur/office/Slice4ScreenTest.kt@@ -87,7 +87,7 @@ class Slice4ScreenTest {         assertEquals("content://x", off.uri)         val on = OfficeRoute.OnlineEditor("doc1")         assertEquals("doc1", on.docId)-        assertTrue(OfficeRoute.Main is OfficeRoute)+        assertTrue(OfficeRoute.OfflineHome is OfficeRoute)     }      @Test fun lightThemeWrapsContent() {