diff --git a/app/src/main/java/com/github/damontecres/wholphin/data/NavDrawerItemRepository.kt b/app/src/main/java/com/github/damontecres/wholphin/data/NavDrawerItemRepository.kt index 3200a281..2312c62c 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/data/NavDrawerItemRepository.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/data/NavDrawerItemRepository.kt @@ -10,6 +10,7 @@ import com.github.damontecres.wholphin.ui.nav.NavDrawerItem import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem import com.github.damontecres.wholphin.util.supportedCollectionTypes import dagger.hilt.android.qualifiers.ApplicationContext +import kotlinx.coroutines.flow.first import org.jellyfin.sdk.api.client.ApiClient import org.jellyfin.sdk.api.client.extensions.liveTvApi import org.jellyfin.sdk.api.client.extensions.userViewsApi @@ -49,7 +50,7 @@ class NavDrawerItemRepository } val builtins = - if (seerrServerRepository.active()) { + if (seerrServerRepository.active.first()) { listOf(NavDrawerItem.Favorites, NavDrawerItem.Discover) } else { listOf(NavDrawerItem.Favorites) diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt index 696c87d2..62ebba0d 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/nav/NavDrawer.kt @@ -78,6 +78,7 @@ import com.github.damontecres.wholphin.preferences.AppThemeColors import com.github.damontecres.wholphin.preferences.UserPreferences import com.github.damontecres.wholphin.services.BackdropService import com.github.damontecres.wholphin.services.NavigationManager +import com.github.damontecres.wholphin.services.SeerrServerRepository import com.github.damontecres.wholphin.services.SetupDestination import com.github.damontecres.wholphin.services.SetupNavigationManager import com.github.damontecres.wholphin.ui.FontAwesome @@ -94,6 +95,8 @@ import com.github.damontecres.wholphin.util.ExceptionHandler import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jellyfin.sdk.model.api.CollectionType @@ -109,6 +112,7 @@ class NavDrawerViewModel val navigationManager: NavigationManager, val setupNavigationManager: SetupNavigationManager, val backdropService: BackdropService, + private val seerrServerRepository: SeerrServerRepository, ) : ViewModel() { // private var all: List? = null val moreLibraries = MutableLiveData>(null) @@ -116,6 +120,13 @@ class NavDrawerViewModel val selectedIndex = MutableLiveData(-1) val showMore = MutableLiveData(false) + init { + seerrServerRepository.active + .onEach { + init() + }.launchIn(viewModelScope) + } + fun init() { viewModelScope.launchIO { val all = navDrawerItemRepository.getNavDrawerItems() @@ -128,11 +139,19 @@ class NavDrawerViewModel this@NavDrawerViewModel.libraries.value = libraries } val asDestinations = - (libraries + listOf(NavDrawerItem.More) + moreLibraries).map { + ( + libraries + + listOf( + NavDrawerItem.More, + NavDrawerItem.Discover, + ) + moreLibraries + ).map { if (it is ServerNavDrawerItem) { it.destination } else if (it is NavDrawerItem.Favorites) { Destination.Favorites + } else if (it is NavDrawerItem.Discover) { + Destination.Discover } else { null } @@ -155,7 +174,7 @@ class NavDrawerViewModel null } } -// Timber.v("Found $index => $key") + Timber.v("Found $index => $key") if (index != null) { selectedIndex.setValueOnMain(index) break