vpn: swipe between the traffic leaderboards
- Commit
00aa6b6b0a1d6536509e84b9e5fe85685f48e510- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 03:54 UTC (9 hours ago)
- Parents
42bc5b7
The Logging destination's three leaderboards (Top apps, Most visited, Top domains by data) are in-screen peer pages: they share one destination, are not routes, and each is a self-contained list over a different ViewModel flow. A hand-rolled PrimaryScrollableTabRow plus when(tabIndex) made them tap-only. Convert LoggingContent to the shared TabbedPagerScaffold in PrimaryTabRow style over a saveable pager state: tap and swipe are equivalent and every leaderboard list keeps its scroll position while flipping. The delete-all action stays in the top bar. The host contract is unchanged - settled page changes still mirror to VpnTabs, which stores the tab in the Route.Logging destination, and a host-driven tab (deep link or restore) now also scrolls the pager to match, with equality guards both ways so the round trip settles. Tab labels lose their custom 13sp ellipsis styling to the shared tab row. Verified: :vpn:lint, :vpn:lintVitalRelease and :vpn:testDevUnitTest all pass.
Diff
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 f486d8ac4f..a7f245e6d5 100644--- a/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingContent.kt+++ b/vpn/src/main/java/com/vayunmathur/vpn/ui/LoggingContent.kt@@ -14,10 +14,8 @@ 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.runtime.getValue-import androidx.compose.runtime.mutableIntStateOf-import androidx.compose.runtime.saveable.rememberSaveable-import androidx.compose.runtime.setValue+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@@ -26,14 +24,15 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp-import com.vayunmathur.library.ui.AppScaffold 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.PrimaryScrollableTabRow-import com.vayunmathur.library.ui.Tab+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@@ -59,31 +58,39 @@ fun LoggingContent( /** 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: saveable so the chosen- // leaderboard survives rotation/process recreation, not routed destinations.- var tabIndex by rememberSaveable { mutableIntStateOf(initialTab) }+ // 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)+ } - AppScaffold(- title = "",- actions = {- IconButton(onClick = onDeleteAllLogsRequest) {- IconDelete()- }+ TabbedPagerScaffold(+ pagerState = pagerState,+ tabStyle = TabStyle.PrimaryTabRow,+ topBar = {+ TopAppBar(+ title = {},+ actions = {+ IconButton(onClick = onDeleteAllLogsRequest) {+ IconDelete()+ }+ },+ ) },- ) { pad ->- Column(Modifier.fillMaxSize().padding(pad)) {- PrimaryScrollableTabRow(selectedTabIndex = tabIndex) {- TABS.forEachIndexed { i, label ->- Tab(- selected = tabIndex == i,- onClick = { tabIndex = i; onTabChange(i) },- text = { Text(label, maxLines = 1, fontSize = 13.sp, overflow = TextOverflow.Ellipsis) },- )- }- }-- when (tabIndex) {- 0 -> Leaderboard(+ tabs = listOf(+ PagerTab(TABS[0]) {+ Leaderboard( entries = topApps.map { LeaderboardEntry( key = it.packageName ?: it.appLabel,@@ -95,7 +102,9 @@ fun LoggingContent( }, emptyText = "No traffic yet โ connect the VPN and browse", )- 1 -> Leaderboard(+ },+ PagerTab(TABS[1]) {+ Leaderboard( entries = domainsByCount.map { LeaderboardEntry( key = it.domain,@@ -108,7 +117,9 @@ fun LoggingContent( }, emptyText = "No domains yet โ connect the VPN and browse", )- 2 -> Leaderboard(+ },+ PagerTab(TABS[2]) {+ Leaderboard( entries = domainsByBytes.map { LeaderboardEntry( key = it.domain,@@ -121,10 +132,9 @@ fun LoggingContent( }, emptyText = "No domains yet โ connect the VPN and browse", )- }- }- }-+ },+ ),+ ) } private data class LeaderboardEntry(