Skip to content

Instantly share code, notes, and snippets.

@DenisBronx
Last active July 26, 2020 10:41
Show Gist options
  • Save DenisBronx/12479034cab2c503a9255ced78183ff8 to your computer and use it in GitHub Desktop.
Save DenisBronx/12479034cab2c503a9255ced78183ff8 to your computer and use it in GitHub Desktop.
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