Smooth scroll to the current media item on current track change
This commit is contained in:
parent
22e4504adb
commit
034ef821e8
3 changed files with 16 additions and 14 deletions
|
@ -149,25 +149,12 @@ class QueueActivity : SimpleControllerActivity() {
|
||||||
|
|
||||||
val currentPosition = shuffledMediaItemsIndices.indexOf(currentMediaItemIndex)
|
val currentPosition = shuffledMediaItemsIndices.indexOf(currentMediaItemIndex)
|
||||||
if (currentPosition > 0) {
|
if (currentPosition > 0) {
|
||||||
lazySmoothScroll(currentPosition)
|
queue_list.lazySmoothScroll(currentPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun lazySmoothScroll(scrollToPosition: Int) {
|
|
||||||
queue_list.apply {
|
|
||||||
if (scrollToPosition > 100) {
|
|
||||||
post {
|
|
||||||
scrollToPosition(scrollToPosition - 50)
|
|
||||||
smoothScrollToPosition(scrollToPosition)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
smoothScrollToPosition(scrollToPosition)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateAdapter() {
|
private fun updateAdapter() {
|
||||||
val adapter = getAdapter() ?: return
|
val adapter = getAdapter() ?: return
|
||||||
withPlayer {
|
withPlayer {
|
||||||
|
|
|
@ -85,6 +85,7 @@ class QueueAdapter(activity: SimpleActivity, items: ArrayList<Track>, var curren
|
||||||
if (previousIndex != -1 && newIndex != -1) {
|
if (previousIndex != -1 && newIndex != -1) {
|
||||||
notifyItemChanged(previousIndex)
|
notifyItemChanged(previousIndex)
|
||||||
notifyItemChanged(newIndex)
|
notifyItemChanged(newIndex)
|
||||||
|
recyclerView.lazySmoothScroll(newIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.simplemobiletools.musicplayer.extensions
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
fun RecyclerView.lazySmoothScroll(scrollToPosition: Int) {
|
||||||
|
if (scrollToPosition > 100) {
|
||||||
|
post {
|
||||||
|
scrollToPosition(scrollToPosition - 25)
|
||||||
|
smoothScrollToPosition(scrollToPosition)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
smoothScrollToPosition(scrollToPosition)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue