Skip to content

Commit

Permalink
Fixes #410
Browse files Browse the repository at this point in the history
Signed-off-by: enricocid <enrico2588@gmail.com>
  • Loading branch information
enricocid committed May 7, 2022
1 parent cba5e64 commit 91e2d24
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ This work is licensed under a [CC 0](https://creativecommons.org/share-your-work

- [**repparw**](https://github.com/repparw) for having helped me to solve [task #8 on issue 220](https://github.com/enricocid/Music-Player-GO/issues/220)

- **Carmine Nives** for having reported this [issue](https://github.com/enricocid/Music-Player-GO/issues/410)


### Big thanks to translators:

- [**z1q7p3m9**](https://github.com/z1q7p3m9) for **Kurdish** translations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class DetailsFragment : Fragment(), SearchView.OnQueryTextListener {
private var sCanUpdateSongs = true
private var sAlbumSwapped = false
private var sOpenNewDetailsFragment = false
private var sSongHighlighted = false

@SuppressLint("NotifyDataSetChanged")
fun swapSelectedSong(songId: Long?) {
Expand Down Expand Up @@ -366,37 +367,43 @@ class DetailsFragment : Fragment(), SearchView.OnQueryTextListener {
_detailsFragmentBinding?.root?.run {
mArtistDetailsAnimator = createCircularReveal(show = true)
mArtistDetailsAnimator.doOnEnd {
highlightSong(mSelectedSongId)
highlightSong(mSelectedSongId, force = false)
}
}
}
}
}

fun highlightSong(songId: Long?) {
fun highlightSong(songId: Long?, force: Boolean) {

if(songId == null) {
return
if (force) {
sSongHighlighted = false
}

mSongsList?.indexOfFirst { song -> song.id == songId }?.let { pos ->
if (pos > -1) {
var songView: View? = _detailsFragmentBinding?.songsRv?.layoutManager?.findViewByPosition(pos)
if (songView == null) {
_detailsFragmentBinding?.songsRv?.addOnScrollListener(object :
RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
songView = _detailsFragmentBinding?.songsRv?.layoutManager?.findViewByPosition(pos)
animateHighlightedSong(songView)
_detailsFragmentBinding?.songsRv?.clearOnScrollListeners()
if (!sSongHighlighted) {

if(songId == null) {
return
}

mSongsList?.indexOfFirst { song -> song.id == songId }?.let { pos ->
if (pos > -1) {
var songView: View? = _detailsFragmentBinding?.songsRv?.layoutManager?.findViewByPosition(pos)
if (songView == null) {
_detailsFragmentBinding?.songsRv?.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (newState == RecyclerView.SCROLL_STATE_IDLE && !sSongHighlighted) {
songView = _detailsFragmentBinding?.songsRv?.layoutManager?.findViewByPosition(pos)
animateHighlightedSong(songView)
sSongHighlighted = true
}
}
}
})
_detailsFragmentBinding?.songsRv?.smoothScrollToPosition(pos)
} else {
animateHighlightedSong(songView)
})
_detailsFragmentBinding?.songsRv?.smoothScrollToPosition(pos)
} else {
animateHighlightedSong(songView)
}
}
}
}
Expand Down Expand Up @@ -646,7 +653,7 @@ class DetailsFragment : Fragment(), SearchView.OnQueryTextListener {
setSongsDataSource(songs, updateSongs = false, updateAdapter = true)
_detailsFragmentBinding?.songsRv?.afterMeasured {
scrollToPosition(0)
highlightSong(mSelectedSongId)
highlightSong(mSelectedSongId, force = false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ class MainActivity : AppCompatActivity(), UIControlInterface, MediaControlInterf
)
)
}
mDetailsFragment?.highlightSong(mMediaPlayerHolder.currentSong?.id)
mDetailsFragment?.highlightSong(mMediaPlayerHolder.currentSong?.id, force = true)
} else {
openDetailsFragment(
selectedArtistOrFolder,
Expand Down

0 comments on commit 91e2d24

Please sign in to comment.