mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-11 01:00:58 +01:00
Replace consumer use with a lambda
This commit is contained in:
parent
c44257f569
commit
fea515a526
@ -63,26 +63,25 @@ class MediaPlayerLifecycleSupport : KoinComponent {
|
||||
mediaPlayerController.onCreate()
|
||||
if (autoPlay) mediaPlayerController.preload()
|
||||
|
||||
playbackStateSerializer.deserialize(object : Consumer<State?>() {
|
||||
override fun accept(state: State?) {
|
||||
mediaPlayerController.restore(
|
||||
state!!.songs,
|
||||
state.currentPlayingIndex,
|
||||
state.currentPlayingPosition,
|
||||
autoPlay,
|
||||
false
|
||||
)
|
||||
playbackStateSerializer.deserialize {
|
||||
|
||||
// Work-around: Serialize again, as the restore() method creates a
|
||||
// serialization without current playing info.
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
mediaPlayerController.playerPosition
|
||||
)
|
||||
afterCreated?.run()
|
||||
}
|
||||
})
|
||||
mediaPlayerController.restore(
|
||||
it!!.songs,
|
||||
it.currentPlayingIndex,
|
||||
it.currentPlayingPosition,
|
||||
autoPlay,
|
||||
false
|
||||
)
|
||||
|
||||
// Work-around: Serialize again, as the restore() method creates a
|
||||
// serialization without current playing info.
|
||||
playbackStateSerializer.serialize(
|
||||
downloader.playlist,
|
||||
downloader.currentPlayingIndex,
|
||||
mediaPlayerController.playerPosition
|
||||
)
|
||||
afterCreated?.run()
|
||||
}
|
||||
|
||||
CacheCleaner().clean()
|
||||
created = true
|
||||
|
@ -81,7 +81,7 @@ class PlaybackStateSerializer : KoinComponent {
|
||||
mediaSessionHandler.updateMediaSessionQueue(state.songs)
|
||||
}
|
||||
|
||||
fun deserialize(afterDeserialized: Consumer<State?>) {
|
||||
fun deserialize(afterDeserialized: (State?) -> Unit?) {
|
||||
|
||||
appScope.launch {
|
||||
try {
|
||||
@ -94,7 +94,7 @@ class PlaybackStateSerializer : KoinComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeNow(afterDeserialized: Consumer<State?>) {
|
||||
private fun deserializeNow(afterDeserialized: (State?) -> Unit?) {
|
||||
|
||||
val state = FileUtil.deserialize<State>(
|
||||
context, Constants.FILENAME_PLAYLIST_SER
|
||||
@ -107,6 +107,6 @@ class PlaybackStateSerializer : KoinComponent {
|
||||
)
|
||||
|
||||
mediaSessionHandler.updateMediaSessionQueue(state.songs)
|
||||
afterDeserialized.accept(state)
|
||||
afterDeserialized(state)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user