diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt index 55e37c73..f2199333 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedContent.kt @@ -42,7 +42,7 @@ abstract class RecommendedViewModel( ) : ViewModel() { abstract fun init() - abstract val rows: MutableStateFlow> + abstract val rows: MutableStateFlow> val loading = MutableLiveData(LoadingState.Loading) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedMovie.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedMovie.kt index 48388419..7eb676d0 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedMovie.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedMovie.kt @@ -57,13 +57,13 @@ class RecommendedMovieViewModel } override val rows = - MutableStateFlow>( + MutableStateFlow>( rowTitles .map { HomeRowLoadingState.Pending( context.getString(it), ) - }.toMutableList(), + }, ) override fun init() { @@ -166,6 +166,9 @@ class RecommendedMovieViewModel val result = try { pager.init() + if (pager.isNotEmpty()) { + pager.getBlocking(0) + } HomeRowLoadingState.Success(title, pager) } catch (ex: Exception) { Timber.e(ex, "Error fetching %s", title) @@ -182,7 +185,7 @@ class RecommendedMovieViewModel row: HomeRowLoadingState, ) { rows.update { current -> - current.apply { set(position, row) } + current.toMutableList().apply { set(position, row) } } } diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedTvShow.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedTvShow.kt index f504c614..cf5580eb 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedTvShow.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/components/RecommendedTvShow.kt @@ -59,13 +59,13 @@ class RecommendedTvShowViewModel } override val rows = - MutableStateFlow>( + MutableStateFlow>( rowTitles .map { HomeRowLoadingState.Pending( context.getString(it), ) - }.toMutableList(), + }, ) override fun init() { @@ -210,7 +210,7 @@ class RecommendedTvShowViewModel row: HomeRowLoadingState, ) { rows.update { current -> - current.apply { set(position, row) } + current.toMutableList().apply { set(position, row) } } } 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 e73f0cb6..cf1fb36f 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 @@ -360,9 +360,15 @@ fun HomePageContent( ), ).onFocusChanged { if (it.isFocused) { + val nonEmptyRowBefore = + homeRows + .subList(0, rowIndex) + .count { + it is HomeRowLoadingState.Success && it.items.isEmpty() + } onFocusPosition?.invoke( RowColumn( - rowIndex, + rowIndex - nonEmptyRowBefore, index, ), )