Integrate nav drawer settings for default home page (#888)

## Description
Customizing the home page (#803) and nav drawer (#886) were developed
independently, so this PR just cleans up somethings so that those two
changes work together.

This PR restores the default home page when there is no customization to
be the same as before: continue watching/next up row(s) followed by the
order of the nav drawer libraries' recently added rows.

Finally gets rid of `NavDrawerIteRepository` and related functions which
all had weird, hard to follow code.

### Related issues
Related to #803 & #886

### Testing
Emulator testing

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Ray 2026-02-12 21:19:33 -05:00 committed by GitHub
parent 17b0eef5c5
commit 7fcd66f407
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 58 additions and 153 deletions

View file

@ -2,7 +2,7 @@ package com.github.damontecres.wholphin.services
import android.content.Context
import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
import com.github.damontecres.wholphin.data.ServerRepository
import com.github.damontecres.wholphin.data.model.BaseItem
import com.github.damontecres.wholphin.data.model.HomePageSettings
import com.github.damontecres.wholphin.data.model.HomeRowConfig
@ -12,8 +12,8 @@ import com.github.damontecres.wholphin.preferences.HomePagePreferences
import com.github.damontecres.wholphin.ui.DefaultItemFields
import com.github.damontecres.wholphin.ui.SlimItemFields
import com.github.damontecres.wholphin.ui.components.getGenreImageMap
import com.github.damontecres.wholphin.ui.isNotNullOrBlank
import com.github.damontecres.wholphin.ui.main.settings.Library
import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem
import com.github.damontecres.wholphin.ui.toServerString
import com.github.damontecres.wholphin.util.GetGenresRequestHandler
import com.github.damontecres.wholphin.util.GetItemsRequestHandler
@ -64,8 +64,9 @@ class HomeSettingsService
constructor(
@param:ApplicationContext private val context: Context,
private val api: ApiClient,
private val serverRepository: ServerRepository,
private val userPreferencesService: UserPreferencesService,
private val navDrawerItemRepository: NavDrawerItemRepository,
private val navDrawerService: NavDrawerService,
private val latestNextUpService: LatestNextUpService,
private val imageUrlService: ImageUrlService,
private val suggestionService: SuggestionService,
@ -233,7 +234,7 @@ class HomeSettingsService
}
HomePageResolvedSettings(resolvedRows)
} else {
createDefault()
createDefault(userId)
}
currentSettings.update { resolvedSettings }
@ -251,25 +252,24 @@ class HomeSettingsService
/**
* Create a default [HomePageResolvedSettings] using the available libraries
*/
suspend fun createDefault(): HomePageResolvedSettings {
suspend fun createDefault(userId: UUID): HomePageResolvedSettings {
Timber.v("Creating default settings")
val navDrawerItems = navDrawerItemRepository.getNavDrawerItems()
val user = serverRepository.currentUser.value?.takeIf { it.id == userId }
val libraries =
navDrawerItems
.filter { it is ServerNavDrawerItem }
.map {
it as ServerNavDrawerItem
Library(it.itemId, it.name, it.type)
}
if (user != null) {
navDrawerService.getFilteredUserLibraries(user)
} else {
navDrawerService.getAllUserLibraries(userId)
}
val prefs =
userPreferencesService.getCurrent().appPreferences.homePagePreferences
val includedIds =
navDrawerItemRepository
.getFilteredNavDrawerItems(navDrawerItems)
.filter { it is ServerNavDrawerItem }
libraries
.mapIndexed { index, it ->
val parentId = (it as ServerNavDrawerItem).itemId
val name = libraries.firstOrNull { it.itemId == parentId }?.name
val parentId = it.itemId
val name = it.name.takeIf { it.isNotNullOrBlank() }
val title =
name?.let { context.getString(R.string.recently_added_in, it) }
?: context.getString(R.string.recently_added)

View file

@ -8,6 +8,7 @@ import com.github.damontecres.wholphin.data.model.BaseItem
import com.github.damontecres.wholphin.data.model.JellyfinUser
import com.github.damontecres.wholphin.data.model.NavPinType
import com.github.damontecres.wholphin.services.hilt.DefaultCoroutineScope
import com.github.damontecres.wholphin.ui.main.settings.Library
import com.github.damontecres.wholphin.ui.nav.Destination
import com.github.damontecres.wholphin.ui.nav.NavDrawerItem
import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem
@ -26,6 +27,7 @@ import org.jellyfin.sdk.api.client.extensions.userViewsApi
import org.jellyfin.sdk.model.api.CollectionType
import org.jellyfin.sdk.model.api.UserDto
import timber.log.Timber
import java.util.UUID
import javax.inject.Inject
import javax.inject.Singleton
@ -66,6 +68,29 @@ class NavDrawerService
}.launchIn(coroutineScope)
}
suspend fun getAllUserLibraries(userId: UUID): List<Library> {
val userViews =
api.userViewsApi
.getUserViews(userId = userId)
.content.items
val libraries =
userViews
.filter { it.collectionType in supportedCollectionTypes }
.map { Library(it.id, it.name ?: "", it.collectionType ?: CollectionType.UNKNOWN) }
return libraries
}
suspend fun getFilteredUserLibraries(user: JellyfinUser): List<Library> {
val pins =
serverPreferencesDao
.getNavDrawerPinnedItems(user)
.associateBy { it.itemId }
val libraries =
getAllUserLibraries(user.id)
.filterNot { pins[ServerNavDrawerItem.getId(it.itemId)]?.type == NavPinType.UNPINNED }
return libraries
}
suspend fun updateNavDrawer(
user: JellyfinUser,
userDto: UserDto,