Preferences updates

This commit is contained in:
Damontecres 2025-09-30 17:14:08 -04:00
parent 54bdb25d49
commit 60de501851
No known key found for this signature in database
25 changed files with 1544 additions and 56 deletions

View file

@ -0,0 +1,51 @@
package com.github.damontecres.dolphin.preferences
import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.github.damontecres.dolphin.ui.preferences.AppPreference
import com.google.protobuf.InvalidProtocolBufferException
import java.io.InputStream
import java.io.OutputStream
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
class AppPreferencesSerializer
@Inject
constructor() : Serializer<AppPreferences> {
override val defaultValue: AppPreferences =
AppPreferences
.newBuilder()
.apply {
playbackPreferences =
PlaybackPreferences
.newBuilder()
.apply {
skipForwardMs =
AppPreference.SkipForward.defaultValue.seconds.inWholeMilliseconds
skipBackMs =
AppPreference.SkipBack.defaultValue.seconds.inWholeMilliseconds
controllerTimeoutMs = AppPreference.ControllerTimeout.defaultValue
seekBarSteps = AppPreference.SeekBarSteps.defaultValue.toInt()
}.build()
}.build()
override suspend fun readFrom(input: InputStream): AppPreferences {
try {
return AppPreferences.parseFrom(input)
} catch (exception: InvalidProtocolBufferException) {
throw CorruptionException("Cannot read proto.", exception)
}
}
override suspend fun writeTo(
t: AppPreferences,
output: OutputStream,
) = t.writeTo(output)
}
inline fun AppPreferences.update(block: AppPreferences.Builder.() -> Unit): AppPreferences = toBuilder().apply(block).build()
inline fun AppPreferences.updatePlaybackPreferences(block: PlaybackPreferences.Builder.() -> Unit): AppPreferences =
update {
playbackPreferences = playbackPreferences.toBuilder().apply(block).build()
}

View file

@ -0,0 +1,26 @@
package com.github.damontecres.dolphin.preferences
import org.jellyfin.sdk.model.api.SubtitlePlaybackMode
import org.jellyfin.sdk.model.api.UserConfiguration
data class UserPreferences(
val appPreferences: AppPreferences,
val userConfig: UserConfiguration,
)
val DefaultUserConfiguration =
UserConfiguration(
playDefaultAudioTrack = true,
displayMissingEpisodes = false,
groupedFolders = listOf(),
subtitleMode = SubtitlePlaybackMode.DEFAULT,
displayCollectionsView = false,
enableLocalPassword = false,
orderedViews = listOf(),
latestItemsExcludes = listOf(),
myMediaExcludes = listOf(),
hidePlayedInLatest = true,
rememberAudioSelections = true,
rememberSubtitleSelections = true,
enableNextEpisodeAutoPlay = true,
)

View file

@ -1,27 +0,0 @@
package com.github.damontecres.dolphin.preferences
import androidx.datastore.core.CorruptionException
import androidx.datastore.core.Serializer
import com.google.protobuf.InvalidProtocolBufferException
import java.io.InputStream
import java.io.OutputStream
import javax.inject.Inject
class UserPreferencesSerializer
@Inject
constructor() : Serializer<UserPreferences> {
override val defaultValue: UserPreferences = UserPreferences.getDefaultInstance()
override suspend fun readFrom(input: InputStream): UserPreferences {
try {
return UserPreferences.parseFrom(input)
} catch (exception: InvalidProtocolBufferException) {
throw CorruptionException("Cannot read proto.", exception)
}
}
override suspend fun writeTo(
t: UserPreferences,
output: OutputStream,
) = t.writeTo(output)
}