From 5eab83ba4dbde8944ce2e231fe7df453e3fa74ab Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 20 Feb 2023 19:28:27 -0700 Subject: [PATCH] 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. --- .../java/org/oxycblt/auxio/music/model/Library.kt | 15 +++++++++++++++ .../java/org/oxycblt/auxio/settings/Settings.kt | 1 + 2 files changed, 16 insertions(+) diff --git a/app/src/main/java/org/oxycblt/auxio/music/model/Library.kt b/app/src/main/java/org/oxycblt/auxio/music/model/Library.kt index b952efba8..54c99a084 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/model/Library.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/model/Library.kt @@ -100,6 +100,21 @@ private class LibraryImpl(rawSongs: List, 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. diff --git a/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt b/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt index 1552becd3..5bc4448b9 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt @@ -85,6 +85,7 @@ interface Settings { sharedPreferences: SharedPreferences, key: String ) { + // FIXME: Settings initialization firing the listener. onSettingChanged(key, unlikelyToBeNull(listener)) }