mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Switch ids to ints
This commit is contained in:
parent
a90e6bc7b0
commit
d809cc2be4
3 changed files with 88 additions and 38 deletions
|
|
@ -12,6 +12,7 @@ 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 kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.UseSerializers
|
import kotlinx.serialization.UseSerializers
|
||||||
import org.jellyfin.sdk.model.serializer.UUIDSerializer
|
import org.jellyfin.sdk.model.serializer.UUIDSerializer
|
||||||
|
|
@ -19,38 +20,42 @@ import java.util.UUID
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
sealed class HomeRowConfig {
|
sealed class HomeRowConfig {
|
||||||
abstract val id: UUID
|
abstract val id: Int
|
||||||
abstract val viewOptions: HomeRowViewOptions
|
abstract val viewOptions: HomeRowViewOptions
|
||||||
|
|
||||||
abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig
|
abstract fun updateViewOptions(viewOptions: HomeRowViewOptions): HomeRowConfig
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@SerialName("ContinueWatching")
|
||||||
data class ContinueWatching(
|
data class ContinueWatching(
|
||||||
override val id: UUID,
|
override val id: Int,
|
||||||
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
|
@Serializable
|
||||||
|
@SerialName("NextUp")
|
||||||
data class NextUp(
|
data class NextUp(
|
||||||
override val id: UUID,
|
override val id: Int,
|
||||||
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
|
@Serializable
|
||||||
|
@SerialName("ContinueWatchingCombined")
|
||||||
data class ContinueWatchingCombined(
|
data class ContinueWatchingCombined(
|
||||||
override val id: UUID,
|
override val id: Int,
|
||||||
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
|
@Serializable
|
||||||
|
@SerialName("RecentlyAdded")
|
||||||
data class RecentlyAdded(
|
data class RecentlyAdded(
|
||||||
override val id: UUID,
|
override val id: Int,
|
||||||
val parentId: UUID,
|
val parentId: UUID,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig() {
|
||||||
|
|
@ -58,8 +63,9 @@ sealed class HomeRowConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@SerialName("RecentlyReleased")
|
||||||
data class RecentlyReleased(
|
data class RecentlyReleased(
|
||||||
override val id: UUID,
|
override val id: Int,
|
||||||
val parentId: UUID,
|
val parentId: UUID,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig() {
|
||||||
|
|
@ -67,8 +73,9 @@ sealed class HomeRowConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@SerialName("Genres")
|
||||||
data class Genres(
|
data class Genres(
|
||||||
override val id: UUID,
|
override val id: Int,
|
||||||
val parentId: UUID,
|
val parentId: UUID,
|
||||||
override val viewOptions: HomeRowViewOptions,
|
override val viewOptions: HomeRowViewOptions,
|
||||||
) : HomeRowConfig() {
|
) : HomeRowConfig() {
|
||||||
|
|
|
||||||
|
|
@ -37,13 +37,14 @@ 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.AspectRatio
|
||||||
import com.github.damontecres.wholphin.ui.Cards
|
import com.github.damontecres.wholphin.ui.Cards
|
||||||
|
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
|
||||||
import com.github.damontecres.wholphin.ui.launchIO
|
import com.github.damontecres.wholphin.ui.launchIO
|
||||||
import com.github.damontecres.wholphin.ui.main.HomePageContent
|
import com.github.damontecres.wholphin.ui.main.HomePageContent
|
||||||
import com.github.damontecres.wholphin.ui.main.LatestData
|
|
||||||
import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem
|
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.HomeRowLoadingState
|
import com.github.damontecres.wholphin.util.HomeRowLoadingState
|
||||||
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
|
||||||
|
|
@ -51,10 +52,16 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import org.jellyfin.sdk.api.client.ApiClient
|
import org.jellyfin.sdk.api.client.ApiClient
|
||||||
|
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.SortOrder
|
||||||
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.GetLatestMediaRequest
|
import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest
|
||||||
|
import timber.log.Timber
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
@ -96,7 +103,7 @@ class HomePageSettingsViewModel
|
||||||
navDrawerItemRepository
|
navDrawerItemRepository
|
||||||
.getFilteredNavDrawerItems(navDrawerItems)
|
.getFilteredNavDrawerItems(navDrawerItems)
|
||||||
.filter { it is ServerNavDrawerItem }
|
.filter { it is ServerNavDrawerItem }
|
||||||
.map {
|
.mapIndexed { index, it ->
|
||||||
val id = (it as ServerNavDrawerItem).itemId
|
val id = (it as ServerNavDrawerItem).itemId
|
||||||
val name = libraries.firstOrNull { it.itemId == id }?.name
|
val name = libraries.firstOrNull { it.itemId == id }?.name
|
||||||
val title =
|
val title =
|
||||||
|
|
@ -105,7 +112,7 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
title,
|
title,
|
||||||
HomeRowConfig.RecentlyAdded(
|
HomeRowConfig.RecentlyAdded(
|
||||||
UUID.randomUUID(),
|
index,
|
||||||
id,
|
id,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
|
|
@ -117,7 +124,7 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
context.getString(R.string.combine_continue_next),
|
context.getString(R.string.combine_continue_next),
|
||||||
HomeRowConfig.ContinueWatchingCombined(
|
HomeRowConfig.ContinueWatchingCombined(
|
||||||
UUID.randomUUID(),
|
includedIds.size + 1,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -127,14 +134,14 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
context.getString(R.string.continue_watching),
|
context.getString(R.string.continue_watching),
|
||||||
HomeRowConfig.ContinueWatching(
|
HomeRowConfig.ContinueWatching(
|
||||||
UUID.randomUUID(),
|
includedIds.size + 1,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
context.getString(R.string.next_up),
|
context.getString(R.string.next_up),
|
||||||
HomeRowConfig.NextUp(
|
HomeRowConfig.NextUp(
|
||||||
UUID.randomUUID(),
|
includedIds.size + 2,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -144,6 +151,8 @@ class HomePageSettingsViewModel
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(rows = rowConfig)
|
it.copy(rows = rowConfig)
|
||||||
}
|
}
|
||||||
|
val json = Json.encodeToString(rowConfig.map { it.config })
|
||||||
|
Timber.v("json=$json")
|
||||||
|
|
||||||
fetchRowData()
|
fetchRowData()
|
||||||
}
|
}
|
||||||
|
|
@ -276,21 +285,52 @@ class HomePageSettingsViewModel
|
||||||
limit = limit,
|
limit = limit,
|
||||||
isPlayed = null, // Server will handle user's preference
|
isPlayed = null, // Server will handle user's preference
|
||||||
)
|
)
|
||||||
latestNextUpService
|
val latest =
|
||||||
.loadLatest(listOf(LatestData(title, request)))
|
api.userLibraryApi
|
||||||
.let {
|
.getLatestMedia(request)
|
||||||
it.map {
|
.content
|
||||||
if (it is HomeRowLoadingState.Success) {
|
.map { BaseItem.from(it, api, true) }
|
||||||
it.copy(viewOptions = row.viewOptions)
|
.let {
|
||||||
} else {
|
HomeRowLoadingState.Success(
|
||||||
it
|
title,
|
||||||
}
|
it,
|
||||||
|
row.viewOptions,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
listOf(latest)
|
||||||
}
|
}
|
||||||
|
|
||||||
is HomeRowConfig.RecentlyReleased -> {
|
is HomeRowConfig.RecentlyReleased -> {
|
||||||
TODO()
|
val name =
|
||||||
|
_state.value.libraries
|
||||||
|
.firstOrNull { it.itemId == row.parentId }
|
||||||
|
?.name
|
||||||
|
val title =
|
||||||
|
name?.let {
|
||||||
|
context.getString(R.string.recently_released_in, it)
|
||||||
|
} ?: context.getString(R.string.recently_released)
|
||||||
|
val request =
|
||||||
|
GetItemsRequest(
|
||||||
|
parentId = row.parentId,
|
||||||
|
limit = limit,
|
||||||
|
sortBy = listOf(ItemSortBy.PREMIERE_DATE),
|
||||||
|
sortOrder = listOf(SortOrder.DESCENDING),
|
||||||
|
fields = DefaultItemFields,
|
||||||
|
recursive = true,
|
||||||
|
)
|
||||||
|
GetItemsRequestHandler
|
||||||
|
.execute(api, request)
|
||||||
|
.content.items
|
||||||
|
.map { BaseItem.from(it, api, true) }
|
||||||
|
.let {
|
||||||
|
listOf(
|
||||||
|
HomeRowLoadingState.Success(
|
||||||
|
title,
|
||||||
|
it,
|
||||||
|
row.viewOptions,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.flatten()
|
}.flatten()
|
||||||
|
|
@ -349,13 +389,14 @@ class HomePageSettingsViewModel
|
||||||
|
|
||||||
fun addRow(type: MetaRowType) {
|
fun addRow(type: MetaRowType) {
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
|
val id = state.value.rows.size
|
||||||
val newRow =
|
val newRow =
|
||||||
when (type) {
|
when (type) {
|
||||||
MetaRowType.CONTINUE_WATCHING -> {
|
MetaRowType.CONTINUE_WATCHING -> {
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
context.getString(R.string.continue_watching),
|
context.getString(R.string.continue_watching),
|
||||||
HomeRowConfig.ContinueWatching(
|
HomeRowConfig.ContinueWatching(
|
||||||
UUID.randomUUID(),
|
id,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -365,7 +406,7 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
context.getString(R.string.continue_watching),
|
context.getString(R.string.continue_watching),
|
||||||
HomeRowConfig.NextUp(
|
HomeRowConfig.NextUp(
|
||||||
UUID.randomUUID(),
|
id,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -375,7 +416,7 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
context.getString(R.string.combine_continue_next),
|
context.getString(R.string.combine_continue_next),
|
||||||
HomeRowConfig.ContinueWatchingCombined(
|
HomeRowConfig.ContinueWatchingCombined(
|
||||||
UUID.randomUUID(),
|
id,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
@ -396,6 +437,7 @@ class HomePageSettingsViewModel
|
||||||
rowType: LibraryRowType,
|
rowType: LibraryRowType,
|
||||||
) {
|
) {
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
|
val id = state.value.rows.size
|
||||||
val newRow =
|
val newRow =
|
||||||
when (rowType) {
|
when (rowType) {
|
||||||
LibraryRowType.RECENTLY_ADDED -> {
|
LibraryRowType.RECENTLY_ADDED -> {
|
||||||
|
|
@ -404,7 +446,7 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
title,
|
title,
|
||||||
HomeRowConfig.RecentlyAdded(
|
HomeRowConfig.RecentlyAdded(
|
||||||
UUID.randomUUID(),
|
id,
|
||||||
library.itemId,
|
library.itemId,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
|
|
@ -422,7 +464,7 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
title,
|
title,
|
||||||
HomeRowConfig.RecentlyReleased(
|
HomeRowConfig.RecentlyReleased(
|
||||||
UUID.randomUUID(),
|
id,
|
||||||
library.itemId,
|
library.itemId,
|
||||||
HomeRowViewOptions(),
|
HomeRowViewOptions(),
|
||||||
),
|
),
|
||||||
|
|
@ -434,7 +476,7 @@ class HomePageSettingsViewModel
|
||||||
HomeRowConfigDisplay(
|
HomeRowConfigDisplay(
|
||||||
title,
|
title,
|
||||||
HomeRowConfig.Genres(
|
HomeRowConfig.Genres(
|
||||||
UUID.randomUUID(),
|
id,
|
||||||
library.itemId,
|
library.itemId,
|
||||||
HomeRowViewOptions(
|
HomeRowViewOptions(
|
||||||
heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(),
|
heightDp = (Cards.HEIGHT_2X3_DP * .75f).toInt(),
|
||||||
|
|
@ -455,17 +497,17 @@ class HomePageSettingsViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateViewOptions(
|
fun updateViewOptions(
|
||||||
rowId: UUID,
|
rowId: Int,
|
||||||
viewOptions: HomeRowViewOptions,
|
viewOptions: HomeRowViewOptions,
|
||||||
) {
|
) {
|
||||||
viewModelScope.launchIO {
|
viewModelScope.launchIO {
|
||||||
_state.update {
|
_state.update {
|
||||||
val index = state.value.rows.indexOfFirst { it.config.id == rowId }
|
val index = it.rows.indexOfFirst { it.config.id == rowId }
|
||||||
val newRowConfig =
|
val newRowConfig =
|
||||||
state.value.rows[index]
|
it.rows[index]
|
||||||
.config
|
.config
|
||||||
.updateViewOptions(viewOptions)
|
.updateViewOptions(viewOptions)
|
||||||
val newRow = state.value.rows[index].copy(config = newRowConfig)
|
val newRow = it.rows[index].copy(config = newRowConfig)
|
||||||
it.copy(
|
it.copy(
|
||||||
rows =
|
rows =
|
||||||
it.rows.toMutableList().apply {
|
it.rows.toMutableList().apply {
|
||||||
|
|
@ -580,7 +622,10 @@ fun HomePageSettings(
|
||||||
HomePageLibraryList(
|
HomePageLibraryList(
|
||||||
libraries = state.libraries,
|
libraries = state.libraries,
|
||||||
onClick = { destination = HomePageSettingsDestination.ChooseRowType(it) },
|
onClick = { destination = HomePageSettingsDestination.ChooseRowType(it) },
|
||||||
onClickMeta = { viewModel.addRow(it) },
|
onClickMeta = {
|
||||||
|
viewModel.addRow(it)
|
||||||
|
destination = HomePageSettingsDestination.RowList
|
||||||
|
},
|
||||||
modifier = destModifier,
|
modifier = destModifier,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.github.damontecres.wholphin.ui.main.settings
|
package com.github.damontecres.wholphin.ui.main.settings
|
||||||
|
|
||||||
import java.util.UUID
|
|
||||||
|
|
||||||
sealed interface HomePageSettingsDestination {
|
sealed interface HomePageSettingsDestination {
|
||||||
data object RowList : HomePageSettingsDestination
|
data object RowList : HomePageSettingsDestination
|
||||||
|
|
||||||
|
|
@ -12,6 +10,6 @@ sealed interface HomePageSettingsDestination {
|
||||||
) : HomePageSettingsDestination
|
) : HomePageSettingsDestination
|
||||||
|
|
||||||
data class RowSettings(
|
data class RowSettings(
|
||||||
val rowId: UUID,
|
val rowId: Int,
|
||||||
) : HomePageSettingsDestination
|
) : HomePageSettingsDestination
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue