From 3d4b06db4495fe6084b51ed51a73bea45d45dec0 Mon Sep 17 00:00:00 2001 From: joshjryan Date: Sat, 3 Jan 2026 16:38:07 -0700 Subject: [PATCH] Guard against navigating to a non-existant tab (#629) Just make sure we don't crash if the selectedTabIndex isn't a positive int. Fixes #628. --------- Co-authored-by: Damontecres --- .../github/damontecres/wholphin/ui/components/TabRow.kt | 4 +++- .../wholphin/ui/detail/series/SeriesViewModel.kt | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/TabRow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/TabRow.kt index 16e26649..b8607b82 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/TabRow.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/TabRow.kt @@ -51,7 +51,9 @@ fun TabRow( ) { val state = rememberLazyListState() LaunchedEffect(selectedTabIndex) { - state.animateScrollToItem(selectedTabIndex, -(state.layoutInfo.viewportSize.width / 3.5).toInt()) + if (selectedTabIndex >= 0) { + state.animateScrollToItem(selectedTabIndex, -(state.layoutInfo.viewportSize.width / 3.5).toInt()) + } } val focusRequesters = remember(tabs) { List(tabs.size) { FocusRequester() } } var rowHasFocus by remember { mutableStateOf(false) } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt index 181e5b98..e5fd3cd4 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/detail/series/SeriesViewModel.kt @@ -161,7 +161,7 @@ class SeriesViewModel } ?: 0 Timber.v("Got initial season index: $index") position.update { - it.copy(seasonTabIndex = index) + it.copy(seasonTabIndex = index.coerceAtLeast(0)) } } } @@ -547,7 +547,10 @@ private suspend fun findIndexOf( val index = if (targetId != null && (targetNum == null || targetNum !in pager.indices)) { // No hint info, so have to check everything - pager.indexOfBlocking { equalsNotNull(it?.id, targetId) } + pager.indexOfBlocking { + equalsNotNull(it?.indexNumber, targetNum) || + equalsNotNull(it?.id, targetId) + } } else if (targetNum != null && targetNum in pager.indices) { // Start searching from the season number and choose direction from there val num = pager.getBlocking(targetNum)?.indexNumber