2017-09-02 19:40:32 +02:00
|
|
|
// Converts Album entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
|
|
|
// to app domain entities.
|
|
|
|
@file:JvmName("APIAlbumConverter")
|
2018-02-17 20:36:19 +01:00
|
|
|
package org.moire.ultrasonic.domain
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
|
|
|
|
2021-11-26 17:03:33 +01:00
|
|
|
fun Album.toDomainEntity(): MusicDirectory.Album = MusicDirectory.Album(
|
2018-02-22 22:45:28 +01:00
|
|
|
id = this@toDomainEntity.id,
|
2021-11-30 20:53:10 +01:00
|
|
|
title = this@toDomainEntity.name ?: this@toDomainEntity.title,
|
2021-11-30 00:46:48 +01:00
|
|
|
album = this@toDomainEntity.album,
|
2018-02-22 22:45:28 +01:00
|
|
|
coverArt = this@toDomainEntity.coverArt,
|
|
|
|
artist = this@toDomainEntity.artist,
|
|
|
|
artistId = this@toDomainEntity.artistId,
|
|
|
|
songCount = this@toDomainEntity.songCount.toLong(),
|
|
|
|
duration = this@toDomainEntity.duration,
|
|
|
|
created = this@toDomainEntity.created?.time,
|
|
|
|
year = this@toDomainEntity.year,
|
2021-10-06 17:25:30 +02:00
|
|
|
genre = this@toDomainEntity.genre,
|
|
|
|
starred = this@toDomainEntity.starredDate.isNotEmpty()
|
2018-02-22 22:45:28 +01:00
|
|
|
)
|
2017-09-02 19:40:32 +02:00
|
|
|
|
|
|
|
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
2021-12-21 12:16:40 +01:00
|
|
|
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toTrackEntity() })
|
2017-09-02 19:40:32 +02:00
|
|
|
}
|
2017-09-16 20:02:44 +02:00
|
|
|
|
2021-11-26 17:03:33 +01:00
|
|
|
fun List<Album>.toDomainEntityList(): List<MusicDirectory.Album> = this.map { it.toDomainEntity() }
|