diff --git a/app/src/main/java/org/oxycblt/auxio/detail/PlaylistDetailFragment.kt b/app/src/main/java/org/oxycblt/auxio/detail/PlaylistDetailFragment.kt index 8c4cb4d2f..d1214f6b2 100644 --- a/app/src/main/java/org/oxycblt/auxio/detail/PlaylistDetailFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/detail/PlaylistDetailFragment.kt @@ -127,7 +127,7 @@ class PlaylistDetailFragment : true } R.id.action_delete -> { - musicModel.createPlaylist() + musicModel.deletePlaylist(currentPlaylist) true } else -> false diff --git a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt index 4de6f3c37..c98049d68 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceMusicImpl.kt @@ -34,10 +34,6 @@ import org.oxycblt.auxio.util.toUuidOrNull import org.oxycblt.auxio.util.unlikelyToBeNull import org.oxycblt.auxio.util.update -// TODO: Entirely rework music equality such that it's not completely UID-focused and actually -// takes metadata into account -// TODO: Reduce need for raw objects to save some memory - /** * Library-backed implementation of [Song]. * @@ -45,7 +41,7 @@ import org.oxycblt.auxio.util.update * @param musicSettings [MusicSettings] to for user parsing configuration. * @author Alexander Capehart (OxygenCobalt) */ -class SongImpl(rawSong: RawSong, musicSettings: MusicSettings) : Song { +class SongImpl(private val rawSong: RawSong, musicSettings: MusicSettings) : Song { override val uid = // Attempt to use a MusicBrainz ID first before falling back to a hashed UID. rawSong.musicBrainzId?.toUuidOrNull()?.let { Music.UID.musicBrainz(MusicMode.SONGS, it) } @@ -89,9 +85,9 @@ class SongImpl(rawSong: RawSong, musicSettings: MusicSettings) : Song { override val album: Album get() = unlikelyToBeNull(_album) - // Note: Only compare by UID so songs that differ only in MBID are treated differently. - override fun hashCode() = uid.hashCode() - override fun equals(other: Any?) = other is Song && uid == other.uid + override fun hashCode() = 31 * uid.hashCode() + rawSong.hashCode() + override fun equals(other: Any?) = + other is SongImpl && uid == other.uid && rawSong == other.rawSong private val artistMusicBrainzIds = rawSong.artistMusicBrainzIds.parseMultiValue(musicSettings) private val artistNames = rawSong.artistNames.parseMultiValue(musicSettings) @@ -248,11 +244,15 @@ class AlbumImpl( override val durationMs: Long override val dateAdded: Long - // Note: Append song contents to MusicParent equality so that Groups with - // the same UID but different contents are not equal. - override fun hashCode() = 31 * uid.hashCode() + songs.hashCode() + override fun hashCode(): Int { + var hashCode = uid.hashCode() + hashCode = 31 * hashCode + rawAlbum.hashCode() + hashCode = 31 * hashCode + songs.hashCode() + return hashCode + } + override fun equals(other: Any?) = - other is AlbumImpl && uid == other.uid && songs == other.songs + other is AlbumImpl && uid == other.uid && rawAlbum == other.rawAlbum && songs == other.songs private val _artists = mutableListOf() override val artists: List @@ -341,9 +341,18 @@ class ArtistImpl( // Note: Append song contents to MusicParent equality so that artists with // the same UID but different songs are not equal. - override fun hashCode() = 31 * uid.hashCode() + songs.hashCode() + override fun hashCode(): Int { + var hashCode = uid.hashCode() + hashCode = 31 * hashCode + rawArtist.hashCode() + hashCode = 31 * hashCode + songs.hashCode() + return hashCode + } + override fun equals(other: Any?) = - other is ArtistImpl && uid == other.uid && songs == other.songs + other is ArtistImpl && + uid == other.uid && + rawArtist == other.rawArtist && + songs == other.songs override lateinit var genres: List @@ -422,11 +431,15 @@ class GenreImpl( override val artists: List override val durationMs: Long - // Note: Append song contents to MusicParent equality so that Groups with - // the same UID but different contents are not equal. - override fun hashCode() = 31 * uid.hashCode() + songs.hashCode() + override fun hashCode(): Int { + var hashCode = uid.hashCode() + hashCode = 31 * hashCode + rawGenre.hashCode() + hashCode = 31 * hashCode + songs.hashCode() + return hashCode + } + override fun equals(other: Any?) = - other is GenreImpl && uid == other.uid && songs == other.songs + other is GenreImpl && uid == other.uid && rawGenre == other.rawGenre && songs == other.songs init { val distinctAlbums = mutableSetOf() diff --git a/app/src/main/java/org/oxycblt/auxio/music/device/RawMusic.kt b/app/src/main/java/org/oxycblt/auxio/music/device/RawMusic.kt index bf3bb5794..8c91f09f9 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/device/RawMusic.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/device/RawMusic.kt @@ -30,7 +30,7 @@ import org.oxycblt.auxio.music.metadata.* * * @author Alexander Capehart (OxygenCobalt) */ -class RawSong( +data class RawSong( /** * The ID of the [SongImpl]'s audio file, obtained from MediaStore. Note that this ID is highly * unstable and should only be used for accessing the audio file. @@ -95,7 +95,7 @@ class RawSong( * * @author Alexander Capehart (OxygenCobalt) */ -class RawAlbum( +data class RawAlbum( /** * The ID of the [AlbumImpl]'s grouping, obtained from MediaStore. Note that this ID is highly * unstable and should only be used for accessing the system-provided cover art. @@ -142,7 +142,7 @@ class RawAlbum( * * @author Alexander Capehart (OxygenCobalt) */ -class RawArtist( +data class RawArtist( /** @see Music.UID */ val musicBrainzId: UUID? = null, /** @see Music.name */ @@ -184,7 +184,7 @@ class RawArtist( * * @author Alexander Capehart (OxygenCobalt) */ -class RawGenre( +data class RawGenre( /** @see Music.name */ val name: String? = null ) { diff --git a/app/src/main/java/org/oxycblt/auxio/music/picker/NewPlaylistDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/picker/NewPlaylistDialog.kt index 6c14b6d04..f58ba4b3f 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/picker/NewPlaylistDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/picker/NewPlaylistDialog.kt @@ -61,7 +61,6 @@ class NewPlaylistDialog : ViewBindingDialogFragment() } // TODO: Navigate to playlist if there are songs in it musicModel.createPlaylist(name, pendingPlaylist.songs) - pickerModel.dropPendingAddition() requireContext().showToast(R.string.lng_playlist_created) findNavController().apply { navigateUp() diff --git a/app/src/main/java/org/oxycblt/auxio/music/picker/PlaylistPickerViewModel.kt b/app/src/main/java/org/oxycblt/auxio/music/picker/PlaylistPickerViewModel.kt index fe4b482c7..c5508b2e0 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/picker/PlaylistPickerViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/picker/PlaylistPickerViewModel.kt @@ -156,11 +156,6 @@ class PlaylistPickerViewModel @Inject constructor(private val musicRepository: M refreshPlaylistChoices(songs) } - /** Drop any pending songs to add since a playlist has already been found for them. */ - fun dropPendingAddition() { - _currentPendingSongs.value = null - } - private fun refreshPlaylistChoices(songs: List) { val userLibrary = musicRepository.userLibrary ?: return _playlistChoices.value = diff --git a/app/src/main/java/org/oxycblt/auxio/music/user/UserLibrary.kt b/app/src/main/java/org/oxycblt/auxio/music/user/UserLibrary.kt index f2df2d1a5..7ea2c05b5 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/user/UserLibrary.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/user/UserLibrary.kt @@ -112,11 +112,6 @@ private class UserLibraryImpl( override val playlists: List get() = playlistMap.values.toList() - init { - // TODO: Actually read playlists - createPlaylist("Playlist 1", deviceLibrary.songs.slice(58..200)) - } - override fun findPlaylist(uid: Music.UID) = playlistMap[uid] override fun findPlaylist(name: String) = playlistMap.values.find { it.name.raw == name }