From 0f9ffcacb9629dc383b07ef2e6adb6b3927918a8 Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Sat, 6 Jan 2024 13:36:26 +0100 Subject: [PATCH] Defer home initialization until user info is available (cherry picked from commit d72148212792de4013d868dcd837569a22aa5b8a) --- .../jellyfin/androidtv/ui/home/HomeRowsFragment.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/home/HomeRowsFragment.kt b/app/src/main/java/org/jellyfin/androidtv/ui/home/HomeRowsFragment.kt index b316728948..e33ad7f39d 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/home/HomeRowsFragment.kt +++ b/app/src/main/java/org/jellyfin/androidtv/ui/home/HomeRowsFragment.kt @@ -17,11 +17,14 @@ import androidx.lifecycle.repeatOnLifecycle import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlinx.coroutines.withTimeout import org.jellyfin.androidtv.auth.repository.UserRepository import org.jellyfin.androidtv.constant.CustomMessage import org.jellyfin.androidtv.constant.HomeSectionType @@ -88,15 +91,17 @@ class HomeRowsFragment : RowsSupportFragment(), AudioEventListener, View.OnKeyLi adapter = MutableObjectAdapter(PositionableListRowPresenter()) - val currentUser = userRepository.currentUser.value - lifecycleScope.launch(Dispatchers.IO) { + val currentUser = withTimeout(30.seconds) { + userRepository.currentUser.filterNotNull().first() + } + // Start out with default sections val homesections = userSettingPreferences.homesections var includeLiveTvRows = false // Check for live TV support - if (homesections.contains(HomeSectionType.LIVE_TV) && currentUser?.policy?.enableLiveTvAccess == true) { + if (homesections.contains(HomeSectionType.LIVE_TV) && currentUser.policy?.enableLiveTvAccess == true) { // This is kind of ugly, but it mirrors how web handles the live TV rows on the home screen // If we can retrieve one live TV recommendation, then we should display the rows val recommendedPrograms by api.liveTvApi.getRecommendedPrograms(