Twelve: QueueFragment: Scroll to current playing item on open
Change-Id: I3481d0cff3155d9694890d90cafbbdb4ea0af6c6
diff --git a/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
index e401822..59b8732 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/QueueFragment.kt
@@ -54,6 +54,7 @@
::ListItem,
) {
var currentQueue = listOf<QueueItem>()
+ var scrolled = false
override fun ViewHolder.onPrepareView() {
view.setTrailingIconImage(R.drawable.ic_drag_handle)
@@ -156,7 +157,14 @@
viewModel.queue.collectLatest { queue ->
queue.toMutableList().let {
adapter.currentQueue = it
- adapter.submitList(it)
+ adapter.submitList(it) {
+ if (it.isNotEmpty() && !adapter.scrolled) {
+ recyclerView.scrollToPosition(
+ queue.indexOfFirst { item -> item.isCurrent }
+ )
+ adapter.scrolled = true
+ }
+ }
}
}
}