diff --git a/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt b/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt index dffde42ac..fcbbe4a33 100644 --- a/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt @@ -46,8 +46,6 @@ import org.oxycblt.auxio.util.* * [ViewModel] that manages the Song, Album, Artist, and Genre detail views. Keeps track of the * current item they are showing, sub-data to display, and configuration. * - * FIXME: Need to do direct item comparison in equality checks, or reset on navigation. - * * @author Alexander Capehart (OxygenCobalt) */ @HiltViewModel @@ -163,9 +161,7 @@ constructor( var playlistSongSort: Sort get() = musicSettings.playlistSongSort set(value) { - logD(value) musicSettings.playlistSongSort = value - logD(musicSettings.playlistSongSort) // Refresh the playlist list to reflect the new sort. currentPlaylist.value?.let { refreshPlaylistList(it, true) } } @@ -234,10 +230,6 @@ constructor( * @param uid The UID of the [Song] to load. Must be valid. */ fun setSongUid(uid: Music.UID) { - if (_currentSong.value?.uid == uid) { - // Nothing to do. - return - } logD("Opening Song [uid: $uid]") _currentSong.value = musicRepository.deviceLibrary?.findSong(uid)?.also(::refreshAudioInfo) } @@ -249,10 +241,6 @@ constructor( * @param uid The [Music.UID] of the [Album] to update [currentAlbum] to. Must be valid. */ fun setAlbumUid(uid: Music.UID) { - if (_currentAlbum.value?.uid == uid) { - // Nothing to do. - return - } logD("Opening Album [uid: $uid]") _currentAlbum.value = musicRepository.deviceLibrary?.findAlbum(uid)?.also(::refreshAlbumList) @@ -265,10 +253,6 @@ constructor( * @param uid The [Music.UID] of the [Artist] to update [currentArtist] to. Must be valid. */ fun setArtistUid(uid: Music.UID) { - if (_currentArtist.value?.uid == uid) { - // Nothing to do. - return - } logD("Opening Artist [uid: $uid]") _currentArtist.value = musicRepository.deviceLibrary?.findArtist(uid)?.also(::refreshArtistList) @@ -281,10 +265,6 @@ constructor( * @param uid The [Music.UID] of the [Genre] to update [currentGenre] to. Must be valid. */ fun setGenreUid(uid: Music.UID) { - if (_currentGenre.value?.uid == uid) { - // Nothing to do. - return - } logD("Opening Genre [uid: $uid]") _currentGenre.value = musicRepository.deviceLibrary?.findGenre(uid)?.also(::refreshGenreList) @@ -297,10 +277,6 @@ constructor( * @param uid The [Music.UID] of the [Playlist] to update [currentPlaylist] to. Must be valid. */ fun setPlaylistUid(uid: Music.UID) { - if (_currentPlaylist.value?.uid == uid) { - // Nothing to do. - return - } logD("Opening Playlist [uid: $uid]") _currentPlaylist.value = musicRepository.userLibrary?.findPlaylist(uid)?.also(::refreshPlaylistList) diff --git a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt index 44ac4e99d..120cd5875 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/device/DeviceLibrary.kt @@ -170,7 +170,7 @@ private class DeviceLibraryImpl(rawSongs: List, settings: MusicSettings */ private fun buildSongs(rawSongs: List, settings: MusicSettings) = Sort(Sort.Mode.ByName, Sort.Direction.ASCENDING) - .songs(rawSongs.map { SongImpl(it, settings) }.distinct()) + .songs(rawSongs.map { SongImpl(it, settings) }.distinctBy { it.uid }) /** * Build a list of [Album]s from the given [Song]s. 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 1de1db4a8..ef17f395d 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,6 +34,9 @@ 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 + /** * Library-backed implementation of [Song]. * diff --git a/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt index eb81775c2..03cb0e597 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/picker/AddToPlaylistDialog.kt @@ -82,7 +82,6 @@ class AddToPlaylistDialog : override fun onClick(item: PlaylistChoice, viewHolder: RecyclerView.ViewHolder) { musicModel.addToPlaylist(pickerModel.currentPendingSongs.value ?: return, item.playlist) - pickerModel.confirmPlaylistAddition() requireContext().showToast(R.string.lng_playlist_added) findNavController().navigateUp() } 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 27d84fbec..d4b4d02ea 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 @@ -60,7 +60,7 @@ class NewPlaylistDialog : ViewBindingDialogFragment() } // TODO: Navigate to playlist if there are songs in it musicModel.createPlaylist(name, pendingPlaylist.songs) - pickerModel.confirmPlaylistCreation() + pickerModel.dropPendingAddition() requireContext().showToast(R.string.lng_playlist_created) } .setNegativeButton(R.string.lbl_cancel, null) 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 8fb9a9eb1..fe4b482c7 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 @@ -105,10 +105,6 @@ class PlaylistPickerViewModel @Inject constructor(private val musicRepository: M * @param songUids The [Music.UID]s of songs to be present in the playlist. */ fun setPendingPlaylist(context: Context, songUids: Array) { - if (currentPendingPlaylist.value?.songs?.map { it.uid } == songUids) { - // Nothing to do. - return - } val deviceLibrary = musicRepository.deviceLibrary ?: return val songs = songUids.mapNotNull(deviceLibrary::findSong) @@ -146,15 +142,6 @@ class PlaylistPickerViewModel @Inject constructor(private val musicRepository: M } } - /** Confirm the playlist creation process as completed. */ - fun confirmPlaylistCreation() { - // Confirm any playlist additions if needed, as the creation process may have been started - // by it and is still waiting on a result. - confirmPlaylistAddition() - _currentPendingPlaylist.value = null - _chosenName.value = ChosenName.Empty - } - /** * Update the current [Song]s that to show playlist add choices for. Will do nothing if already * equal. @@ -169,8 +156,8 @@ class PlaylistPickerViewModel @Inject constructor(private val musicRepository: M refreshPlaylistChoices(songs) } - /** Mark the addition process as complete. */ - fun confirmPlaylistAddition() { + /** Drop any pending songs to add since a playlist has already been found for them. */ + fun dropPendingAddition() { _currentPendingSongs.value = null } diff --git a/app/src/test/java/org/oxycblt/auxio/music/FakeMusicRepository.kt b/app/src/test/java/org/oxycblt/auxio/music/FakeMusicRepository.kt index a09aa1722..7ae9197b6 100644 --- a/app/src/test/java/org/oxycblt/auxio/music/FakeMusicRepository.kt +++ b/app/src/test/java/org/oxycblt/auxio/music/FakeMusicRepository.kt @@ -62,6 +62,10 @@ open class FakeMusicRepository : MusicRepository { throw NotImplementedError() } + override fun deletePlaylist(playlist: Playlist) { + throw NotImplementedError() + } + override fun addToPlaylist(songs: List, playlist: Playlist) { throw NotImplementedError() }