Support different rows

This commit is contained in:
Damontecres 2026-01-24 14:46:00 -05:00
parent cd71d5b00f
commit b2016bf976
No known key found for this signature in database
3 changed files with 185 additions and 85 deletions

View file

@ -12,9 +12,11 @@ import com.github.damontecres.wholphin.ui.AspectRatio
import com.github.damontecres.wholphin.ui.Cards import com.github.damontecres.wholphin.ui.Cards
import com.github.damontecres.wholphin.ui.components.ViewOptionImageType import com.github.damontecres.wholphin.ui.components.ViewOptionImageType
import com.github.damontecres.wholphin.ui.components.ViewOptions import com.github.damontecres.wholphin.ui.components.ViewOptions
import com.github.damontecres.wholphin.ui.data.SortAndDirection
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers import kotlinx.serialization.UseSerializers
import org.jellyfin.sdk.model.api.request.GetItemsRequest
import org.jellyfin.sdk.model.serializer.UUIDSerializer import org.jellyfin.sdk.model.serializer.UUIDSerializer
import java.util.UUID import java.util.UUID
@ -25,6 +27,9 @@ sealed class HomeRowConfig {
abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig
/**
* Continue watching media that the user has started but not finished
*/
@Serializable @Serializable
@SerialName("ContinueWatching") @SerialName("ContinueWatching")
data class ContinueWatching( data class ContinueWatching(
@ -34,6 +39,9 @@ sealed class HomeRowConfig {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
} }
/**
* Next up row for next episodes in a series the user has started
*/
@Serializable @Serializable
@SerialName("NextUp") @SerialName("NextUp")
data class NextUp( data class NextUp(
@ -43,6 +51,9 @@ sealed class HomeRowConfig {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
} }
/**
* Combined [ContinueWatching] and [NextUp]
*/
@Serializable @Serializable
@SerialName("ContinueWatchingCombined") @SerialName("ContinueWatchingCombined")
data class ContinueWatchingCombined( data class ContinueWatchingCombined(
@ -52,6 +63,9 @@ sealed class HomeRowConfig {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
} }
/**
* Media recently added to a library
*/
@Serializable @Serializable
@SerialName("RecentlyAdded") @SerialName("RecentlyAdded")
data class RecentlyAdded( data class RecentlyAdded(
@ -62,6 +76,9 @@ sealed class HomeRowConfig {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
} }
/**
* Media recently released (premiere date) in a library
*/
@Serializable @Serializable
@SerialName("RecentlyReleased") @SerialName("RecentlyReleased")
data class RecentlyReleased( data class RecentlyReleased(
@ -72,33 +89,65 @@ sealed class HomeRowConfig {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
} }
/**
* Row of a genres in a library
*/
@Serializable @Serializable
@SerialName("Genres") @SerialName("Genres")
data class Genres( data class Genres(
override val id: Int, override val id: Int,
val parentId: UUID, val parentId: UUID,
override val viewOptions: HomeRowViewOptions, override val viewOptions: HomeRowViewOptions =
HomeRowViewOptions(
heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(),
aspectRatio = AspectRatio.WIDE,
),
) : HomeRowConfig() { ) : HomeRowConfig() {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
} }
/**
* Fetch by parent ID such as a library, collection, or playlist with optional simple sorting
*/
@Serializable @Serializable
@SerialName("Collection") @SerialName("ByParent")
data class Collection( data class ByParent(
override val id: Int, override val id: Int,
val collectionId: UUID, val parentId: UUID,
val recursive: Boolean,
val sort: SortAndDirection? = null,
override val viewOptions: HomeRowViewOptions,
) : HomeRowConfig() {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
}
/**
* An arbitrary [GetItemsRequest] allowing to query for anything
*/
@Serializable
@SerialName("GetItems")
data class GetItems(
override val id: Int,
val name: String?,
val getItems: GetItemsRequest,
override val viewOptions: HomeRowViewOptions, override val viewOptions: HomeRowViewOptions,
) : HomeRowConfig() { ) : HomeRowConfig() {
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions) override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
} }
} }
@Serializable
data class HomeRowConfigDisplay( data class HomeRowConfigDisplay(
val title: String, val title: String,
val config: HomeRowConfig, val config: HomeRowConfig,
) )
@Serializable
@SerialName("HomePageConfiguration")
data class HomePageConfiguration(
val version: Int = 1,
val rows: List<HomeRowConfig>,
)
@Serializable @Serializable
data class HomeRowViewOptions( data class HomeRowViewOptions(
val heightDp: Int = Cards.HEIGHT_2X3_DP, val heightDp: Int = Cards.HEIGHT_2X3_DP,

View file

@ -36,8 +36,6 @@ import com.github.damontecres.wholphin.services.BackdropService
import com.github.damontecres.wholphin.services.ImageUrlService import com.github.damontecres.wholphin.services.ImageUrlService
import com.github.damontecres.wholphin.services.LatestNextUpService import com.github.damontecres.wholphin.services.LatestNextUpService
import com.github.damontecres.wholphin.services.UserPreferencesService import com.github.damontecres.wholphin.services.UserPreferencesService
import com.github.damontecres.wholphin.ui.AspectRatio
import com.github.damontecres.wholphin.ui.Cards
import com.github.damontecres.wholphin.ui.DefaultItemFields import com.github.damontecres.wholphin.ui.DefaultItemFields
import com.github.damontecres.wholphin.ui.SlimItemFields import com.github.damontecres.wholphin.ui.SlimItemFields
import com.github.damontecres.wholphin.ui.components.getGenreImageMap import com.github.damontecres.wholphin.ui.components.getGenreImageMap
@ -155,10 +153,20 @@ class HomePageSettingsViewModel
listOf( listOf(
HomeRowConfigDisplay( HomeRowConfigDisplay(
"Collection", "Collection",
HomeRowConfig.Collection( HomeRowConfig.ByParent(
100, id = 100,
"34ab6fd1f51c41bb014981f2e334f465".toUUID(), parentId = "34ab6fd1f51c41bb014981f2e334f465".toUUID(),
HomeRowViewOptions(), recursive = true,
viewOptions = HomeRowViewOptions(),
),
),
HomeRowConfigDisplay(
"Playlist",
HomeRowConfig.ByParent(
id = 101,
parentId = "f94be36e9836127a0bccfc7843b19e5b".toUUID(),
recursive = true,
viewOptions = HomeRowViewOptions(),
), ),
), ),
) )
@ -363,15 +371,59 @@ class HomePageSettingsViewModel
} }
} }
is HomeRowConfig.Collection -> { is HomeRowConfig.ByParent -> {
val collection by api.userLibraryApi.getItem(itemId = row.collectionId)
val request = val request =
GetItemsRequest( GetItemsRequest(
parentId = row.collectionId, userId = userDto.id,
parentId = row.parentId,
recursive = row.recursive,
sortBy = row.sort?.let { listOf(it.sort) },
sortOrder = row.sort?.let { listOf(it.direction) },
limit = limit, limit = limit,
fields = DefaultItemFields, fields = DefaultItemFields,
recursive = true,
) )
val name =
api.userLibraryApi
.getItem(itemId = row.parentId)
.content.name
GetItemsRequestHandler
.execute(api, request)
.content.items
.map { BaseItem(it, true) }
.let {
listOf(
Success(
name ?: context.getString(R.string.collection),
it,
row.viewOptions,
),
)
}
}
is HomeRowConfig.GetItems -> {
val request =
row.getItems.let {
if (it.limit == null) {
it.copy(
userId = userDto.id,
limit = limit,
)
} else {
it.copy(
userId = userDto.id,
)
}
}
val name =
if (row.name == null && request.parentId != null) {
// If a name was not provided, use the parent's name if available
api.userLibraryApi
.getItem(itemId = request.parentId!!)
.content.name
} else {
row.name
}
GetItemsRequestHandler GetItemsRequestHandler
.execute(api, request) .execute(api, request)
.content.items .content.items
@ -379,7 +431,7 @@ class HomePageSettingsViewModel
.let { .let {
listOf( listOf(
Success( Success(
collection.name ?: "", name ?: context.getString(R.string.collection),
it, it,
row.viewOptions, row.viewOptions,
), ),
@ -524,10 +576,6 @@ class HomePageSettingsViewModel
HomeRowConfig.Genres( HomeRowConfig.Genres(
id, id,
library.itemId, library.itemId,
HomeRowViewOptions(
heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(),
aspectRatio = AspectRatio.WIDE,
),
), ),
) )
} }

View file

@ -1,13 +1,17 @@
package com.github.damontecres.wholphin.test package com.github.damontecres.wholphin.test
import com.github.damontecres.wholphin.data.model.HomeRowConfig import com.github.damontecres.wholphin.data.model.HomeRowConfig
import com.github.damontecres.wholphin.data.model.HomeRowConfigDisplay
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
import com.github.damontecres.wholphin.preferences.PrefContentScale import com.github.damontecres.wholphin.preferences.PrefContentScale
import com.github.damontecres.wholphin.ui.AspectRatio import com.github.damontecres.wholphin.ui.AspectRatio
import com.github.damontecres.wholphin.ui.components.ViewOptionImageType import com.github.damontecres.wholphin.ui.components.ViewOptionImageType
import com.github.damontecres.wholphin.ui.data.SortAndDirection
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import org.jellyfin.sdk.model.UUID import org.jellyfin.sdk.model.UUID
import org.jellyfin.sdk.model.api.BaseItemKind
import org.jellyfin.sdk.model.api.ItemSortBy
import org.jellyfin.sdk.model.api.SortOrder
import org.jellyfin.sdk.model.api.request.GetItemsRequest
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -16,9 +20,6 @@ class TestHomeRowSamples {
companion object { companion object {
val SAMPLES = val SAMPLES =
listOf( listOf(
HomeRowConfigDisplay(
title = "Recently added",
config =
HomeRowConfig.RecentlyAdded( HomeRowConfig.RecentlyAdded(
id = 0, id = 0,
parentId = UUID.randomUUID(), parentId = UUID.randomUUID(),
@ -33,48 +34,48 @@ class TestHomeRowSamples {
useSeries = false, useSeries = false,
), ),
), ),
),
HomeRowConfigDisplay(
title = "Recently released",
config =
HomeRowConfig.RecentlyReleased( HomeRowConfig.RecentlyReleased(
id = 0, id = 0,
parentId = UUID.randomUUID(), parentId = UUID.randomUUID(),
viewOptions = HomeRowViewOptions(), viewOptions = HomeRowViewOptions(),
), ),
),
HomeRowConfigDisplay(
title = "Genres",
config =
HomeRowConfig.Genres( HomeRowConfig.Genres(
id = 0, id = 0,
parentId = UUID.randomUUID(), parentId = UUID.randomUUID(),
viewOptions = HomeRowViewOptions(), viewOptions = HomeRowViewOptions(),
), ),
),
HomeRowConfigDisplay(
title = "Continue watching",
config =
HomeRowConfig.ContinueWatching( HomeRowConfig.ContinueWatching(
id = 0, id = 0,
viewOptions = HomeRowViewOptions(), viewOptions = HomeRowViewOptions(),
), ),
),
HomeRowConfigDisplay(
title = "Next up",
config =
HomeRowConfig.NextUp( HomeRowConfig.NextUp(
id = 0, id = 0,
viewOptions = HomeRowViewOptions(), viewOptions = HomeRowViewOptions(),
), ),
),
HomeRowConfigDisplay(
title = "Combined",
config =
HomeRowConfig.ContinueWatchingCombined( HomeRowConfig.ContinueWatchingCombined(
id = 0, id = 0,
viewOptions = HomeRowViewOptions(), viewOptions = HomeRowViewOptions(),
), ),
HomeRowConfig.ByParent(
id = 0,
parentId = UUID.randomUUID(),
recursive = true,
sort = SortAndDirection(ItemSortBy.CRITIC_RATING, SortOrder.ASCENDING),
viewOptions = HomeRowViewOptions(),
),
HomeRowConfig.GetItems(
id = 0,
name = "Episodes by date created",
getItems =
GetItemsRequest(
parentId = UUID.randomUUID(),
recursive = true,
isFavorite = true,
includeItemTypes = listOf(BaseItemKind.EPISODE),
sortBy = listOf(ItemSortBy.DATE_CREATED),
sortOrder = listOf(SortOrder.DESCENDING),
),
viewOptions = HomeRowViewOptions(),
), ),
) )
} }
@ -84,13 +85,15 @@ class TestHomeRowSamples {
// This ensures there is a sample for each possible HomeRowConfig type // This ensures there is a sample for each possible HomeRowConfig type
val foundTypes = mutableSetOf<KClass<out HomeRowConfig>>() val foundTypes = mutableSetOf<KClass<out HomeRowConfig>>()
SAMPLES.forEach { SAMPLES.forEach {
when (it.config) { when (it) {
is HomeRowConfig.ContinueWatching -> foundTypes.add(HomeRowConfig.ContinueWatching::class) is HomeRowConfig.ContinueWatching -> foundTypes.add(it::class)
is HomeRowConfig.ContinueWatchingCombined -> foundTypes.add(HomeRowConfig.ContinueWatchingCombined::class) is HomeRowConfig.ContinueWatchingCombined -> foundTypes.add(it::class)
is HomeRowConfig.Genres -> foundTypes.add(HomeRowConfig.Genres::class) is HomeRowConfig.Genres -> foundTypes.add(it::class)
is HomeRowConfig.NextUp -> foundTypes.add(HomeRowConfig.NextUp::class) is HomeRowConfig.NextUp -> foundTypes.add(it::class)
is HomeRowConfig.RecentlyAdded -> foundTypes.add(HomeRowConfig.RecentlyAdded::class) is HomeRowConfig.RecentlyAdded -> foundTypes.add(it::class)
is HomeRowConfig.RecentlyReleased -> foundTypes.add(HomeRowConfig.RecentlyReleased::class) is HomeRowConfig.RecentlyReleased -> foundTypes.add(it::class)
is HomeRowConfig.ByParent -> foundTypes.add(it::class)
is HomeRowConfig.GetItems -> foundTypes.add(it::class)
} }
} }
Assert.assertEquals(HomeRowConfig::class.sealedSubclasses.size, foundTypes.size) Assert.assertEquals(HomeRowConfig::class.sealedSubclasses.size, foundTypes.size)
@ -107,6 +110,6 @@ class TestHomeRowSamples {
} }
val string = json.encodeToString(SAMPLES) val string = json.encodeToString(SAMPLES)
println(string) println(string)
json.decodeFromString<List<HomeRowConfigDisplay>>(string) json.decodeFromString<List<HomeRowConfig>>(string)
} }
} }