Skip to content

Instantly share code, notes, and snippets.

@DenisBronx
Created April 16, 2020 23:13
Show Gist options
  • Save DenisBronx/08b5213023331d4432b112f8c4157267 to your computer and use it in GitHub Desktop.
Save DenisBronx/08b5213023331d4432b112f8c4157267 to your computer and use it in GitHub Desktop.
class AlbumDataMapper(
private val songListDataMapper: NullableInputListMapper<NetworkSong, Song>
) : Mapper<NetworkAlbum, Album> {
override fun map(input: NetworkAlbum): Album {
return Album(
input.id.orEmpty(),
input.title.orEmpty(),
songListDataMapper.map(input.songs)
)
}
}
class SongDataMapper : Mapper<NetworkSong, Song> {
override fun map(input: NetworkSong): Song {
return Song(
input.id.orEmpty(),
input.name.orEmpty(),
input.link.orEmpty(),
input.duration ?: 0,
Song.Metadata(
formatDate(input.creationDate),
formatDate(input.uploadDate),
input.authorFullName.orEmpty()
)
)
}
private fun formatDate(date: String?): Long {
return date?.let {
SimpleDateFormat(DATE_FORMAT_PATTERN, Locale.UK).parse(it).time
} ?: Long.MIN_VALUE
}
private companion object {
const val DATE_FORMAT_PATTERN = "dd MMMM yyyy HH:mm:ss"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment