music: fix in-process grouping problems
Parent objects cannot process anything related to eachother until finalize without causing set issues, fix that
This commit is contained in:
parent
1b295934e0
commit
a30e6db71d
2 changed files with 26 additions and 17 deletions
|
@ -99,7 +99,11 @@ class InterpreterImpl @Inject constructor(private val preparer: Preparer) : Inte
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return LibraryImpl(songs, albums, artists, genres)
|
return LibraryImpl(
|
||||||
|
songs,
|
||||||
|
albums.onEach { it.finalize() },
|
||||||
|
artists.onEach { it.finalize() },
|
||||||
|
genres.onEach { it.finalize() })
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class LinkedSongImpl(private val albumLinkedSong: AlbumLinker.LinkedSong) :
|
private data class LinkedSongImpl(private val albumLinkedSong: AlbumLinker.LinkedSong) :
|
||||||
|
|
|
@ -120,8 +120,10 @@ class AlbumImpl(linkedAlbum: LinkedAlbum) : Album {
|
||||||
else if (song.date > it.max) Date.Range(it.min, song.date) else it
|
else if (song.date > it.max) Date.Range(it.min, song.date) else it
|
||||||
} ?: Date.Range(song.date, song.date)
|
} ?: Date.Range(song.date, song.date)
|
||||||
}
|
}
|
||||||
hashCode = 31 * hashCode + song.hashCode()
|
}
|
||||||
cover = ParentCover(song.cover, emptyList())
|
|
||||||
|
fun finalize() {
|
||||||
|
cover = ParentCover(songs.first().cover, songs.map { it.cover })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,16 +141,11 @@ class ArtistImpl(private val preArtist: PreArtist) : Artist {
|
||||||
|
|
||||||
override val songs = mutableSetOf<Song>()
|
override val songs = mutableSetOf<Song>()
|
||||||
|
|
||||||
|
private val albums = mutableListOf<Album>()
|
||||||
override var explicitAlbums = mutableSetOf<Album>()
|
override var explicitAlbums = mutableSetOf<Album>()
|
||||||
override var implicitAlbums = mutableSetOf<Album>()
|
override var implicitAlbums = mutableSetOf<Album>()
|
||||||
|
|
||||||
override val genres: List<Genre> by lazy {
|
override var genres = listOf<Genre>()
|
||||||
// TODO: Not sure how to integrate this into music loading.
|
|
||||||
Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING)
|
|
||||||
.genres(songs.flatMapTo(mutableSetOf()) { it.genres })
|
|
||||||
.sortedByDescending { genre -> songs.count { it.genres.contains(genre) } }
|
|
||||||
}
|
|
||||||
|
|
||||||
override var durationMs = 0L
|
override var durationMs = 0L
|
||||||
override lateinit var cover: ParentCover
|
override lateinit var cover: ParentCover
|
||||||
|
|
||||||
|
@ -171,16 +168,21 @@ class ArtistImpl(private val preArtist: PreArtist) : Artist {
|
||||||
fun link(song: SongImpl) {
|
fun link(song: SongImpl) {
|
||||||
songs.add(song)
|
songs.add(song)
|
||||||
durationMs += song.durationMs
|
durationMs += song.durationMs
|
||||||
if (!explicitAlbums.contains(song.album)) {
|
|
||||||
implicitAlbums.add(song.album)
|
|
||||||
}
|
|
||||||
hashCode = 31 * hashCode + song.hashCode()
|
hashCode = 31 * hashCode + song.hashCode()
|
||||||
cover = ParentCover(song.cover, emptyList())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun link(album: AlbumImpl) {
|
fun link(album: AlbumImpl) {
|
||||||
explicitAlbums.add(album)
|
albums.add(album)
|
||||||
implicitAlbums.remove(album)
|
}
|
||||||
|
|
||||||
|
fun finalize() {
|
||||||
|
explicitAlbums.addAll(albums)
|
||||||
|
implicitAlbums.addAll(songs.mapTo(mutableSetOf()) { it.album } - albums.toSet())
|
||||||
|
cover = ParentCover(songs.first().cover, songs.map { it.cover })
|
||||||
|
genres =
|
||||||
|
Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING)
|
||||||
|
.genres(songs.flatMapTo(mutableSetOf()) { it.genres })
|
||||||
|
.sortedByDescending { genre -> songs.count { it.genres.contains(genre) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,9 +211,12 @@ class GenreImpl(private val preGenre: PreGenre) : Genre {
|
||||||
|
|
||||||
fun link(song: SongImpl) {
|
fun link(song: SongImpl) {
|
||||||
songs.add(song)
|
songs.add(song)
|
||||||
artists.addAll(song.artists)
|
|
||||||
durationMs += song.durationMs
|
durationMs += song.durationMs
|
||||||
hashCode = 31 * hashCode + song.hashCode()
|
hashCode = 31 * hashCode + song.hashCode()
|
||||||
cover = ParentCover(song.cover, emptyList())
|
cover = ParentCover(song.cover, emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun finalize() {
|
||||||
|
artists.addAll(songs.flatMapTo(mutableSetOf()) { it.artists })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue