Modern Apps git

← Modern-Apps.git

email: keep Navigation.kt to the Navigation composable

Commit
22e8328220148d4f003594692b133b08e64e2f3c
Author
Vayun Mathur <[email protected]>
When
2026-11-19 03:29 UTC (17 days ago)
Parents
36cbf26
PackageStructure lint requires the app-root Navigation.kt to
contain only the top-level @Composable fun Navigation(...).
email parked its nav-entry builders in that file, which is
now a fatal lint error.

Move emailEntries and folderEntries verbatim into the new
ui/NavigationEntries.kt (package com.vayunmathur.email.ui).
emailEntries becomes internal so Navigation.kt can still
call it across files; folderEntries stays private to the new
file. Function names, signatures, and behaviour are unchanged;
Navigation.kt imports emailEntries from ui/ and drops the
imports only the moved builders used. No screens moved and
no navigation behaviour changed.

Verified: ./gradlew :email:lintDev :email:testDevUnitTest
both pass.

Diff

email/src/main/java/com/vayunmathur/email/Navigation.kt
diff --git a/email/src/main/java/com/vayunmathur/email/Navigation.kt b/email/src/main/java/com/vayunmathur/email/Navigation.ktindex 19f9a8b8da..13aa5ee138 100644--- a/email/src/main/java/com/vayunmathur/email/Navigation.kt+++ b/email/src/main/java/com/vayunmathur/email/Navigation.kt@@ -8,22 +8,12 @@ import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vayunmathur.email.platform.EmailViewModel import com.vayunmathur.email.platform.IntentState-import com.vayunmathur.email.platform.addAccountEntries-import com.vayunmathur.email.ui.ComposerScreen-import com.vayunmathur.email.ui.DraftsScreen import com.vayunmathur.email.ui.EmailDrawerContent-import com.vayunmathur.email.ui.EmlViewerScreen-import com.vayunmathur.email.ui.MessageListPage-import com.vayunmathur.email.ui.MessageThreadPage-import com.vayunmathur.email.ui.OutboxScreen-import com.vayunmathur.email.ui.SettingsScreen+import com.vayunmathur.email.ui.emailEntries import com.vayunmathur.library.ui.DrawerValue import com.vayunmathur.library.ui.ModalNavigationDrawer import com.vayunmathur.library.ui.rememberDrawerState-import com.vayunmathur.library.util.ListDetailPage-import com.vayunmathur.library.util.ListPage import com.vayunmathur.library.util.MainNavigation-import com.vayunmathur.library.util.MorphPage import com.vayunmathur.library.util.OpenSettingsIfRequested import com.vayunmathur.library.util.rememberNavBackStack import kotlinx.coroutines.launch@@ -85,88 +75,3 @@ fun Navigation(viewModel: EmailViewModel) {         }     } }--/** Every destination of the mail graph, registered on the host's entry scope. */-private fun com.vayunmathur.library.util.EntryProviderScope<Route>.emailEntries(-    viewModel: EmailViewModel,-    backStack: com.vayunmathur.library.util.NavBackStack<Route>,-    onOpenDrawer: () -> Unit,-) {-    entry<Route.MessageList>(metadata = ListPage()) {-        MessageListPage(-            viewModel = viewModel,-            onMessageClick = { msg ->-                val thread = msg.threadId ?: msg.id.toString()-                backStack.add(Route.MessageThread(msg.accountEmail, thread))-            },-            onComposeClick = { backStack.add(Route.Composer()) },-            onOpenDrawer = onOpenDrawer,-        )-    }-    entry<Route.MessageThread>(metadata = ListDetailPage() + MorphPage()) { route ->-        MessageThreadPage(-            viewModel = viewModel,-            accountEmail = route.accountEmail,-            threadId = route.threadId,-            onBack = { backStack.pop() },-            onReply = { to, sub, ref ->-                val subject = "Re: $sub"-                backStack.add(-                    Route.Composer(to = to, subject = subject, references = ref, inReplyTo = ref),-                )-            },-            onForward = { sub, body ->-                val subject = "Fwd: $sub"-                val quote = "\n\n---------- Forwarded message ----------\n$body"-                backStack.add(Route.Composer(subject = subject, body = quote))-            },-            onCompose = { to, sub -> backStack.add(Route.Composer(to = to, subject = sub)) },-        )-    }-    // Morph: a draft's subject line travels out of the drafts list into the subject field.-    // The other five ways in carry no draft id, so their subject key is null and the screen-    // simply crossfades.-    entry<Route.Composer>(metadata = ListDetailPage() + MorphPage()) { route ->-        ComposerScreen(-            viewModel = viewModel,-            initialTo = route.to,-            initialSubject = route.subject,-            initialBody = route.body,-            inReplyTo = route.inReplyTo,-            references = route.references,-            draftId = route.draftId,-            onBack = { backStack.pop() },-        )-    }-    folderEntries(viewModel, backStack)-}--/** Outbox, settings, drafts, the EML viewer and the add-account graph. */-private fun com.vayunmathur.library.util.EntryProviderScope<Route>.folderEntries(-    viewModel: EmailViewModel,-    backStack: com.vayunmathur.library.util.NavBackStack<Route>,-) {-    entry<Route.Outbox>(metadata = ListDetailPage()) {-        OutboxScreen(viewModel = viewModel, onBack = { backStack.pop() })-    }-    addAccountEntries(backStack, onAccountAdded = { backStack.pop() })-    entry<Route.Settings>(metadata = ListDetailPage()) {-        SettingsScreen(viewModel = viewModel, onBack = { backStack.pop() })-    }-    entry<Route.Drafts>(metadata = ListDetailPage()) {-        DraftsScreen(-            viewModel = viewModel,-            onBack = { backStack.pop() },-            onOpenDraft = { id -> backStack.add(Route.Composer(draftId = id)) },-        )-    }-    entry<Route.EmlViewer>(metadata = ListDetailPage()) { route ->-        EmlViewerScreen(-            uriString = route.uriString,-            onBack = { backStack.pop() },-            onComposeForward = { sub, body ->-                backStack.add(Route.Composer(subject = sub, body = body))-            },-        )-    }-}
email/src/main/java/com/vayunmathur/email/ui/NavigationEntries.kt
diff --git a/email/src/main/java/com/vayunmathur/email/ui/NavigationEntries.kt b/email/src/main/java/com/vayunmathur/email/ui/NavigationEntries.ktnew file mode 100644index 0000000000..43387c7a5f--- /dev/null+++ b/email/src/main/java/com/vayunmathur/email/ui/NavigationEntries.kt@@ -0,0 +1,95 @@+package com.vayunmathur.email.ui++import com.vayunmathur.email.Route+import com.vayunmathur.email.platform.EmailViewModel+import com.vayunmathur.email.platform.addAccountEntries+import com.vayunmathur.library.util.EntryProviderScope+import com.vayunmathur.library.util.ListDetailPage+import com.vayunmathur.library.util.ListPage+import com.vayunmathur.library.util.MorphPage+import com.vayunmathur.library.util.NavBackStack++/** Every destination of the mail graph, registered on the host's entry scope. */+internal fun EntryProviderScope<Route>.emailEntries(+    viewModel: EmailViewModel,+    backStack: NavBackStack<Route>,+    onOpenDrawer: () -> Unit,+) {+    entry<Route.MessageList>(metadata = ListPage()) {+        MessageListPage(+            viewModel = viewModel,+            onMessageClick = { msg ->+                val thread = msg.threadId ?: msg.id.toString()+                backStack.add(Route.MessageThread(msg.accountEmail, thread))+            },+            onComposeClick = { backStack.add(Route.Composer()) },+            onOpenDrawer = onOpenDrawer,+        )+    }+    entry<Route.MessageThread>(metadata = ListDetailPage() + MorphPage()) { route ->+        MessageThreadPage(+            viewModel = viewModel,+            accountEmail = route.accountEmail,+            threadId = route.threadId,+            onBack = { backStack.pop() },+            onReply = { to, sub, ref ->+                val subject = "Re: $sub"+                backStack.add(+                    Route.Composer(to = to, subject = subject, references = ref, inReplyTo = ref),+                )+            },+            onForward = { sub, body ->+                val subject = "Fwd: $sub"+                val quote = "\n\n---------- Forwarded message ----------\n$body"+                backStack.add(Route.Composer(subject = subject, body = quote))+            },+            onCompose = { to, sub -> backStack.add(Route.Composer(to = to, subject = sub)) },+        )+    }+    // Morph: a draft's subject line travels out of the drafts list into the subject field.+    // The other five ways in carry no draft id, so their subject key is null and the screen+    // simply crossfades.+    entry<Route.Composer>(metadata = ListDetailPage() + MorphPage()) { route ->+        ComposerScreen(+            viewModel = viewModel,+            initialTo = route.to,+            initialSubject = route.subject,+            initialBody = route.body,+            inReplyTo = route.inReplyTo,+            references = route.references,+            draftId = route.draftId,+            onBack = { backStack.pop() },+        )+    }+    folderEntries(viewModel, backStack)+}++/** Outbox, settings, drafts, the EML viewer and the add-account graph. */+private fun EntryProviderScope<Route>.folderEntries(+    viewModel: EmailViewModel,+    backStack: NavBackStack<Route>,+) {+    entry<Route.Outbox>(metadata = ListDetailPage()) {+        OutboxScreen(viewModel = viewModel, onBack = { backStack.pop() })+    }+    addAccountEntries(backStack, onAccountAdded = { backStack.pop() })+    entry<Route.Settings>(metadata = ListDetailPage()) {+        SettingsScreen(viewModel = viewModel, onBack = { backStack.pop() })+    }+    entry<Route.Drafts>(metadata = ListDetailPage()) {+        DraftsScreen(+            viewModel = viewModel,+            onBack = { backStack.pop() },+            onOpenDraft = { id -> backStack.add(Route.Composer(draftId = id)) },+        )+    }+    entry<Route.EmlViewer>(metadata = ListDetailPage()) { route ->+        EmlViewerScreen(+            uriString = route.uriString,+            onBack = { backStack.pop() },+            onComposeForward = { sub, body ->+                backStack.add(Route.Composer(subject = sub, body = body))+            },+        )+    }+}