Last active
July 26, 2020 10:41
-
-
Save DenisBronx/12479034cab2c503a9255ced78183ff8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun mapAlbumDto(input: NetworkAlbum, mapSongList: (List<NetworkSong>?) -> List<Song>): Album { | |
return Album( | |
input.id.orEmpty(), | |
input.title.orEmpty(), | |
mapSongList(input.songs) | |
) | |
} | |
fun mapSongDto(input: NetworkSong): Song { | |
return Song( | |
input.id.orEmpty(), | |
input.name.orEmpty(), | |
input.link.orEmpty(), | |
input.duration ?: 0, | |
Song.Metadata( | |
formatAlbumDate(input.creationDate), | |
formatAlbumDate(input.uploadDate), | |
input.authorFullName.orEmpty() | |
) | |
) | |
} | |
private fun formatAlbumDate(date: String?): Long { | |
return date?.let { | |
SimpleDateFormat("dd MMMM yyyy HH:mm:ss", Locale.UK).parse(it).time | |
} ?: Long.MIN_VALUE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment