Minor music model changes

Move the size recalculations/child item sorting to a method called finalize() in artists, albums, and genres. Also remove the artist images for now, Ill figure out a good way to bring them back.
This commit is contained in:
OxygenCobalt
2020-09-04 18:28:11 -06:00
parent 7a2c779fe2
commit 565d1efa96
9 changed files with 63 additions and 46 deletions
@@ -65,25 +65,6 @@ fun Long.toAlbumArtURI(): Uri {
)
}
// Get the cover art
@BindingAdapter("coverArt")
fun ImageView.getCoverArt(any: Any) {
val uri = when (any) {
is Song -> any.album.coverUri
is Album -> any.coverUri
// TODO: Artist images
else -> Uri.EMPTY
}
load(uri) {
crossfade(true)
placeholder(android.R.color.transparent)
error(R.drawable.ic_music)
}
}
fun Int.toSongCount(): Int {
return if (this < 2) {
R.string.label_single_song
@@ -113,3 +94,30 @@ fun TextView.getSongAlbumCount(artist: Artist) {
text = context.getString(R.string.format_combined_song_album, albums, songs)
}
// Get the cover art
@BindingAdapter("coverArt")
fun ImageView.getCoverArt(any: Any) {
val uri = when (any) {
is Song -> any.album.coverUri
is Album -> any.coverUri
else -> Uri.EMPTY
}
load(uri) {
crossfade(true)
placeholder(android.R.color.transparent)
error(R.drawable.ic_music)
}
}
// Get the artist image.
@BindingAdapter("artistImage")
fun ImageView.getArtistImage(artist: Artist) {
load(artist.albums[0].coverUri) {
crossfade(true)
placeholder(android.R.color.transparent)
error(R.drawable.ic_music)
}
}
@@ -14,4 +14,8 @@ data class Album(
lateinit var artist: Artist
val songs = mutableListOf<Song>()
fun finalize() {
songs.sortBy { it.track }
}
}
@@ -9,4 +9,13 @@ data class Artist(
val albums = mutableListOf<Album>()
var numAlbums = 0
var numSongs = 0
fun finalize() {
albums.sortByDescending { it.year }
numAlbums = albums.size
albums.forEach { album ->
numSongs += album.numSongs
}
}
}
@@ -6,4 +6,9 @@ data class Genre(
) {
val artists = mutableListOf<Artist>()
var numArtists = 0
fun finalize() {
artists.sortByDescending { it.name }
numArtists = artists.size
}
}
@@ -54,6 +54,7 @@ class MusicSorter(
}
unknownAlbum.numSongs = unknownAlbum.songs.size
unknownAlbum.finalize()
albums.add(unknownAlbum)
@@ -62,6 +63,8 @@ class MusicSorter(
"${unknownSongs.size} songs were placed into an unknown album."
)
}
albums.sortByDescending { it.title }
}
private fun sortAlbumsIntoArtists() {
@@ -79,10 +82,7 @@ class MusicSorter(
artist.albums.add(album)
}
artist.numAlbums = artist.albums.size
artist.albums.forEach { album ->
artist.numSongs += album.numSongs
}
artist.finalize()
unknownAlbums.removeAll(artistAlbums)
}
@@ -98,10 +98,7 @@ class MusicSorter(
unknownArtist.albums.add(album)
}
unknownArtist.numAlbums = unknownArtist.albums.size
unknownArtist.albums.forEach { album ->
unknownArtist.numSongs += album.numSongs
}
unknownArtist.finalize()
artists.add(unknownArtist)
@@ -110,6 +107,8 @@ class MusicSorter(
"${unknownAlbums.size} albums were placed into an unknown artist."
)
}
artists.sortByDescending { it.name }
}
private fun sortArtistsIntoGenres() {
@@ -150,6 +149,8 @@ class MusicSorter(
"${unknownArtists.size} albums were placed into an unknown genre."
)
}
genres.sortByDescending { it.name }
}
// Correct any empty names [""] with the proper placeholders [Unknown Album]