Merge pull request #2787 from Bnyro/master

Fix queue starts wrong video after reordering
This commit is contained in:
Bnyro 2023-01-21 11:20:04 +01:00 committed by GitHub
commit 2acd53515c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.QueueRowBinding
import com.github.libretube.extensions.toID
import com.github.libretube.ui.viewholders.PlayingQueueViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.PlayingQueue
@ -46,10 +47,16 @@ class PlayingQueueAdapter : RecyclerView.Adapter<PlayingQueueViewHolder>() {
)
root.setOnClickListener {
val oldIndex = PlayingQueue.currentIndex()
PlayingQueue.onQueueItemSelected(position)
notifyItemChanged(oldIndex)
notifyItemChanged(position)
val oldPosition = PlayingQueue.currentIndex()
// get the new position from the queue to work properly after reordering the queue
val newPosition = PlayingQueue.getStreams().indexOfFirst {
it.url?.toID() == streamItem.url?.toID()
}.takeIf { it >= 0 } ?: return@setOnClickListener
// select the new item in the queue and update the selected item in the UI
PlayingQueue.onQueueItemSelected(newPosition)
notifyItemChanged(oldPosition)
notifyItemChanged(newPosition)
}
}
}