From 3428f2b208ee4f3639c33943aebdac93b5ea5ba4 Mon Sep 17 00:00:00 2001 From: Ray <154766448+damontecres@users.noreply.github.com> Date: Mon, 26 Jan 2026 16:34:50 -0500 Subject: [PATCH] Fixes possible crash if a home row is removed (#779) ## Description Fixes a possible crash if a row on the home page is removed. This could potentially happen if you only have one thing on the resume row and watch it by accessing it from the bottom row. --- .../com/github/damontecres/wholphin/ui/main/HomePage.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt index 33d40a4a..d866926d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/HomePage.kt @@ -62,6 +62,7 @@ import com.github.damontecres.wholphin.ui.detail.MoreDialogActions import com.github.damontecres.wholphin.ui.detail.PlaylistDialog import com.github.damontecres.wholphin.ui.detail.PlaylistLoadingState import com.github.damontecres.wholphin.ui.detail.buildMoreDialogItemsForHome +import com.github.damontecres.wholphin.ui.indexOfFirstOrNull import com.github.damontecres.wholphin.ui.isNotNullOrBlank import com.github.damontecres.wholphin.ui.nav.Destination import com.github.damontecres.wholphin.ui.playback.isPlayKeyUp @@ -203,15 +204,15 @@ fun HomePageContent( val rowFocusRequesters = remember(homeRows) { List(homeRows.size) { FocusRequester() } } var firstFocused by remember { mutableStateOf(false) } LaunchedEffect(homeRows) { - if (!firstFocused) { + if (!firstFocused && homeRows.isNotEmpty()) { if (position.row >= 0) { - rowFocusRequesters[position.row].tryRequestFocus() + val index = position.row.coerceIn(0, rowFocusRequesters.lastIndex) + rowFocusRequesters.getOrNull(index)?.tryRequestFocus() firstFocused = true } else { // Waiting for the first home row to load, then focus on it homeRows - .indexOfFirst { it is HomeRowLoadingState.Success && it.items.isNotEmpty() } - .takeIf { it >= 0 } + .indexOfFirstOrNull { it is HomeRowLoadingState.Success && it.items.isNotEmpty() } ?.let { rowFocusRequesters[it].tryRequestFocus() firstFocused = true