queue: re-add adaptive divider visibility

Re-add the adaptive divider functionality that was accidentally removed prior.
This commit is contained in:
Alexander Capehart 2022-12-29 13:39:31 -07:00
parent bda42c9762
commit d16fc2e446
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 21 additions and 1 deletions

View file

@ -1,5 +1,5 @@
name: Bug/Crash Report
description: File a bug report
description: Report a problem
labels: ["bug"]
assignees:
- OxygenCobalt

View file

@ -19,6 +19,7 @@ package org.oxycblt.auxio.playback.queue
import android.os.Bundle
import android.view.LayoutInflater
import androidx.core.view.isInvisible
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
@ -54,6 +55,18 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), QueueAdapter.
touchHelper.attachToRecyclerView(this)
}
// Sometimes the scroll can change without the listener being updated, so we also
// check for relayout events.
binding.queueRecycler.apply {
addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> updateDivider() }
addOnScrollListener(
object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
updateDivider()
}
})
}
// --- VIEWMODEL SETUP ----
collectImmediately(
queueModel.queue, queueModel.index, playbackModel.isPlaying, ::updateQueue)
@ -73,6 +86,13 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), QueueAdapter.
touchHelper.startDrag(viewHolder)
}
private fun updateDivider() {
val binding = requireBinding()
binding.queueDivider.isInvisible =
(binding.queueRecycler.layoutManager as LinearLayoutManager)
.findFirstCompletelyVisibleItemPosition() < 1
}
private fun updateQueue(queue: List<Song>, index: Int, isPlaying: Boolean) {
val binding = requireBinding()