music: add equals impl to library

Now that Library is no longer a data class, it needs to have an
implementation of equals.

This caused all reloads to be interpreted as new libraries, even when
they were not.
This commit is contained in:
Alexander Capehart 2023-02-20 19:28:27 -07:00
parent f4aee4532b
commit 5eab83ba4d
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 16 additions and 0 deletions

View file

@ -100,6 +100,21 @@ private class LibraryImpl(rawSongs: List<RawSong>, settings: MusicSettings) : Li
genres.forEach { put(it.uid, it.finalize()) }
}
override fun equals(other: Any?) =
other is Library &&
other.songs == songs &&
other.albums == albums &&
other.artists == artists &&
other.genres == genres
override fun hashCode(): Int {
var hashCode = songs.hashCode()
hashCode = hashCode * 31 + albums.hashCode()
hashCode = hashCode * 31 + artists.hashCode()
hashCode = hashCode * 31 + genres.hashCode()
return hashCode
}
/**
* Finds a [Music] item [T] in the library by it's [Music.UID].
* @param uid The [Music.UID] to search for.

View file

@ -85,6 +85,7 @@ interface Settings<L> {
sharedPreferences: SharedPreferences,
key: String
) {
// FIXME: Settings initialization firing the listener.
onSettingChanged(key, unlikelyToBeNull(listener))
}