From 64a01d8ca250cb4df4fb6e6cb22d934df000e196 Mon Sep 17 00:00:00 2001 From: Jeena Date: Tue, 13 Oct 2026 23:33:06 +0000 Subject: [PATCH] lists: derive cards-per-row from screen and card width MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The adaptive grid resolves to exactly four cards on a full-width landscape TV pane — but a portrait-mounted or otherwise narrow TV gets fewer columns and the hardcoded row start broke there. Compute the count with the same arithmetic Compose uses (pane padding minus card minimum, integer division) so the drawer-from-row-start rule tracks the real grid on every mounting. --- .../jtubetv/ui/screens/list/VideoListScreen.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/net/jeena/jtubetv/ui/screens/list/VideoListScreen.kt b/app/src/main/java/net/jeena/jtubetv/ui/screens/list/VideoListScreen.kt index 265d2ed..02bd0b6 100644 --- a/app/src/main/java/net/jeena/jtubetv/ui/screens/list/VideoListScreen.kt +++ b/app/src/main/java/net/jeena/jtubetv/ui/screens/list/VideoListScreen.kt @@ -91,12 +91,18 @@ fun VideoListScreen( LaunchedEffect(source) { viewModel.loadChannelHeader(AppGraph.repository) } } - // Row starts of the 4-per-row grid: LEFT from a row's first card opens the - // drawer (issue #7). rowCardWidth() sizes the adaptive columns to resolve - // to exactly 4 on the full-width TV pane, so the row start is index % 4 — - // no layout measuring needed (measuring the first visible item instead was - // what made the full-span page header count as "one card per row"). - val cardsPerRow = 4 + // Row starts of the grid: LEFT from a row's first card opens the drawer + // (issue #7). The adaptive columns use a `rowCardWidth() - 12` minimum with + // zero spacing, and the content pane eats 40dp (8 start + 32 end), so the + // resolved card count is exactly Compose's arithmetic here — 4 on a full- + // width TV pane; a narrow/portrait TV gets fewer columns and keeps working. + val cardsPerRow = maxOf( + 1, + ( + (androidx.compose.ui.platform.LocalConfiguration.current.screenWidthDp - 40) / + (rowCardWidth().value - 12) + ).toInt(), + ) if (viewModel.loadingInitial && items.isEmpty()) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {