Disable scroll when item is already visible

This commit is contained in:
Naveen 2023-08-27 20:01:05 +05:30
parent 034ef821e8
commit 0514d90998
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3
2 changed files with 9 additions and 0 deletions

View file

@ -160,6 +160,7 @@ class QueueActivity : SimpleControllerActivity() {
withPlayer {
val currentTracks = currentMediaItemsShuffled.toTracks() as ArrayList<Track>
adapter.updateItems(currentTracks)
queue_list.lazySmoothScroll(shuffledMediaItemsIndices.indexOf(currentMediaItemIndex))
}
}

View file

@ -1,8 +1,16 @@
package com.simplemobiletools.musicplayer.extensions
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
fun RecyclerView.lazySmoothScroll(scrollToPosition: Int) {
val layoutManager = layoutManager
if (layoutManager is LinearLayoutManager) {
if (scrollToPosition in layoutManager.findFirstCompletelyVisibleItemPosition()..layoutManager.findLastCompletelyVisibleItemPosition()) {
return
}
}
if (scrollToPosition > 100) {
post {
scrollToPosition(scrollToPosition - 25)