mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Parse by row
This commit is contained in:
parent
668a3960f3
commit
f58b371698
3 changed files with 67 additions and 17 deletions
|
|
@ -34,7 +34,7 @@ sealed interface HomeRowConfig {
|
|||
@SerialName("ContinueWatching")
|
||||
data class ContinueWatching(
|
||||
override val id: Int,
|
||||
override val viewOptions: HomeRowViewOptions,
|
||||
override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(),
|
||||
) : HomeRowConfig {
|
||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatching = this.copy(viewOptions = viewOptions)
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ sealed interface HomeRowConfig {
|
|||
@SerialName("NextUp")
|
||||
data class NextUp(
|
||||
override val id: Int,
|
||||
override val viewOptions: HomeRowViewOptions,
|
||||
override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(),
|
||||
) : HomeRowConfig {
|
||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): NextUp = this.copy(viewOptions = viewOptions)
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ sealed interface HomeRowConfig {
|
|||
@SerialName("ContinueWatchingCombined")
|
||||
data class ContinueWatchingCombined(
|
||||
override val id: Int,
|
||||
override val viewOptions: HomeRowViewOptions,
|
||||
override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(),
|
||||
) : HomeRowConfig {
|
||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): ContinueWatchingCombined = this.copy(viewOptions = viewOptions)
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ sealed interface HomeRowConfig {
|
|||
data class RecentlyAdded(
|
||||
override val id: Int,
|
||||
val parentId: UUID,
|
||||
override val viewOptions: HomeRowViewOptions,
|
||||
override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(),
|
||||
) : HomeRowConfig {
|
||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyAdded = this.copy(viewOptions = viewOptions)
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ sealed interface HomeRowConfig {
|
|||
data class RecentlyReleased(
|
||||
override val id: Int,
|
||||
val parentId: UUID,
|
||||
override val viewOptions: HomeRowViewOptions,
|
||||
override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(),
|
||||
) : HomeRowConfig {
|
||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): RecentlyReleased = this.copy(viewOptions = viewOptions)
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ sealed interface HomeRowConfig {
|
|||
val parentId: UUID,
|
||||
val recursive: Boolean,
|
||||
val sort: SortAndDirection? = null,
|
||||
override val viewOptions: HomeRowViewOptions,
|
||||
override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(),
|
||||
) : HomeRowConfig {
|
||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): ByParent = this.copy(viewOptions = viewOptions)
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ sealed interface HomeRowConfig {
|
|||
override val id: Int,
|
||||
val name: String,
|
||||
val getItems: GetItemsRequest,
|
||||
override val viewOptions: HomeRowViewOptions,
|
||||
override val viewOptions: HomeRowViewOptions = HomeRowViewOptions(),
|
||||
) : HomeRowConfig {
|
||||
override fun updateViewOptions(viewOptions: HomeRowViewOptions): GetItems = this.copy(viewOptions = viewOptions)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import com.github.damontecres.wholphin.data.model.BaseItem
|
|||
import com.github.damontecres.wholphin.data.model.HomePageSettings
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowConfig
|
||||
import com.github.damontecres.wholphin.data.model.HomeRowViewOptions
|
||||
import com.github.damontecres.wholphin.data.model.SUPPORTED_HOME_PAGE_SETTINGS_VERSION
|
||||
import com.github.damontecres.wholphin.preferences.HomePagePreferences
|
||||
import com.github.damontecres.wholphin.ui.DefaultItemFields
|
||||
import com.github.damontecres.wholphin.ui.SlimItemFields
|
||||
|
|
@ -24,8 +23,11 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.decodeFromJsonElement
|
||||
import kotlinx.serialization.json.encodeToStream
|
||||
import kotlinx.serialization.json.jsonArray
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import org.jellyfin.sdk.api.client.ApiClient
|
||||
import org.jellyfin.sdk.api.client.extensions.displayPreferencesApi
|
||||
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
||||
|
|
@ -85,9 +87,8 @@ class HomeSettingsService
|
|||
): HomePageSettings? {
|
||||
val current = getDisplayPreferences(userId, displayPreferencesId)
|
||||
return current.customPrefs[DISPLAY_PREF_ID]?.let {
|
||||
Json
|
||||
.decodeFromString<HomePageSettings>(it)
|
||||
.takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION }
|
||||
val jsonElement = jsonParser.parseToJsonElement(it)
|
||||
decode(jsonElement)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,16 +121,30 @@ class HomeSettingsService
|
|||
val dir = File(context.filesDir, CUSTOM_PREF_ID)
|
||||
val file = File(dir, filename(userId))
|
||||
return if (file.exists()) {
|
||||
file.inputStream().use {
|
||||
jsonParser
|
||||
.decodeFromStream<HomePageSettings>(it)
|
||||
.takeIf { it.version <= SUPPORTED_HOME_PAGE_SETTINGS_VERSION }
|
||||
}
|
||||
val fileContents = file.readText()
|
||||
val jsonElement = jsonParser.parseToJsonElement(fileContents)
|
||||
decode(jsonElement)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun decode(element: JsonElement): HomePageSettings {
|
||||
val rowsElement = element.jsonObject["rows"]?.jsonArray
|
||||
val rows =
|
||||
rowsElement
|
||||
?.mapNotNull { row ->
|
||||
try {
|
||||
jsonParser.decodeFromJsonElement<HomeRowConfig>(row)
|
||||
} catch (ex: Exception) {
|
||||
Timber.w(ex, "Unknown row %s", row)
|
||||
// TODO maybe use placeholder instead of null?
|
||||
null
|
||||
}
|
||||
}.orEmpty()
|
||||
return HomePageSettings(rows)
|
||||
}
|
||||
|
||||
suspend fun updateCurrent(userId: UUID) {
|
||||
Timber.v("Getting setting for %s", userId)
|
||||
// User local then server/remote otherwise create a default
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue