mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 08:01:20 +02:00
Support collections
This commit is contained in:
parent
2da34a8f56
commit
cd71d5b00f
2 changed files with 219 additions and 161 deletions
|
|
@ -81,6 +81,16 @@ sealed class HomeRowConfig {
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig() {
|
||||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@SerialName("Collection")
|
||||||
|
data class Collection(
|
||||||
|
override val id: Int,
|
||||||
|
val collectionId: UUID,
|
||||||
|
override val viewOptions: HomeRowViewOptions,
|
||||||
|
) : HomeRowConfig() {
|
||||||
|
override fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig = this.copy(viewOptions = viewOptions)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import com.github.damontecres.wholphin.data.model.BaseItem
|
||||||
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.HomeRowConfigDisplay
|
||||||
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
|
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
|
||||||
|
import com.github.damontecres.wholphin.preferences.HomePagePreferences
|
||||||
import com.github.damontecres.wholphin.services.BackdropService
|
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
|
||||||
|
|
@ -46,6 +47,7 @@ import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem
|
||||||
import com.github.damontecres.wholphin.util.GetGenresRequestHandler
|
import com.github.damontecres.wholphin.util.GetGenresRequestHandler
|
||||||
import com.github.damontecres.wholphin.util.GetItemsRequestHandler
|
import com.github.damontecres.wholphin.util.GetItemsRequestHandler
|
||||||
import com.github.damontecres.wholphin.util.HomeRowLoadingState
|
import com.github.damontecres.wholphin.util.HomeRowLoadingState
|
||||||
|
import com.github.damontecres.wholphin.util.HomeRowLoadingState.Success
|
||||||
import com.github.damontecres.wholphin.util.LoadingState
|
import com.github.damontecres.wholphin.util.LoadingState
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
|
@ -57,9 +59,11 @@ import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
||||||
import org.jellyfin.sdk.model.api.CollectionType
|
import org.jellyfin.sdk.model.api.CollectionType
|
||||||
import org.jellyfin.sdk.model.api.ItemSortBy
|
import org.jellyfin.sdk.model.api.ItemSortBy
|
||||||
import org.jellyfin.sdk.model.api.SortOrder
|
import org.jellyfin.sdk.model.api.SortOrder
|
||||||
|
import org.jellyfin.sdk.model.api.UserDto
|
||||||
import org.jellyfin.sdk.model.api.request.GetGenresRequest
|
import org.jellyfin.sdk.model.api.request.GetGenresRequest
|
||||||
import org.jellyfin.sdk.model.api.request.GetItemsRequest
|
import org.jellyfin.sdk.model.api.request.GetItemsRequest
|
||||||
import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest
|
import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest
|
||||||
|
import org.jellyfin.sdk.model.serializer.toUUID
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
@ -145,7 +149,19 @@ class HomePageSettingsViewModel
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val rowConfig = continueWatchingRows + includedIds
|
val rowConfig =
|
||||||
|
continueWatchingRows + includedIds +
|
||||||
|
// TODO remove after testing
|
||||||
|
listOf(
|
||||||
|
HomeRowConfigDisplay(
|
||||||
|
"Collection",
|
||||||
|
HomeRowConfig.Collection(
|
||||||
|
100,
|
||||||
|
"34ab6fd1f51c41bb014981f2e334f465".toUUID(),
|
||||||
|
HomeRowViewOptions(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(rows = rowConfig)
|
it.copy(rows = rowConfig)
|
||||||
}
|
}
|
||||||
|
|
@ -171,11 +187,27 @@ class HomePageSettingsViewModel
|
||||||
.map { it.config }
|
.map { it.config }
|
||||||
.map { row ->
|
.map { row ->
|
||||||
// TODO parallelize
|
// TODO parallelize
|
||||||
|
parseRow(prefs, userDto, row, limit)
|
||||||
|
}.flatten()
|
||||||
|
}
|
||||||
|
rows?.let { rows ->
|
||||||
|
_state.update {
|
||||||
|
it.copy(loading = LoadingState.Success, rowData = rows)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun parseRow(
|
||||||
|
prefs: HomePagePreferences,
|
||||||
|
userDto: UserDto,
|
||||||
|
row: HomeRowConfig,
|
||||||
|
limit: Int,
|
||||||
|
): List<HomeRowLoadingState> =
|
||||||
when (row) {
|
when (row) {
|
||||||
is HomeRowConfig.ContinueWatching -> {
|
is HomeRowConfig.ContinueWatching -> {
|
||||||
val resume = latestNextUpService.getResume(userDto.id, limit, true)
|
val resume = latestNextUpService.getResume(userDto.id, limit, true)
|
||||||
listOf(
|
listOf(
|
||||||
HomeRowLoadingState.Success(
|
Success(
|
||||||
title = context.getString(R.string.continue_watching),
|
title = context.getString(R.string.continue_watching),
|
||||||
items = resume,
|
items = resume,
|
||||||
viewOptions = row.viewOptions,
|
viewOptions = row.viewOptions,
|
||||||
|
|
@ -192,7 +224,7 @@ class HomePageSettingsViewModel
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
listOf(
|
listOf(
|
||||||
HomeRowLoadingState.Success(
|
Success(
|
||||||
title = context.getString(R.string.next_up),
|
title = context.getString(R.string.next_up),
|
||||||
items = nextUp,
|
items = nextUp,
|
||||||
viewOptions = row.viewOptions,
|
viewOptions = row.viewOptions,
|
||||||
|
|
@ -212,7 +244,7 @@ class HomePageSettingsViewModel
|
||||||
)
|
)
|
||||||
|
|
||||||
listOf(
|
listOf(
|
||||||
HomeRowLoadingState.Success(
|
Success(
|
||||||
title = context.getString(R.string.continue_watching),
|
title = context.getString(R.string.continue_watching),
|
||||||
items =
|
items =
|
||||||
latestNextUpService.buildCombined(
|
latestNextUpService.buildCombined(
|
||||||
|
|
@ -258,7 +290,7 @@ class HomePageSettingsViewModel
|
||||||
name?.let { context.getString(R.string.genres_in, it) }
|
name?.let { context.getString(R.string.genres_in, it) }
|
||||||
?: context.getString(R.string.genres)
|
?: context.getString(R.string.genres)
|
||||||
listOf(
|
listOf(
|
||||||
HomeRowLoadingState.Success(
|
Success(
|
||||||
title,
|
title,
|
||||||
genres,
|
genres,
|
||||||
viewOptions = row.viewOptions,
|
viewOptions = row.viewOptions,
|
||||||
|
|
@ -289,7 +321,7 @@ class HomePageSettingsViewModel
|
||||||
.content
|
.content
|
||||||
.map { BaseItem.from(it, api, true) }
|
.map { BaseItem.from(it, api, true) }
|
||||||
.let {
|
.let {
|
||||||
HomeRowLoadingState.Success(
|
Success(
|
||||||
title,
|
title,
|
||||||
it,
|
it,
|
||||||
row.viewOptions,
|
row.viewOptions,
|
||||||
|
|
@ -322,7 +354,7 @@ class HomePageSettingsViewModel
|
||||||
.map { BaseItem.from(it, api, true) }
|
.map { BaseItem.from(it, api, true) }
|
||||||
.let {
|
.let {
|
||||||
listOf(
|
listOf(
|
||||||
HomeRowLoadingState.Success(
|
Success(
|
||||||
title,
|
title,
|
||||||
it,
|
it,
|
||||||
row.viewOptions,
|
row.viewOptions,
|
||||||
|
|
@ -330,12 +362,28 @@ class HomePageSettingsViewModel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}.flatten()
|
is HomeRowConfig.Collection -> {
|
||||||
}
|
val collection by api.userLibraryApi.getItem(itemId = row.collectionId)
|
||||||
rows?.let { rows ->
|
val request =
|
||||||
_state.update {
|
GetItemsRequest(
|
||||||
it.copy(loading = LoadingState.Success, rowData = rows)
|
parentId = row.collectionId,
|
||||||
|
limit = limit,
|
||||||
|
fields = DefaultItemFields,
|
||||||
|
recursive = true,
|
||||||
|
)
|
||||||
|
GetItemsRequestHandler
|
||||||
|
.execute(api, request)
|
||||||
|
.content.items
|
||||||
|
.map { BaseItem.from(it, api, true) }
|
||||||
|
.let {
|
||||||
|
listOf(
|
||||||
|
Success(
|
||||||
|
collection.name ?: "",
|
||||||
|
it,
|
||||||
|
row.viewOptions,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue