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) }
|
||||
}
|
||||
|
||||
private suspend fun applyTrackPreferences() {
|
||||
private fun applyTrackPreferences() {
|
||||
val context = currentMediaContext ?: return
|
||||
val preferences = context.preferences ?: return
|
||||
val preferences = context.preferences
|
||||
|
||||
val currentTrackState = _tracks.value
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@ import hu.bbara.purefin.core.player.preference.MediaTrackPreferences
|
||||
|
||||
data class MediaContext(
|
||||
val mediaId: String,
|
||||
val preferences: MediaTrackPreferences?,
|
||||
val preferences: MediaTrackPreferences,
|
||||
val mediaSegments: List<MediaSegment>
|
||||
)
|
||||
@@ -13,7 +13,13 @@ data class MediaTrackPreferences(
|
||||
val mediaId: String,
|
||||
val audioPreference: AudioTrackProperties? = null,
|
||||
val subtitlePreference: SubtitleTrackProperties? = null
|
||||
)
|
||||
) {
|
||||
companion object {
|
||||
fun empty(mediaId: String): MediaTrackPreferences {
|
||||
return MediaTrackPreferences(mediaId = mediaId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class AudioTrackProperties(
|
||||
|
||||
@@ -10,8 +10,8 @@ class TrackPreferencesRepository @Inject constructor(
|
||||
) {
|
||||
val preferences: Flow<TrackPreferences> = trackPreferencesDataStore.data
|
||||
|
||||
fun getMediaPreferences(mediaId: String): Flow<MediaTrackPreferences?> {
|
||||
return preferences.map { it.mediaPreferences[mediaId] }
|
||||
fun getMediaPreferences(mediaId: String): Flow<MediaTrackPreferences> {
|
||||
return preferences.map { it.mediaPreferences[mediaId] ?: MediaTrackPreferences.empty(mediaId = mediaId) }
|
||||
}
|
||||
|
||||
suspend fun saveAudioPreference(
|
||||
|
||||
@@ -17,7 +17,7 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.InternalSerializationApi
|
||||
@@ -157,7 +157,7 @@ class PlayerViewModel @Inject constructor(
|
||||
val (mediaItem, resumePositionMs) = result
|
||||
|
||||
val preferenceKey = episodeSeriesLookup.preferenceKeyFor(uuid)
|
||||
val preferences = trackPreferencesRepository.getMediaPreferences(preferenceKey).firstOrNull()
|
||||
val preferences = trackPreferencesRepository.getMediaPreferences(preferenceKey).first()
|
||||
val mediaSegments = playableMediaRepository.getMediaSegments(uuid)
|
||||
|
||||
val mediaContext = MediaContext(
|
||||
|
||||
Reference in New Issue
Block a user