Smooth scroll to the current media item on current track change

This commit is contained in:
Naveen 2023-08-27 16:30:10 +05:30
parent 22e4504adb
commit 034ef821e8
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3
3 changed files with 16 additions and 14 deletions

View file

@ -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 {

View file

@ -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)
} }
} }
} }

View file

@ -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)
}
}