diff --git a/CHANGELOG.md b/CHANGELOG.md index 602d4e17c..1418b016a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ file manager - Fixed genre picker from repeatedly showing up when device rotates - Fixed multi-value genres not being recognized on vorbis files - Fixed sharp-cornered widget bar appearing even when round mode was enabled +- Fixed duplicate song items from appearing #### What's Changed - Implemented new queue system diff --git a/app/src/main/java/org/oxycblt/auxio/music/library/Library.kt b/app/src/main/java/org/oxycblt/auxio/music/library/Library.kt index 88cbe302f..d8a42b40a 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/library/Library.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/library/Library.kt @@ -35,7 +35,7 @@ import org.oxycblt.auxio.util.logD */ class Library(rawSongs: List, settings: MusicSettings) { /** All [Song]s that were detected on the device. */ - val songs = Sort(Sort.Mode.ByName, true).songs(rawSongs.map { Song(it, settings) }) + val songs = Sort(Sort.Mode.ByName, true).songs(rawSongs.map { Song(it, settings) }.distinct()) /** All [Album]s found on the device. */ val albums = buildAlbums(songs) /** All [Artist]s found on the device. */ diff --git a/app/src/main/java/org/oxycblt/auxio/music/library/Sort.kt b/app/src/main/java/org/oxycblt/auxio/music/library/Sort.kt index a126f3879..2cda0e76f 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/library/Sort.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/library/Sort.kt @@ -97,7 +97,7 @@ data class Sort(val mode: Mode, val isAscending: Boolean) { * Sort a *mutable* list of [Song]s in-place using this [Sort]'s configuration. * @param songs The [Song]s to sort. */ - fun songsInPlace(songs: MutableList) { + private fun songsInPlace(songs: MutableList) { songs.sortWith(mode.getSongComparator(isAscending)) } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt index 9f8feb3d8..50c363721 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt @@ -100,7 +100,7 @@ class QueueFragment : ViewBindingFragment(), EditableListL val binding = requireBinding() // Replace or diff the queue depending on the type of change it is. - val instructions = queueModel.instructions + val instructions = queueModel.queueListInstructions queueAdapter.submitList(queue, instructions?.update ?: BasicListInstructions.DIFF) // Update position in list (and thus past/future items) queueAdapter.setPosition(index, isPlaying) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueViewModel.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueViewModel.kt index c97beabc0..71bbe02e9 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueViewModel.kt @@ -44,20 +44,20 @@ class QueueViewModel : ViewModel(), PlaybackStateManager.Listener { get() = _index /** Specifies how to update the list when the queue changes. */ - var instructions: Instructions? = null + var queueListInstructions: ListInstructions? = null init { playbackManager.addListener(this) } override fun onIndexMoved(queue: Queue) { - instructions = Instructions(null, queue.index) + queueListInstructions = ListInstructions(null, queue.index) _index.value = queue.index } override fun onQueueChanged(queue: Queue, change: Queue.ChangeResult) { // Queue changed trivially due to item mo -> Diff queue, stay at current index. - instructions = Instructions(BasicListInstructions.DIFF, null) + queueListInstructions = ListInstructions(BasicListInstructions.DIFF, null) _queue.value = queue.resolve() if (change != Queue.ChangeResult.MAPPING) { // Index changed, make sure it remains updated without actually scrolling to it. @@ -67,14 +67,14 @@ class QueueViewModel : ViewModel(), PlaybackStateManager.Listener { override fun onQueueReordered(queue: Queue) { // Queue changed completely -> Replace queue, update index - instructions = Instructions(BasicListInstructions.REPLACE, queue.index) + queueListInstructions = ListInstructions(BasicListInstructions.REPLACE, queue.index) _queue.value = queue.resolve() _index.value = queue.index } override fun onNewPlayback(queue: Queue, parent: MusicParent?) { // Entirely new queue -> Replace queue, update index - instructions = Instructions(BasicListInstructions.REPLACE, queue.index) + queueListInstructions = ListInstructions(BasicListInstructions.REPLACE, queue.index) _queue.value = queue.resolve() _index.value = queue.index } @@ -119,10 +119,10 @@ class QueueViewModel : ViewModel(), PlaybackStateManager.Listener { return true } - /** Signal that the specified [Instructions] in [instructions] were performed. */ + /** Signal that the specified [ListInstructions] in [queueListInstructions] were performed. */ fun finishInstructions() { - instructions = null + queueListInstructions = null } - class Instructions(val update: BasicListInstructions?, val scrollTo: Int?) + class ListInstructions(val update: BasicListInstructions?, val scrollTo: Int?) } diff --git a/app/src/main/res/layout/item_header.xml b/app/src/main/res/layout/item_header.xml index aa69cc8ef..0f7e21fa8 100644 --- a/app/src/main/res/layout/item_header.xml +++ b/app/src/main/res/layout/item_header.xml @@ -1,6 +1,5 @@