Semantically rename DownloadQueueSerializer to PlaybackStateSerializer
This commit is contained in:
parent
7d2923230c
commit
939cd8583c
|
@ -2,13 +2,13 @@ package org.moire.ultrasonic.di
|
|||
|
||||
import org.koin.dsl.module
|
||||
import org.moire.ultrasonic.service.AudioFocusHandler
|
||||
import org.moire.ultrasonic.service.DownloadQueueSerializer
|
||||
import org.moire.ultrasonic.service.Downloader
|
||||
import org.moire.ultrasonic.service.ExternalStorageMonitor
|
||||
import org.moire.ultrasonic.service.JukeboxMediaPlayer
|
||||
import org.moire.ultrasonic.service.LocalMediaPlayer
|
||||
import org.moire.ultrasonic.service.MediaPlayerController
|
||||
import org.moire.ultrasonic.service.MediaPlayerLifecycleSupport
|
||||
import org.moire.ultrasonic.service.PlaybackStateSerializer
|
||||
import org.moire.ultrasonic.util.ShufflePlayBuffer
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ import org.moire.ultrasonic.util.ShufflePlayBuffer
|
|||
val mediaPlayerModule = module {
|
||||
single { JukeboxMediaPlayer(get()) }
|
||||
single { MediaPlayerLifecycleSupport() }
|
||||
single { DownloadQueueSerializer() }
|
||||
single { PlaybackStateSerializer() }
|
||||
single { ExternalStorageMonitor() }
|
||||
single { ShufflePlayBuffer() }
|
||||
single { Downloader(get(), get(), get()) }
|
||||
|
|
|
@ -32,7 +32,7 @@ import timber.log.Timber
|
|||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
class MediaPlayerController(
|
||||
private val downloadQueueSerializer: DownloadQueueSerializer,
|
||||
private val playbackStateSerializer: PlaybackStateSerializer,
|
||||
private val externalStorageMonitor: ExternalStorageMonitor,
|
||||
private val downloader: Downloader,
|
||||
private val shufflePlayBuffer: ShufflePlayBuffer,
|
||||
|
@ -197,7 +197,7 @@ class MediaPlayerController(
|
|||
downloader.checkDownloads()
|
||||
}
|
||||
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
playerPosition
|
||||
|
@ -209,7 +209,7 @@ class MediaPlayerController(
|
|||
if (songs == null) return
|
||||
val filteredSongs = songs.filterNotNull()
|
||||
downloader.downloadBackground(filteredSongs, save)
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
playerPosition
|
||||
|
@ -240,7 +240,7 @@ class MediaPlayerController(
|
|||
@Synchronized
|
||||
fun shuffle() {
|
||||
downloader.shuffle()
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
playerPosition
|
||||
|
@ -273,7 +273,7 @@ class MediaPlayerController(
|
|||
// If no MediaPlayerService is available, just empty the playlist
|
||||
downloader.clearPlaylist()
|
||||
if (serialize) {
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex, playerPosition
|
||||
)
|
||||
|
@ -293,7 +293,7 @@ class MediaPlayerController(
|
|||
}
|
||||
}
|
||||
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
playerPosition
|
||||
|
@ -310,7 +310,7 @@ class MediaPlayerController(
|
|||
}
|
||||
downloader.removeFromPlaylist(downloadFile)
|
||||
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
playerPosition
|
||||
|
|
|
@ -32,7 +32,7 @@ import timber.log.Timber
|
|||
* @author Sindre Mehus
|
||||
*/
|
||||
class MediaPlayerLifecycleSupport : KoinComponent {
|
||||
private val downloadQueueSerializer by inject<DownloadQueueSerializer>()
|
||||
private val playbackStateSerializer by inject<PlaybackStateSerializer>()
|
||||
private val mediaPlayerController by inject<MediaPlayerController>()
|
||||
private val downloader by inject<Downloader>()
|
||||
private val mediaSessionEventDistributor by inject<MediaSessionEventDistributor>()
|
||||
|
@ -63,7 +63,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||
mediaPlayerController.onCreate()
|
||||
if (autoPlay) mediaPlayerController.preload()
|
||||
|
||||
downloadQueueSerializer.deserializeDownloadQueue(object : Consumer<State?>() {
|
||||
playbackStateSerializer.deserialize(object : Consumer<State?>() {
|
||||
override fun accept(state: State?) {
|
||||
mediaPlayerController.restore(
|
||||
state!!.songs,
|
||||
|
@ -75,7 +75,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||
|
||||
// Work-around: Serialize again, as the restore() method creates a
|
||||
// serialization without current playing info.
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
mediaPlayerController.playerPosition
|
||||
|
@ -93,7 +93,7 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
|||
|
||||
if (!created) return
|
||||
|
||||
downloadQueueSerializer.serializeDownloadQueueNow(
|
||||
playbackStateSerializer.serializeNow(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
mediaPlayerController.playerPosition
|
||||
|
|
|
@ -60,7 +60,7 @@ class MediaPlayerService : Service() {
|
|||
private val scrobbler = Scrobbler()
|
||||
|
||||
private val jukeboxMediaPlayer by inject<JukeboxMediaPlayer>()
|
||||
private val downloadQueueSerializer by inject<DownloadQueueSerializer>()
|
||||
private val playbackStateSerializer by inject<PlaybackStateSerializer>()
|
||||
private val shufflePlayBuffer by inject<ShufflePlayBuffer>()
|
||||
private val downloader by inject<Downloader>()
|
||||
private val localMediaPlayer by inject<LocalMediaPlayer>()
|
||||
|
@ -92,7 +92,7 @@ class MediaPlayerService : Service() {
|
|||
setupOnSongCompletedHandler()
|
||||
|
||||
localMediaPlayer.onPrepared = {
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
playerPosition
|
||||
|
@ -304,7 +304,7 @@ class MediaPlayerService : Service() {
|
|||
private fun resetPlayback() {
|
||||
localMediaPlayer.reset()
|
||||
localMediaPlayer.setCurrentPlaying(null)
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex, playerPosition
|
||||
)
|
||||
|
@ -406,7 +406,7 @@ class MediaPlayerService : Service() {
|
|||
)
|
||||
|
||||
if (playerState === PlayerState.PAUSED) {
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist, downloader.currentPlayingIndex, playerPosition
|
||||
)
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ class MediaPlayerService : Service() {
|
|||
localMediaPlayer.setCurrentPlaying(null)
|
||||
setNextPlaying()
|
||||
if (serialize) {
|
||||
downloadQueueSerializer.serializeDownloadQueue(
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex, playerPosition
|
||||
)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* DownloadQueueSerializer.kt
|
||||
* PlaybackStateSerializer.kt
|
||||
* Copyright (C) 2009-2021 Ultrasonic developers
|
||||
*
|
||||
* Distributed under terms of the GNU GPLv3 license.
|
||||
|
@ -24,10 +24,10 @@ import timber.log.Timber
|
|||
|
||||
/**
|
||||
* This class is responsible for the serialization / deserialization
|
||||
* of the DownloadQueue (playlist) to the filesystem.
|
||||
* It also serializes the player state e.g. current playing number and play position.
|
||||
* of the playlist and the player state (e.g. current playing number and play position)
|
||||
* to the filesystem.
|
||||
*/
|
||||
class DownloadQueueSerializer : KoinComponent {
|
||||
class PlaybackStateSerializer : KoinComponent {
|
||||
|
||||
private val context by inject<Context>()
|
||||
private val mediaSessionHandler by inject<MediaSessionHandler>()
|
||||
|
@ -37,7 +37,7 @@ class DownloadQueueSerializer : KoinComponent {
|
|||
|
||||
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
|
||||
fun serializeDownloadQueue(
|
||||
fun serialize(
|
||||
songs: Iterable<DownloadFile>,
|
||||
currentPlayingIndex: Int,
|
||||
currentPlayingPosition: Int
|
||||
|
@ -47,7 +47,7 @@ class DownloadQueueSerializer : KoinComponent {
|
|||
appScope.launch {
|
||||
if (lock.tryLock()) {
|
||||
try {
|
||||
serializeDownloadQueueNow(songs, currentPlayingIndex, currentPlayingPosition)
|
||||
serializeNow(songs, currentPlayingIndex, currentPlayingPosition)
|
||||
} finally {
|
||||
lock.unlock()
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class DownloadQueueSerializer : KoinComponent {
|
|||
}
|
||||
}
|
||||
|
||||
fun serializeDownloadQueueNow(
|
||||
fun serializeNow(
|
||||
songs: Iterable<DownloadFile>,
|
||||
currentPlayingIndex: Int,
|
||||
currentPlayingPosition: Int
|
||||
|
@ -75,18 +75,18 @@ class DownloadQueueSerializer : KoinComponent {
|
|||
state.currentPlayingPosition
|
||||
)
|
||||
|
||||
FileUtil.serialize(context, state, Constants.FILENAME_DOWNLOADS_SER)
|
||||
FileUtil.serialize(context, state, Constants.FILENAME_PLAYLIST_SER)
|
||||
|
||||
// This is called here because the queue is usually serialized after a change
|
||||
mediaSessionHandler.updateMediaSessionQueue(state.songs)
|
||||
}
|
||||
|
||||
fun deserializeDownloadQueue(afterDeserialized: Consumer<State?>) {
|
||||
fun deserialize(afterDeserialized: Consumer<State?>) {
|
||||
|
||||
appScope.launch {
|
||||
try {
|
||||
lock.lock()
|
||||
deserializeDownloadQueueNow(afterDeserialized)
|
||||
deserializeNow(afterDeserialized)
|
||||
setup.set(true)
|
||||
} finally {
|
||||
lock.unlock()
|
||||
|
@ -94,10 +94,10 @@ class DownloadQueueSerializer : KoinComponent {
|
|||
}
|
||||
}
|
||||
|
||||
private fun deserializeDownloadQueueNow(afterDeserialized: Consumer<State?>) {
|
||||
private fun deserializeNow(afterDeserialized: Consumer<State?>) {
|
||||
|
||||
val state = FileUtil.deserialize<State>(
|
||||
context, Constants.FILENAME_DOWNLOADS_SER
|
||||
context, Constants.FILENAME_PLAYLIST_SER
|
||||
) ?: return
|
||||
|
||||
Timber.i(
|
|
@ -118,7 +118,7 @@ object Constants {
|
|||
const val PREFERENCE_VALUE_ALL = 0
|
||||
const val PREFERENCE_VALUE_A2DP = 1
|
||||
const val PREFERENCE_VALUE_DISABLED = 2
|
||||
const val FILENAME_DOWNLOADS_SER = "downloadstate.ser"
|
||||
const val FILENAME_PLAYLIST_SER = "downloadstate.ser"
|
||||
const val ALBUM_ART_FILE = "folder.jpeg"
|
||||
const val STARRED = "starred"
|
||||
const val ALPHABETICAL_BY_NAME = "alphabeticalByName"
|
||||
|
|
Loading…
Reference in New Issue