mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-24 03:36:51 +00:00
refactor: Update MediaTrackPreferences handling for improved null safety and initialization
This commit is contained in:
@@ -264,9 +264,9 @@ class PlayerManager @Inject constructor(
|
|||||||
_playbackState.update { it.copy(error = null) }
|
_playbackState.update { it.copy(error = null) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun applyTrackPreferences() {
|
private fun applyTrackPreferences() {
|
||||||
val context = currentMediaContext ?: return
|
val context = currentMediaContext ?: return
|
||||||
val preferences = context.preferences ?: return
|
val preferences = context.preferences
|
||||||
|
|
||||||
val currentTrackState = _tracks.value
|
val currentTrackState = _tracks.value
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ import hu.bbara.purefin.core.player.preference.MediaTrackPreferences
|
|||||||
|
|
||||||
data class MediaContext(
|
data class MediaContext(
|
||||||
val mediaId: String,
|
val mediaId: String,
|
||||||
val preferences: MediaTrackPreferences?,
|
val preferences: MediaTrackPreferences,
|
||||||
val mediaSegments: List<MediaSegment>
|
val mediaSegments: List<MediaSegment>
|
||||||
)
|
)
|
||||||
@@ -13,7 +13,13 @@ data class MediaTrackPreferences(
|
|||||||
val mediaId: String,
|
val mediaId: String,
|
||||||
val audioPreference: AudioTrackProperties? = null,
|
val audioPreference: AudioTrackProperties? = null,
|
||||||
val subtitlePreference: SubtitleTrackProperties? = null
|
val subtitlePreference: SubtitleTrackProperties? = null
|
||||||
)
|
) {
|
||||||
|
companion object {
|
||||||
|
fun empty(mediaId: String): MediaTrackPreferences {
|
||||||
|
return MediaTrackPreferences(mediaId = mediaId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class AudioTrackProperties(
|
data class AudioTrackProperties(
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ class TrackPreferencesRepository @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
val preferences: Flow<TrackPreferences> = trackPreferencesDataStore.data
|
val preferences: Flow<TrackPreferences> = trackPreferencesDataStore.data
|
||||||
|
|
||||||
fun getMediaPreferences(mediaId: String): Flow<MediaTrackPreferences?> {
|
fun getMediaPreferences(mediaId: String): Flow<MediaTrackPreferences> {
|
||||||
return preferences.map { it.mediaPreferences[mediaId] }
|
return preferences.map { it.mediaPreferences[mediaId] ?: MediaTrackPreferences.empty(mediaId = mediaId) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun saveAudioPreference(
|
suspend fun saveAudioPreference(
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.serialization.InternalSerializationApi
|
import kotlinx.serialization.InternalSerializationApi
|
||||||
@@ -157,7 +157,7 @@ class PlayerViewModel @Inject constructor(
|
|||||||
val (mediaItem, resumePositionMs) = result
|
val (mediaItem, resumePositionMs) = result
|
||||||
|
|
||||||
val preferenceKey = episodeSeriesLookup.preferenceKeyFor(uuid)
|
val preferenceKey = episodeSeriesLookup.preferenceKeyFor(uuid)
|
||||||
val preferences = trackPreferencesRepository.getMediaPreferences(preferenceKey).firstOrNull()
|
val preferences = trackPreferencesRepository.getMediaPreferences(preferenceKey).first()
|
||||||
val mediaSegments = playableMediaRepository.getMediaSegments(uuid)
|
val mediaSegments = playableMediaRepository.getMediaSegments(uuid)
|
||||||
|
|
||||||
val mediaContext = MediaContext(
|
val mediaContext = MediaContext(
|
||||||
|
|||||||
Reference in New Issue
Block a user