Created
April 16, 2020 23:13
-
-
Save DenisBronx/08b5213023331d4432b112f8c4157267 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
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