2017-09-02 19:40:32 +02:00
|
|
|
// Converts Playlist entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
|
|
|
// to app domain entities.
|
|
|
|
@file:JvmName("APIPlaylistConverter")
|
2018-02-17 20:36:19 +01:00
|
|
|
package org.moire.ultrasonic.domain
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
import java.text.SimpleDateFormat
|
2017-11-10 21:31:48 +01:00
|
|
|
import kotlin.LazyThreadSafetyMode.NONE
|
2017-09-02 19:40:32 +02:00
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Playlist as APIPlaylist
|
|
|
|
|
2017-11-10 21:31:48 +01:00
|
|
|
internal val playlistDateFormat by lazy(NONE) { SimpleDateFormat.getInstance() }
|
|
|
|
|
2017-09-02 19:40:32 +02:00
|
|
|
fun APIPlaylist.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
|
|
|
name = this@toMusicDirectoryDomainEntity.name
|
|
|
|
addAll(this@toMusicDirectoryDomainEntity.entriesList.map { it.toDomainEntity() })
|
|
|
|
}
|
|
|
|
|
2017-12-16 20:47:00 +01:00
|
|
|
fun APIPlaylist.toDomainEntity(): Playlist = Playlist(this.id, this.name, this.owner,
|
2017-09-02 19:40:32 +02:00
|
|
|
this.comment, this.songCount.toString(),
|
2018-02-22 21:15:32 +01:00
|
|
|
this.created?.let { playlistDateFormat.format(it.time) } ?: "",
|
|
|
|
public)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
fun List<APIPlaylist>.toDomainEntitiesList(): List<Playlist> = this.map { it.toDomainEntity() }
|