Skip to content

Commit

Permalink
Defer home initialization until user info is available
Browse files Browse the repository at this point in the history
(cherry picked from commit d721482)
  • Loading branch information
nielsvanvelzen committed Jan 6, 2024
1 parent aa7c45d commit 0f9ffca
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,15 +91,17 @@ class HomeRowsFragment : RowsSupportFragment(), AudioEventListener, View.OnKeyLi

adapter = MutableObjectAdapter<Row>(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(
Expand Down

0 comments on commit 0f9ffca

Please sign in to comment.