Skip to content

Commit

Permalink
Centralize requested item fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Dec 28, 2024
1 parent 7e6f88e commit 832ab68
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 334 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jellyfin.androidtv.data.repository

import org.jellyfin.sdk.model.api.ItemFields

object ItemRepository {
val itemFields = setOf(
ItemFields.CAN_DELETE,
ItemFields.CHANNEL_INFO,
ItemFields.CHAPTERS,
ItemFields.CHILD_COUNT,
ItemFields.CUMULATIVE_RUN_TIME_TICKS,
ItemFields.DATE_CREATED,
ItemFields.DISPLAY_PREFERENCES_ID,
ItemFields.GENRES,
ItemFields.ITEM_COUNTS,
ItemFields.MEDIA_SOURCE_COUNT,
ItemFields.MEDIA_SOURCES,
ItemFields.MEDIA_STREAMS,
ItemFields.OVERVIEW,
ItemFields.PATH,
ItemFields.PRIMARY_IMAGE_ASPECT_RATIO,
ItemFields.SERIES_PRIMARY_IMAGE,
ItemFields.TAGLINES,
ItemFields.TRICKPLAY,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.withContext
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.data.repository.ItemRepository
import org.jellyfin.androidtv.data.repository.UserViewsRepository
import org.jellyfin.androidtv.integration.provider.ImageProvider
import org.jellyfin.androidtv.preference.UserPreferences
Expand All @@ -41,7 +42,6 @@ import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.BaseItemKind
import org.jellyfin.sdk.model.api.ImageFormat
import org.jellyfin.sdk.model.api.ImageType
import org.jellyfin.sdk.model.api.ItemFields
import org.jellyfin.sdk.model.api.MediaType
import org.jellyfin.sdk.model.extensions.ticks
import org.koin.core.component.KoinComponent
Expand Down Expand Up @@ -270,7 +270,7 @@ class LeanbackChannelWorker(
withContext(Dispatchers.IO) {
val resume = async {
api.itemsApi.getResumeItems(
fields = listOf(ItemFields.DATE_CREATED),
fields = ItemRepository.itemFields,
imageTypeLimit = 1,
limit = 10,
mediaTypes = listOf(MediaType.VIDEO),
Expand All @@ -284,7 +284,7 @@ class LeanbackChannelWorker(
imageTypeLimit = 1,
limit = 10,
enableResumable = false,
fields = listOf(ItemFields.DATE_CREATED),
fields = ItemRepository.itemFields,
).content.items
}

Expand All @@ -296,9 +296,7 @@ class LeanbackChannelWorker(
withContext(Dispatchers.IO) {
val latestEpisodes = async {
api.userLibraryApi.getLatestMedia(
fields = listOf(
ItemFields.OVERVIEW,
),
fields = ItemRepository.itemFields,
limit = 50,
includeItemTypes = listOf(BaseItemKind.EPISODE),
isPlayed = false
Expand All @@ -307,9 +305,7 @@ class LeanbackChannelWorker(

val latestMovies = async {
api.userLibraryApi.getLatestMedia(
fields = listOf(
ItemFields.OVERVIEW,
),
fields = ItemRepository.itemFields,
limit = 50,
includeItemTypes = listOf(BaseItemKind.MOVIE),
isPlayed = false
Expand All @@ -318,9 +314,7 @@ class LeanbackChannelWorker(

val latestMedia = async {
api.userLibraryApi.getLatestMedia(
fields = listOf(
ItemFields.OVERVIEW,
),
fields = ItemRepository.itemFields,
limit = 50,
includeItemTypes = listOf(BaseItemKind.MOVIE, BaseItemKind.SERIES),
isPlayed = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.provider.BaseColumns
import kotlinx.coroutines.runBlocking
import org.jellyfin.androidtv.BuildConfig
import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.data.repository.ItemRepository
import org.jellyfin.androidtv.integration.provider.ImageProvider
import org.jellyfin.androidtv.util.ImageHelper
import org.jellyfin.androidtv.util.sdk.isUsable
Expand All @@ -21,7 +22,6 @@ import org.jellyfin.sdk.api.client.extensions.imageApi
import org.jellyfin.sdk.api.client.extensions.itemsApi
import org.jellyfin.sdk.model.api.BaseItemDtoQueryResult
import org.jellyfin.sdk.model.api.ImageType
import org.jellyfin.sdk.model.api.ItemFields
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import timber.log.Timber
Expand Down Expand Up @@ -75,7 +75,7 @@ class MediaContentProvider : ContentProvider(), KoinComponent {
searchTerm = query,
recursive = true,
limit = limit,
fields = setOf(ItemFields.TAGLINES)
fields = ItemRepository.itemFields
)

items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.jellyfin.androidtv.ui
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
import org.jellyfin.androidtv.data.repository.ItemRepository
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.extensions.itemsApi
import org.jellyfin.sdk.model.api.ItemFields
import org.koin.java.KoinJavaComponent

fun ItemListView.refresh() {
Expand All @@ -14,14 +14,7 @@ fun ItemListView.refresh() {
findViewTreeLifecycleOwner()?.lifecycleScope?.launch {
val response by api.itemsApi.getItems(
ids = mItemIds,
fields = setOf(
ItemFields.PRIMARY_IMAGE_ASPECT_RATIO,
ItemFields.OVERVIEW,
ItemFields.ITEM_COUNTS,
ItemFields.DISPLAY_PREFERENCES_ID,
ItemFields.CHILD_COUNT,
ItemFields.MEDIA_SOURCES,
)
fields = ItemRepository.itemFields
)

response.items?.forEachIndexed { index, item ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package org.jellyfin.androidtv.ui.browsing

import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
import org.jellyfin.androidtv.data.repository.ItemRepository
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.extensions.liveTvApi
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.BaseItemDtoQueryResult
import org.jellyfin.sdk.model.api.BaseItemKind
import org.jellyfin.sdk.model.api.ItemFields
import org.jellyfin.sdk.model.api.LocationType
import org.jellyfin.sdk.model.api.MediaType
import org.jellyfin.sdk.model.api.TimerInfoDto
Expand All @@ -24,11 +24,7 @@ fun EnhancedBrowseFragment.getLiveTvRecordingsAndTimers(
lifecycleScope.launch {
runCatching {
val recordings by api.liveTvApi.getRecordings(
fields = setOf(
ItemFields.OVERVIEW,
ItemFields.PRIMARY_IMAGE_ASPECT_RATIO,
ItemFields.CHILD_COUNT,
),
fields = ItemRepository.itemFields,
enableImages = true,
limit = 40,
)
Expand Down
Loading

0 comments on commit 832ab68

Please sign in to comment.