From 939cd8583c603d175e8f48705c366cb1bc6562b0 Mon Sep 17 00:00:00 2001 From: tzugen Date: Sat, 23 Oct 2021 16:37:19 +0200 Subject: [PATCH] Semantically rename DownloadQueueSerializer to PlaybackStateSerializer --- .../moire/ultrasonic/di/MediaPlayerModule.kt | 4 ++-- .../service/MediaPlayerController.kt | 14 +++++------ .../service/MediaPlayerLifecycleSupport.kt | 8 +++---- .../ultrasonic/service/MediaPlayerService.kt | 10 ++++---- ...rializer.kt => PlaybackStateSerializer.kt} | 24 +++++++++---------- .../org/moire/ultrasonic/util/Constants.kt | 2 +- 6 files changed, 31 insertions(+), 31 deletions(-) rename ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/{DownloadQueueSerializer.kt => PlaybackStateSerializer.kt} (78%) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MediaPlayerModule.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MediaPlayerModule.kt index f50883d6..d08c8f20 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MediaPlayerModule.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MediaPlayerModule.kt @@ -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()) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerController.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerController.kt index 2a96b79e..0e13666c 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerController.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerController.kt @@ -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 diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt index 11ef9c7c..5bc0801e 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt @@ -32,7 +32,7 @@ import timber.log.Timber * @author Sindre Mehus */ class MediaPlayerLifecycleSupport : KoinComponent { - private val downloadQueueSerializer by inject() + private val playbackStateSerializer by inject() private val mediaPlayerController by inject() private val downloader by inject() private val mediaSessionEventDistributor by inject() @@ -63,7 +63,7 @@ class MediaPlayerLifecycleSupport : KoinComponent { mediaPlayerController.onCreate() if (autoPlay) mediaPlayerController.preload() - downloadQueueSerializer.deserializeDownloadQueue(object : Consumer() { + playbackStateSerializer.deserialize(object : Consumer() { 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 diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt index bd8eb3a5..21a8e5f8 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt @@ -60,7 +60,7 @@ class MediaPlayerService : Service() { private val scrobbler = Scrobbler() private val jukeboxMediaPlayer by inject() - private val downloadQueueSerializer by inject() + private val playbackStateSerializer by inject() private val shufflePlayBuffer by inject() private val downloader by inject() private val localMediaPlayer by inject() @@ -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 ) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadQueueSerializer.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt similarity index 78% rename from ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadQueueSerializer.kt rename to ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt index 1cb08b32..f32bc6b7 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadQueueSerializer.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt @@ -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() private val mediaSessionHandler by inject() @@ -37,7 +37,7 @@ class DownloadQueueSerializer : KoinComponent { private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) - fun serializeDownloadQueue( + fun serialize( songs: Iterable, 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, 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) { + fun deserialize(afterDeserialized: Consumer) { 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) { + private fun deserializeNow(afterDeserialized: Consumer) { val state = FileUtil.deserialize( - context, Constants.FILENAME_DOWNLOADS_SER + context, Constants.FILENAME_PLAYLIST_SER ) ?: return Timber.i( diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Constants.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Constants.kt index 6206378f..a8da7b71 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Constants.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Constants.kt @@ -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"