music: re-add song de-duplication
Re-add song deduplication, which apparently was lost at some point in 3.0.0's development cycle.
This commit is contained in:
@@ -35,7 +35,7 @@ import org.oxycblt.auxio.util.logD
|
||||
*/
|
||||
class Library(rawSongs: List<Song.Raw>, 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. */
|
||||
|
||||
@@ -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<Song>) {
|
||||
private fun songsInPlace(songs: MutableList<Song>) {
|
||||
songs.sortWith(mode.getSongComparator(isAscending))
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), 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)
|
||||
|
||||
@@ -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?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user