Modern Apps git

← Modern-Apps.git

vpn: logging leaderboards as sibling routes with swipe

Commit
18186c474976a6d703dbb73eaff3df494dccb8ce
Author
Vayun Mathur <[email protected]>
When
2026-12-06 04:24 UTC (4 hours ago)
Parents
0d36a7a
The three Logging leaderboards stop being pager pages inside
Route.Logging and become sibling routes LoggingTopApps /
LoggingMostVisited / LoggingTopDomains, each collecting only its
own flow. VpnTabs nests a SwipeRouteHost (tab row + delete-all top
bar, outside the NavDisplay) inside the route-backed
TabbedPagerScaffold whose bottom tab bar is likewise outside the
navigation host: both bars stay still while a swipe/tab switch
replaces the Logging entry (SiblingPage crossfade), so Back returns
to the tab parent stack. The Logging bottom-bar tab targets the
leaderboard last viewed. Route.Logging(tab) is kept as a legacy
deep-link selector: its entry resolves the tab via
siblingRouteForIndex and replaces itself with that sibling, so old
deep links and restored stacks land on the right leaderboard.
Preview names now map to the new routes (logging-top-apps,
logging-most-visited, logging-top-domains; 5-logging keeps covering
the legacy selector). Metadata regenerated.

Verified: :vpn:lint, :vpn:lintVitalRelease and :vpn:testDevUnitTest
pass; :vpn:metadata regenerated.

Diff

metadata_data/photos/vpn/large-tablet/1.png
diff --git a/metadata_data/photos/vpn/large-tablet/1.png b/metadata_data/photos/vpn/large-tablet/1.pngindex 6b09d381a0..dbc4e06c90 100644Binary files a/metadata_data/photos/vpn/large-tablet/1.png and b/metadata_data/photos/vpn/large-tablet/1.png differ
metadata_data/photos/vpn/phone/1.png
diff --git a/metadata_data/photos/vpn/phone/1.png b/metadata_data/photos/vpn/phone/1.pngindex c24cd59a44..b9576ff8a4 100644Binary files a/metadata_data/photos/vpn/phone/1.png and b/metadata_data/photos/vpn/phone/1.png differ
metadata_data/photos/vpn/phone/10.png
diff --git a/metadata_data/photos/vpn/phone/10.png b/metadata_data/photos/vpn/phone/10.pngnew file mode 100644index 0000000000..86173ec6c2Binary files /dev/null and b/metadata_data/photos/vpn/phone/10.png differ
metadata_data/photos/vpn/phone/11.png
diff --git a/metadata_data/photos/vpn/phone/11.png b/metadata_data/photos/vpn/phone/11.pngnew file mode 100644index 0000000000..740891e19fBinary files /dev/null and b/metadata_data/photos/vpn/phone/11.png differ
metadata_data/photos/vpn/phone/2.png
diff --git a/metadata_data/photos/vpn/phone/2.png b/metadata_data/photos/vpn/phone/2.pngindex 6404e593ef..647667f46c 100644Binary files a/metadata_data/photos/vpn/phone/2.png and b/metadata_data/photos/vpn/phone/2.png differ
metadata_data/photos/vpn/phone/3.png
diff --git a/metadata_data/photos/vpn/phone/3.png b/metadata_data/photos/vpn/phone/3.pngindex a69990db3f..5c0dfe144b 100644Binary files a/metadata_data/photos/vpn/phone/3.png and b/metadata_data/photos/vpn/phone/3.png differ
metadata_data/photos/vpn/phone/4.png
diff --git a/metadata_data/photos/vpn/phone/4.png b/metadata_data/photos/vpn/phone/4.pngnew file mode 100644index 0000000000..87ffd92fd7Binary files /dev/null and b/metadata_data/photos/vpn/phone/4.png differ
metadata_data/photos/vpn/phone/5.png
diff --git a/metadata_data/photos/vpn/phone/5.png b/metadata_data/photos/vpn/phone/5.pngnew file mode 100644index 0000000000..c24cd59a44Binary files /dev/null and b/metadata_data/photos/vpn/phone/5.png differ
metadata_data/photos/vpn/phone/6.png
diff --git a/metadata_data/photos/vpn/phone/6.png b/metadata_data/photos/vpn/phone/6.pngnew file mode 100644index 0000000000..c4316e686dBinary files /dev/null and b/metadata_data/photos/vpn/phone/6.png differ
metadata_data/photos/vpn/phone/7.png
diff --git a/metadata_data/photos/vpn/phone/7.png b/metadata_data/photos/vpn/phone/7.pngnew file mode 100644index 0000000000..35bb4b6397Binary files /dev/null and b/metadata_data/photos/vpn/phone/7.png differ
metadata_data/photos/vpn/phone/8.png
diff --git a/metadata_data/photos/vpn/phone/8.png b/metadata_data/photos/vpn/phone/8.pngnew file mode 100644index 0000000000..a2a40d1d3aBinary files /dev/null and b/metadata_data/photos/vpn/phone/8.png differ
metadata_data/photos/vpn/phone/9.png
diff --git a/metadata_data/photos/vpn/phone/9.png b/metadata_data/photos/vpn/phone/9.pngnew file mode 100644index 0000000000..ece242e232Binary files /dev/null and b/metadata_data/photos/vpn/phone/9.png differ
vpn/AGENTS.md
diff --git a/vpn/AGENTS.md b/vpn/AGENTS.mdindex 279b4ef221..d705e9754a 100644--- a/vpn/AGENTS.md+++ b/vpn/AGENTS.md@@ -54,8 +54,9 @@ _Install: ./install vpn (dev by default)._ - com/vayunmathur/vpn/ui/ConfigListContent.kt - com/vayunmathur/vpn/ui/ConfigDetailPage.kt - com/vayunmathur/vpn/ui/BypassListPage.kt-- com/vayunmathur/vpn/ui/LoggingPage.kt-- com/vayunmathur/vpn/ui/LoggingContent.kt+- com/vayunmathur/vpn/ui/LoggingPage.kt — Top apps sibling route + `LOGGING_SIBLINGS` order+- com/vayunmathur/vpn/ui/LoggingMostVisitedPage.kt, LoggingTopDomainsPage.kt, LoggingRedirectPage.kt — Most visited / Top domains sibling routes; legacy `Route.Logging(tab)` deep-link redirect+- com/vayunmathur/vpn/ui/LoggingContent.kt — shared leaderboard rows; per-kind contents in TopAppsLeaderboard.kt / MostVisitedLeaderboard.kt / TopDomainsLeaderboard.kt - com/vayunmathur/vpn/ui/SettingsPage.kt - com/vayunmathur/vpn/ui/GeoPickerPage.kt - com/vayunmathur/vpn/ui/GeoCountryPage.kt
vpn/src/main/java/com/vayunmathur/vpn/Route.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/Route.kt b/vpn/src/main/java/com/vayunmathur/vpn/Route.ktindex 0a67227d99..9cd7743f9f 100644--- a/vpn/src/main/java/com/vayunmathur/vpn/Route.kt+++ b/vpn/src/main/java/com/vayunmathur/vpn/Route.kt@@ -11,14 +11,26 @@ sealed interface Route : NavKey {     data object Tunnels : Route      /**-     * The Logging tab: a sibling destination switched with `backStack.reset`.-     * [tab] is the in-screen leaderboard tab the Logging screen last showed, so-     * leaving and returning to Logging restores it; the sub-tabs themselves stay-     * in-screen state of the Logging destination (see `LoggingContent`).+     * Legacy Logging selector kept for deep links / restored stacks saved+     * before the leaderboards became routes. It never stays on the stack:+     * the Logging entry resolves [tab] to the sibling route below+     * (`siblingRouteForIndex`) and replaces itself with it.      */     @Serializable     data class Logging(val tab: Int = 0) : Route +    /** The Top apps leaderboard sibling route (order 0 of the Logging group). */+    @Serializable+    data object LoggingTopApps : Route++    /** The Most visited leaderboard sibling route (order 1 of the Logging group). */+    @Serializable+    data object LoggingMostVisited : Route++    /** The Top domains by data leaderboard sibling route (order 2 of the Logging group). */+    @Serializable+    data object LoggingTopDomains : Route+     /** The Settings tab: a sibling destination switched with `backStack.reset`. */     @Serializable     data object Settings : Route
vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingContent.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingContent.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingContent.ktindex a7f245e6d5..d5c734088f 100644--- a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingContent.kt+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingContent.kt@@ -14,8 +14,6 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable-import androidx.compose.foundation.pager.rememberPagerState-import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.font.FontFamily@@ -25,119 +23,14 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.LinearProgressIndicator import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.PagerTab-import com.vayunmathur.library.ui.TabStyle-import com.vayunmathur.library.ui.TabbedPagerScaffold-import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.ui.Text-import com.vayunmathur.vpn.data.AppUsageSummary-import com.vayunmathur.vpn.data.DomainBytesSummary-import com.vayunmathur.vpn.data.DomainCountSummary -private val TABS = listOf("Top apps", "Most visited", "Top domains by data")+/** Ordered labels of the Logging sibling routes, in swipe order. */+internal val LOGGING_TABS = listOf("Top apps", "Most visited", "Top domains by data") -/**- * The traffic leaderboards, with no ViewModel reference so they can be rendered from a- * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.- */-@Composable-fun LoggingContent(-    topApps: List<AppUsageSummary>,-    domainsByCount: List<DomainCountSummary>,-    domainsByBytes: List<DomainBytesSummary>,-    onDeleteAllLogsRequest: () -> Unit = {},-    /**-     * Which leaderboard to open on. The app always starts on the first; previews set it so a-     * given tab can be captured without driving the UI to get there.-     */-    initialTab: Int = 0,-    /** Notified when the in-screen leaderboard tab changes, so the host can mirror it. */-    onTabChange: (Int) -> Unit = {},-) {-    // In-screen sub-tabs of the Logging destination: the pager state is-    // saveable so the chosen leaderboard survives rotation/process-    // recreation; these are not routed destinations.-    val pagerState = rememberPagerState(-        initialPage = initialTab.coerceIn(0, TABS.lastIndex),-        pageCount = { TABS.size },-    )-    // Mirror settled-page changes to the host (it stores the tab in the-    // Logging route), and follow a host-driven tab change (deep link /-    // restore) onto the pager. Both directions guard on equality, so the-    // mirror -> route -> mirror round trip settles instead of looping.-    LaunchedEffect(pagerState.currentPage) { onTabChange(pagerState.currentPage) }-    LaunchedEffect(initialTab) {-        val target = initialTab.coerceIn(0, TABS.lastIndex)-        if (pagerState.currentPage != target) pagerState.animateScrollToPage(target)-    }--    TabbedPagerScaffold(-        pagerState = pagerState,-        tabStyle = TabStyle.PrimaryTabRow,-        topBar = {-            TopAppBar(-                title = {},-                actions = {-                    IconButton(onClick = onDeleteAllLogsRequest) {-                        IconDelete()-                    }-                },-            )-        },-        tabs = listOf(-            PagerTab(TABS[0]) {-                Leaderboard(-                    entries = topApps.map {-                        LeaderboardEntry(-                            key = it.packageName ?: it.appLabel,-                            title = it.appLabel.ifBlank { it.packageName ?: "Unknown" },-                            subtitle = it.packageName,-                            value = formatBytes(it.totalBytes),-                            weight = it.totalBytes,-                        )-                    },-                    emptyText = "No traffic yet — connect the VPN and browse",-                )-            },-            PagerTab(TABS[1]) {-                Leaderboard(-                    entries = domainsByCount.map {-                        LeaderboardEntry(-                            key = it.domain,-                            title = it.domain,-                            subtitle = null,-                            value = "${it.totalCount} req",-                            weight = it.totalCount,-                            monospaceTitle = true,-                        )-                    },-                    emptyText = "No domains yet — connect the VPN and browse",-                )-            },-            PagerTab(TABS[2]) {-                Leaderboard(-                    entries = domainsByBytes.map {-                        LeaderboardEntry(-                            key = it.domain,-                            title = it.domain,-                            subtitle = null,-                            value = formatBytes(it.totalBytes),-                            weight = it.totalBytes,-                            monospaceTitle = true,-                        )-                    },-                    emptyText = "No domains yet — connect the VPN and browse",-                )-            },-        ),-    )-}--private data class LeaderboardEntry(+internal data class LeaderboardEntry(     val key: String,     val title: String,     val subtitle: String?,@@ -147,7 +40,7 @@ private data class LeaderboardEntry( )  @Composable-private fun Leaderboard(entries: List<LeaderboardEntry>, emptyText: String) {+internal fun Leaderboard(entries: List<LeaderboardEntry>, emptyText: String) {     if (entries.isEmpty()) {         Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {             Text(emptyText, color = MaterialTheme.colorScheme.onSurfaceVariant, fontSize = 13.sp)
vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingMostVisitedPage.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingMostVisitedPage.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingMostVisitedPage.ktnew file mode 100644index 0000000000..1265f75584--- /dev/null+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingMostVisitedPage.kt@@ -0,0 +1,13 @@+package com.vayunmathur.vpn.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import com.vayunmathur.vpn.platform.VpnViewModel++/** Most visited sibling route: its own destination, collecting only its flow. */+@Composable+fun LoggingMostVisitedPage(vm: VpnViewModel) {+    val domainsByCount by vm.domainsByCountFlow.collectAsState()+    MostVisitedLeaderboard(domainsByCount)+}
vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingPage.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingPage.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingPage.ktindex c5d2a2c8b5..508be6fb21 100644--- a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingPage.kt+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingPage.kt@@ -3,25 +3,16 @@ package com.vayunmathur.vpn.ui import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue+import com.vayunmathur.vpn.Route import com.vayunmathur.vpn.platform.VpnViewModel +/** The Logging sibling routes, in swipe order. */+internal val LOGGING_SIBLINGS: List<Route> =+    listOf(Route.LoggingTopApps, Route.LoggingMostVisited, Route.LoggingTopDomains)++/** Top apps sibling route: its own destination, collecting only its flow. */ @Composable-fun LoggingPage(-    vm: VpnViewModel,-    initialTab: Int = 0,-    onTabChange: (Int) -> Unit = {},-    onDeleteAllLogsRequest: () -> Unit = {},-) {+fun LoggingTopAppsPage(vm: VpnViewModel) {     val topApps by vm.topAppsFlow.collectAsState()-    val domainsByCount by vm.domainsByCountFlow.collectAsState()-    val domainsByBytes by vm.domainsByBytesFlow.collectAsState()--    LoggingContent(-        topApps = topApps,-        domainsByCount = domainsByCount,-        domainsByBytes = domainsByBytes,-        onDeleteAllLogsRequest = onDeleteAllLogsRequest,-        initialTab = initialTab,-        onTabChange = onTabChange,-    )+    TopAppsLeaderboard(topApps) }
vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingRedirectPage.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingRedirectPage.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingRedirectPage.ktnew file mode 100644index 0000000000..719325dd77--- /dev/null+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingRedirectPage.kt@@ -0,0 +1,24 @@+package com.vayunmathur.vpn.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.siblingRouteForIndex+import com.vayunmathur.vpn.Route+import com.vayunmathur.vpn.platform.VpnViewModel++/** Legacy `Route.Logging(tab)` deep link: resolve to the sibling route and replace itself with it. */+@Composable+fun LoggingRedirectPage(backStack: NavBackStack<Route>, vm: VpnViewModel, tab: Int) {+    val target = siblingRouteForIndex(LOGGING_SIBLINGS, tab)+    LaunchedEffect(target) {+        if (backStack.last() != target) backStack.setLast(target)+    }+    // Render the resolved leaderboard while the redirect lands, so the+    // deep-linked sibling is what the user sees from the first frame.+    when (target) {+        Route.LoggingTopApps -> LoggingTopAppsPage(vm)+        Route.LoggingMostVisited -> LoggingMostVisitedPage(vm)+        else -> LoggingTopDomainsPage(vm)+    }+}
vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingTopDomainsPage.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingTopDomainsPage.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingTopDomainsPage.ktnew file mode 100644index 0000000000..242cf3ecac--- /dev/null+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingTopDomainsPage.kt@@ -0,0 +1,13 @@+package com.vayunmathur.vpn.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import com.vayunmathur.vpn.platform.VpnViewModel++/** Top domains by data sibling route: its own destination, collecting only its flow. */+@Composable+fun LoggingTopDomainsPage(vm: VpnViewModel) {+    val domainsByBytes by vm.domainsByBytesFlow.collectAsState()+    TopDomainsLeaderboard(domainsByBytes)+}
vpn/src/main/java/com/vayunmathur/vpn/ui/MostVisitedLeaderboard.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/MostVisitedLeaderboard.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/MostVisitedLeaderboard.ktnew file mode 100644index 0000000000..1f4f054cd2--- /dev/null+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/MostVisitedLeaderboard.kt@@ -0,0 +1,22 @@+package com.vayunmathur.vpn.ui++import androidx.compose.runtime.Composable+import com.vayunmathur.vpn.data.DomainCountSummary++/** The Most visited leaderboard content of the [com.vayunmathur.vpn.Route.LoggingMostVisited] sibling route. */+@Composable+fun MostVisitedLeaderboard(domainsByCount: List<DomainCountSummary>) {+    Leaderboard(+        entries = domainsByCount.map {+            LeaderboardEntry(+                key = it.domain,+                title = it.domain,+                subtitle = null,+                value = "${it.totalCount} req",+                weight = it.totalCount,+                monospaceTitle = true,+            )+        },+        emptyText = "No domains yet \u2014 connect the VPN and browse",+    )+}
vpn/src/main/java/com/vayunmathur/vpn/ui/TopAppsLeaderboard.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/TopAppsLeaderboard.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/TopAppsLeaderboard.ktnew file mode 100644index 0000000000..ce7e086eb3--- /dev/null+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/TopAppsLeaderboard.kt@@ -0,0 +1,21 @@+package com.vayunmathur.vpn.ui++import androidx.compose.runtime.Composable+import com.vayunmathur.vpn.data.AppUsageSummary++/** The Top apps leaderboard content of the [com.vayunmathur.vpn.Route.LoggingTopApps] sibling route. */+@Composable+fun TopAppsLeaderboard(topApps: List<AppUsageSummary>) {+    Leaderboard(+        entries = topApps.map {+            LeaderboardEntry(+                key = it.packageName ?: it.appLabel,+                title = it.appLabel.ifBlank { it.packageName ?: "Unknown" },+                subtitle = it.packageName,+                value = formatBytes(it.totalBytes),+                weight = it.totalBytes,+            )+        },+        emptyText = "No traffic yet \u2014 connect the VPN and browse",+    )+}
vpn/src/main/java/com/vayunmathur/vpn/ui/TopDomainsLeaderboard.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/TopDomainsLeaderboard.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/TopDomainsLeaderboard.ktnew file mode 100644index 0000000000..e1d4762f95--- /dev/null+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/TopDomainsLeaderboard.kt@@ -0,0 +1,22 @@+package com.vayunmathur.vpn.ui++import androidx.compose.runtime.Composable+import com.vayunmathur.vpn.data.DomainBytesSummary++/** The Top domains leaderboard content of the [com.vayunmathur.vpn.Route.LoggingTopDomains] sibling route. */+@Composable+fun TopDomainsLeaderboard(domainsByBytes: List<DomainBytesSummary>) {+    Leaderboard(+        entries = domainsByBytes.map {+            LeaderboardEntry(+                key = it.domain,+                title = it.domain,+                subtitle = null,+                value = formatBytes(it.totalBytes),+                weight = it.totalBytes,+                monospaceTitle = true,+            )+        },+        emptyText = "No domains yet \u2014 connect the VPN and browse",+    )+}
vpn/src/main/java/com/vayunmathur/vpn/ui/VpnTabs.kt
diff --git a/vpn/src/main/java/com/vayunmathur/vpn/ui/VpnTabs.kt b/vpn/src/main/java/com/vayunmathur/vpn/ui/VpnTabs.ktindex b1370dcf3d..30517e5cba 100644--- a/vpn/src/main/java/com/vayunmathur/vpn/ui/VpnTabs.kt+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/VpnTabs.kt@@ -6,11 +6,15 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue+import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconDashboard+import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconHistory import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.RouteTab+import com.vayunmathur.library.ui.SwipeRouteHost import com.vayunmathur.library.ui.TabbedPagerScaffold+import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.util.DialogPage import com.vayunmathur.library.util.ListDetailPage import com.vayunmathur.library.util.ListPage@@ -24,68 +28,93 @@ import com.vayunmathur.vpn.ui.dialogs.DeleteAllLogsDialog  /**  * The three top-level tabs as sibling routes. The route-backed- * [TabbedPagerScaffold] owns the tab bar / rail chrome and switches tabs with- * `backStack.reset`, so each tab is a real destination (deep link, restore and- * back see it) instead of a pager page inside one `Route.Main`. Detail and- * BypassList push on top of whichever tab is showing.+ * [TabbedPagerScaffold] owns the bottom tab bar / rail chrome — rendered+ * outside the navigation host, so it stays still while content+ * transitions — and switches tabs with `backStack.reset`, so each tab+ * is a real destination (deep link, restore and back see it). Detail+ * and BypassList push on top of whichever tab is showing.  *- * The Logging leaderboard tab is in-screen state of the Logging destination;- * it is mirrored into [Route.Logging] (and remembered here for the tab's- * target route) so returning to Logging restores the leaderboard last viewed.+ * Inside the Logging tab, the three leaderboards are sibling routes of+ * their own ([LOGGING_SIBLINGS]), hosted by a nested [SwipeRouteHost]+ * around the same [MainNavigation]: its tab row and delete-all top bar+ * sit outside the `NavDisplay` too, and a swipe or tab tap replaces the+ * Logging entry (never pushes), so Back from any leaderboard returns to+ * the tab's parent stack, not to the previous leaderboard. The Logging+ * bottom-bar tab targets the leaderboard last viewed. A legacy+ * `Route.Logging(tab)` deep link resolves to its sibling on entry.  */ @Composable fun VpnTabs(backStack: NavBackStack<Route>, vm: VpnViewModel) {-    var loggingTab by rememberSaveable {-        mutableIntStateOf((backStack.last() as? Route.Logging)?.tab ?: 0)+    var loggingIndex by rememberSaveable {+        mutableIntStateOf(loggingIndexOf(backStack.last()).coerceAtLeast(0))     }-    // A restored or deep-linked Logging route carries its tab; keep the tab-    // target in sync when the stack top is Logging with a different tab.-    val topLoggingTab = (backStack.last() as? Route.Logging)?.tab-    LaunchedEffect(topLoggingTab) {-        if (topLoggingTab != null && topLoggingTab != loggingTab) loggingTab = topLoggingTab+    val topLoggingIndex = loggingIndexOf(backStack.last())+    LaunchedEffect(topLoggingIndex) {+        if (topLoggingIndex >= 0 && topLoggingIndex != loggingIndex) loggingIndex = topLoggingIndex+    }+    val legacyTab = (backStack.last() as? Route.Logging)?.tab+    LaunchedEffect(legacyTab) {+        if (legacyTab != null) loggingIndex = legacyTab.coerceIn(0, LOGGING_SIBLINGS.lastIndex)     }     val tabs = listOf<RouteTab<Route>>(         RouteTab(Route.Tunnels, "Tunnels") { IconDashboard() },-        RouteTab(Route.Logging(loggingTab), "Logging") { IconHistory() },+        RouteTab(LOGGING_SIBLINGS[loggingIndex], "Logging") { IconHistory() },         RouteTab(Route.Settings, "Settings") { IconSettings() },     )     TabbedPagerScaffold(backStack = backStack, tabs = tabs) {-        MainNavigation(backStack) {-            entry<Route.Tunnels>(metadata = SiblingPage() + ListPage()) {-                ConfigListPage(backStack, vm)-            }-            entry<Route.Logging>(metadata = SiblingPage()) {-                LoggingPage(-                    vm,-                    initialTab = it.tab,-                    onTabChange = { tab ->-                        loggingTab = tab-                        if (backStack.last() != Route.Logging(tab)) {-                            backStack.setLast(Route.Logging(tab))+        SwipeRouteHost(+            backStack = backStack,+            tabs = LOGGING_SIBLINGS.mapIndexed { index, route -> RouteTab(route, LOGGING_TABS[index]) },+            showChrome = { it in LOGGING_SIBLINGS || it is Route.Logging },+            topBar = {+                TopAppBar(+                    title = {},+                    actions = {+                        IconButton(onClick = { backStack.add(Route.DeleteAllLogsDialog) }) {+                            IconDelete()                         }                     },-                    onDeleteAllLogsRequest = { backStack.add(Route.DeleteAllLogsDialog) },-                )-            }-            entry<Route.Settings>(metadata = SiblingPage()) { SettingsPage(backStack) }-            entry<Route.Detail>(metadata = ListDetailPage() + MorphPage()) {-                ConfigDetailPage(backStack, vm, it.id)-            }-            entry<Route.BypassList>(metadata = ListDetailPage()) { BypassListPage(backStack) }-            entry<Route.GeoPicker>(metadata = ListDetailPage()) { GeoPickerPage(backStack, vm) }-            entry<Route.GeoCountry>(metadata = ListDetailPage()) { GeoCountryPage(backStack, vm, it.countryCode) }-            entry<Route.GeoCity>(metadata = ListDetailPage()) {-                GeoCityPage(backStack, vm, it.countryCode, it.city)-            }-            entry<Route.DeleteAllLogsDialog>(metadata = DialogPage()) {-                DeleteAllLogsDialog(-                    onDismiss = { backStack.pop() },-                    onConfirm = {-                        vm.deleteAllLogs()-                        backStack.pop()-                    },                 )+            },+        ) {+            MainNavigation(backStack) {+                entry<Route.Tunnels>(metadata = SiblingPage() + ListPage()) {+                    ConfigListPage(backStack, vm)+                }+                entry<Route.LoggingTopApps>(metadata = SiblingPage()) { LoggingTopAppsPage(vm) }+                entry<Route.LoggingMostVisited>(metadata = SiblingPage()) { LoggingMostVisitedPage(vm) }+                entry<Route.LoggingTopDomains>(metadata = SiblingPage()) { LoggingTopDomainsPage(vm) }+                entry<Route.Logging>(metadata = SiblingPage()) {+                    LoggingRedirectPage(backStack, vm, it.tab)+                }+                entry<Route.Settings>(metadata = SiblingPage()) { SettingsPage(backStack) }+                entry<Route.Detail>(metadata = ListDetailPage() + MorphPage()) {+                    ConfigDetailPage(backStack, vm, it.id)+                }+                entry<Route.BypassList>(metadata = ListDetailPage()) { BypassListPage(backStack) }+                entry<Route.GeoPicker>(metadata = ListDetailPage()) { GeoPickerPage(backStack, vm) }+                entry<Route.GeoCountry>(metadata = ListDetailPage()) { GeoCountryPage(backStack, vm, it.countryCode) }+                entry<Route.GeoCity>(metadata = ListDetailPage()) {+                    GeoCityPage(backStack, vm, it.countryCode, it.city)+                }+                entry<Route.DeleteAllLogsDialog>(metadata = DialogPage()) {+                    DeleteAllLogsDialog(+                        onDismiss = { backStack.pop() },+                        onConfirm = {+                            vm.deleteAllLogs()+                            backStack.pop()+                        },+                    )+                }             }         }     } }++private fun loggingIndexOf(route: Route): Int = when (route) {+    Route.LoggingTopApps -> 0+    Route.LoggingMostVisited -> 1+    Route.LoggingTopDomains -> 2+    is Route.Logging -> route.tab.coerceIn(0, LOGGING_SIBLINGS.lastIndex)+    else -> -1+}
vpn/src/screenshotTest/kotlin/com/vayunmathur/vpn/ui/MetadataPreviews.kt
diff --git a/vpn/src/screenshotTest/kotlin/com/vayunmathur/vpn/ui/MetadataPreviews.kt b/vpn/src/screenshotTest/kotlin/com/vayunmathur/vpn/ui/MetadataPreviews.ktindex 9331ab469e..48a4a792c7 100644--- a/vpn/src/screenshotTest/kotlin/com/vayunmathur/vpn/ui/MetadataPreviews.kt+++ b/vpn/src/screenshotTest/kotlin/com/vayunmathur/vpn/ui/MetadataPreviews.kt@@ -36,7 +36,7 @@ private const val EXPANDED = "spec:width=1280dp,height=800dp,dpi=240"  * Store listing images for `:vpn`. See `common-conventions-preview-metadata`.  *  * The pages take `(backStack, VpnViewModel)`, so the two screens shown here were split into- * stateless [ConfigListContent] and [LoggingContent]. Navigation stays in the page: a+ * stateless [ConfigListContent] and the leaderboard contents. Navigation stays in the page: a  * `NavBackStack` is not state the previews can meaningfully fake.  *  * Each preview needs @PreviewTest as well as @Preview: @Preview alone renders in Studio but@@ -112,20 +112,27 @@ class MetadataPreviews {     }      @PreviewTest-    @Preview(name = "2-top-apps", device = PHONE, group = "phone", showSystemUi = true)+    @Preview(name = "2-logging-top-apps", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview2TopApps() {         ChromePreview(selectedTab = 1)     }      @PreviewTest-    @Preview(name = "3-top-domains", device = PHONE, group = "phone", showSystemUi = true)+    @Preview(name = "3-logging-top-domains", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview3TopDomains() {         ChromePreview(selectedTab = 1, loggingTab = 2)     } -    @PreviewTest+        @PreviewTest+    @Preview(name = "13-logging-most-visited", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview13LoggingMostVisited() {+        ChromePreview(selectedTab = 1, loggingTab = 1)+    }++@PreviewTest     @Preview(name = "4-expanded", device = EXPANDED, group = "large-tablet", showSystemUi = true)     @Composable     // CHROME EXEMPT: pushed traffic-detail route renders with no tab chrome on device.@@ -133,7 +140,7 @@ class MetadataPreviews {         DynamicTheme(darkTheme = true) {             // Expanded windows keep the tunnel list visible while the traffic             // detail opens beside it instead of covering it. ConfigDetailPage-            // reads its ViewModel internally, so the previewable LoggingContent+            // reads its ViewModel internally, so the previewable leaderboard content             // stands in as the detail pane.             Row(Modifier.fillMaxSize()) {                 Box(Modifier.weight(1f).fillMaxHeight()) {@@ -144,11 +151,7 @@ class MetadataPreviews {                     )                 }                 Box(Modifier.weight(0.6f).fillMaxHeight()) {-                    LoggingContent(-                        topApps = topApps,-                        domainsByCount = domainsByCount,-                        domainsByBytes = domainsByBytes,-                    )+                    TopAppsLeaderboard(topApps = topApps)                 }             }         }@@ -290,24 +293,21 @@ class MetadataPreviews {     private fun ChromePreview(selectedTab: Int, loggingTab: Int = 0) {         DynamicTheme(darkTheme = true) {             val startRoute: Route = when (selectedTab) {-                1 -> Route.Logging(loggingTab)+                1 -> LOGGING_SIBLINGS[loggingTab]                 2 -> Route.Settings                 else -> Route.Tunnels             }             val backStack = NavBackStack(arrayOf(startRoute))             val tabs = listOf<RouteTab<Route>>(                 RouteTab(Route.Tunnels, "Tunnels") { IconDashboard() },-                RouteTab(Route.Logging(loggingTab), "Logging") { IconHistory() },+                RouteTab(LOGGING_SIBLINGS[loggingTab], "Logging") { IconHistory() },                 RouteTab(Route.Settings, "Settings") { IconSettings() },             )             TabbedPagerScaffold(backStack = backStack, tabs = tabs) { route ->                 when (route) {-                    is Route.Logging -> LoggingContent(-                        topApps = topApps,-                        domainsByCount = domainsByCount,-                        domainsByBytes = domainsByBytes,-                        initialTab = loggingTab,-                    )+                    Route.LoggingMostVisited -> MostVisitedLeaderboard(domainsByCount)+                    Route.LoggingTopDomains -> TopDomainsLeaderboard(domainsByBytes)+                    is Route.Logging -> TopAppsLeaderboard(topApps)                     Route.Settings -> SettingsPage(backStack = backStack)                     else -> ConfigListContent(                         configs = tunnels,
vpn/src/test/java/com/vayunmathur/vpn/ui/FinalVpnBatchTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/ui/FinalVpnBatchTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/ui/FinalVpnBatchTest.ktindex 7bc490b8bd..f2af58fd8e 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/ui/FinalVpnBatchTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/ui/FinalVpnBatchTest.kt@@ -15,6 +15,7 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.onRoot import androidx.test.core.app.ApplicationProvider import com.vayunmathur.library.ui.DynamicTheme+import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.vpn.Route import com.vayunmathur.vpn.data.AppUsageSummary import com.vayunmathur.vpn.platform.VpnViewModel@@ -60,7 +61,8 @@ class FinalVpnBatchTest {         var requested = 0         rule.setContent {             DynamicTheme {-                LoggingContent(+                LoggingSiblingHost(+                    backStack = NavBackStack(arrayOf(Route.LoggingTopApps)),                     topApps = listOf(AppUsageSummary("com.a", "A", 10, 1)),                     domainsByCount = emptyList(), domainsByBytes = emptyList(),                     onDeleteAllLogsRequest = { requested++ },
vpn/src/test/java/com/vayunmathur/vpn/ui/LoggingSiblingHost.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/ui/LoggingSiblingHost.kt b/vpn/src/test/java/com/vayunmathur/vpn/ui/LoggingSiblingHost.ktnew file mode 100644index 0000000000..49d6c45df6--- /dev/null+++ b/vpn/src/test/java/com/vayunmathur/vpn/ui/LoggingSiblingHost.kt@@ -0,0 +1,42 @@+package com.vayunmathur.vpn.ui++import androidx.compose.runtime.Composable+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.RouteTab+import com.vayunmathur.library.ui.SwipeRouteHost+import com.vayunmathur.library.ui.TopAppBar+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.vpn.Route+import com.vayunmathur.vpn.data.AppUsageSummary+import com.vayunmathur.vpn.data.DomainBytesSummary+import com.vayunmathur.vpn.data.DomainCountSummary++/** Test host for the Logging sibling routes, mirroring `VpnTabs`' chrome. */+@Composable+fun LoggingSiblingHost(+    backStack: NavBackStack<Route>,+    topApps: List<AppUsageSummary>,+    domainsByCount: List<DomainCountSummary>,+    domainsByBytes: List<DomainBytesSummary>,+    onDeleteAllLogsRequest: () -> Unit = {},+) {+    SwipeRouteHost(+        backStack = backStack,+        tabs = LOGGING_SIBLINGS.mapIndexed { index, route -> RouteTab(route, LOGGING_TABS[index]) },+        topBar = {+            TopAppBar(+                title = {},+                actions = {+                    IconButton(onClick = onDeleteAllLogsRequest) { IconDelete() }+                },+            )+        },+    ) { route ->+        when (route) {+            Route.LoggingMostVisited -> MostVisitedLeaderboard(domainsByCount)+            Route.LoggingTopDomains -> TopDomainsLeaderboard(domainsByBytes)+            else -> TopAppsLeaderboard(topApps)+        }+    }+}
vpn/src/test/java/com/vayunmathur/vpn/ui/VpnComposeScreensTest.kt
diff --git a/vpn/src/test/java/com/vayunmathur/vpn/ui/VpnComposeScreensTest.kt b/vpn/src/test/java/com/vayunmathur/vpn/ui/VpnComposeScreensTest.ktindex ac65a067de..d8a57d0ec4 100644--- a/vpn/src/test/java/com/vayunmathur/vpn/ui/VpnComposeScreensTest.kt+++ b/vpn/src/test/java/com/vayunmathur/vpn/ui/VpnComposeScreensTest.kt@@ -13,6 +13,7 @@ import androidx.compose.ui.test.onFirst import androidx.compose.ui.test.performScrollTo import androidx.test.core.app.ApplicationProvider import com.vayunmathur.library.ui.DynamicTheme+import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.vpn.Route import com.vayunmathur.vpn.data.AppUsageSummary@@ -90,7 +91,8 @@ class VpnComposeScreensTest {         var deleteAll = 0         rule.setContent {             DynamicTheme {-                LoggingContent(+                LoggingSiblingHost(+                    backStack = NavBackStack(arrayOf(Route.LoggingTopApps)),                     topApps = listOf(AppUsageSummary("com.a", "App A", 2048, 3), AppUsageSummary(null, "", 1024, 1)),                     domainsByCount = listOf(DomainCountSummary("a.com", 7)),                     domainsByBytes = listOf(DomainBytesSummary("b.com", 1048576)),@@ -110,7 +112,7 @@ class VpnComposeScreensTest {     }      @Test fun loggingEmptyStates() {-        rule.setContent { DynamicTheme { LoggingContent(emptyList(), emptyList(), emptyList(), initialTab = 1) } }+        rule.setContent { DynamicTheme { LoggingSiblingHost(NavBackStack(arrayOf(Route.LoggingMostVisited)), emptyList(), emptyList(), emptyList()) } }         rule.onNodeWithText("No domains yet — connect the VPN and browse").assertIsDisplayed()     }